1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
24 #include "Dialog_SplashScreen.h"
25 #include "Dialog_MainWindow.h"
26 #include "Dialog_Processing.h"
27 #include "Thread_Initialization.h"
28 #include "Thread_MessageProducer.h"
29 #include "Model_Settings.h"
30 #include "Model_FileList.h"
31 #include "Model_AudioFile.h"
32 #include "Encoder_Abstract.h"
35 #include <QApplication>
36 #include <QMessageBox>
40 #include <QInputDialog>
42 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
46 int lamexp_main(int argc, char* argv[])
49 bool bAccepted = true;
52 lamexp_init_console(argc, argv);
55 qDebug("LameXP - Audio Encoder Front-End");
56 qDebug("Version %d.%02d %s, Build %d [%s], compiled with %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_compiler());
57 qDebug("Copyright (C) 2004-%04d LoRd_MuldeR <MuldeR2@GMX.de>\n", max(lamexp_version_date().year(),QDate::currentDate().year()));
60 qDebug("This program is free software: you can redistribute it and/or modify");
61 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
62 qDebug("This program comes with ABSOLUTELY NO WARRANTY.\n");
64 //Print warning, if this is a "debug" build
65 LAMEXP_CHECK_DEBUG_BUILD;
67 //Detect CPU capabilities
68 lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
69 qDebug(" CPU vendor id : %s (Intel: %d)", cpuFeatures.vendor, (cpuFeatures.intel ? 1 : 0));
70 qDebug("CPU brand string : %s", cpuFeatures.brand);
71 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
72 qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", LAMEXP_BOOL(cpuFeatures.mmx), LAMEXP_BOOL(cpuFeatures.sse), LAMEXP_BOOL(cpuFeatures.sse2), LAMEXP_BOOL(cpuFeatures.sse3), LAMEXP_BOOL(cpuFeatures.ssse3), LAMEXP_BOOL(cpuFeatures.x64));
73 qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
76 if(!lamexp_init_qt(argc, argv))
81 //Check for expiration
82 if(lamexp_version_demo())
84 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate)).toLatin1().constData());
87 //Check for multiple instances of LameXP
88 if((iResult = lamexp_init_ipc()) != 0)
90 qDebug("LameXP is already running, connecting to running instance...");
93 MessageProducerThread *messageProducerThread = new MessageProducerThread();
94 messageProducerThread->start();
95 if(!messageProducerThread->wait(30000))
97 messageProducerThread->terminate();
98 QMessageBox messageBox(QMessageBox::Critical, "LameXP", "LameXP is already running, but the running instance doesn't respond!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
100 messageProducerThread->wait();
101 LAMEXP_DELETE(messageProducerThread);
104 LAMEXP_DELETE(messageProducerThread);
110 for(int i = 0; i < argc; i++)
112 if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
119 FileListModel *fileListModel = new FileListModel();
120 AudioFileModel *metaInfo = new AudioFileModel();
121 SettingsModel *settingsModel = new SettingsModel();
124 InitializationThread *poInitializationThread = new InitializationThread();
125 SplashScreen::showSplash(poInitializationThread);
126 LAMEXP_DELETE(poInitializationThread);
129 settingsModel->validate();
132 MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
134 //Main application loop
138 poMainWindow->show();
139 iResult = QApplication::instance()->exec();
140 bAccepted = poMainWindow->isAccepted();
142 //Show processing dialog
143 if(bAccepted && fileListModel->rowCount() > 0)
145 ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
146 processingDialog->exec();
147 LAMEXP_DELETE(processingDialog);
152 LAMEXP_DELETE(poMainWindow);
153 LAMEXP_DELETE(fileListModel);
154 LAMEXP_DELETE(metaInfo);
155 LAMEXP_DELETE(settingsModel);
158 qDebug("Shutting down, please wait...\n");
164 ///////////////////////////////////////////////////////////////////////////////
165 // Applicaton entry point
166 ///////////////////////////////////////////////////////////////////////////////
168 int main(int argc, char* argv[])
172 qInstallMsgHandler(lamexp_message_handler);
173 LAMEXP_MEMORY_CHECK(iResult = lamexp_main(argc, argv));
174 lamexp_finalization();
180 qInstallMsgHandler(lamexp_message_handler);
181 iResult = lamexp_main(argc, argv);
182 lamexp_finalization();
189 fprintf(stderr, "\nGURU MEDITATION: %s\n", error);
190 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
191 TerminateProcess(GetCurrentProcess(), -1);
197 fprintf(stderr, "\nGURU MEDITATION: Error code 0x%X\n", error);
198 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
199 TerminateProcess(GetCurrentProcess(), -1);
205 fprintf(stderr, "\nGURU MEDITATION !!!\n");
206 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
207 TerminateProcess(GetCurrentProcess(), -1);
214 void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
216 OutputDebugStringA("Hello cruel world!");
217 MessageBoxA(0, lpszCmdLine, "LameXP v9.0", MB_ICONINFORMATION);