void LatexDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; QCString lang = m_langExt; if (!s->language().isEmpty()) // explicit language setting { lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch(s->type()) { case DocVerbatim::Code: { m_t << "\n\\begin{DoxyCode}\n"; Doxygen::parserManager->getParser(lang) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "\\end{DoxyCode}\n"; } break; case DocVerbatim::Verbatim: m_t << "\\begin{DoxyVerb}"; m_t << s->text(); m_t << "\\end{DoxyVerb}\n"; break; case DocVerbatim::HtmlOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: case DocVerbatim::RtfOnly: case DocVerbatim::DocbookOnly: /* nothing */ break; case DocVerbatim::LatexOnly: m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString("LATEX_OUTPUT")+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); m_t << "\\begin{center}\n"; startDotFile(fileName,"","",FALSE); endDotFile(FALSE); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d", (Config_getString("LATEX_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << "\\begin{center}\n"; writeMscFile(baseName); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; } }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GOwnPtr<GFile> file(g_file_new_for_path(finalPath.get())); GOwnPtr<GFile> dir(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GOwnPtr<GFile> resolvedFile(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } m_isLoaded = true; NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); #if defined(XP_UNIX) npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); #else npErr = NP_Initialize(&m_browserFuncs); #endif if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
int main( int argc, char *argv[] ){ Froot *dirNames; /* To hold the directories to be scanned */ Fnode *pFN; /* Running pointer over directory names */ int to_bExt = FALSE; /* Flag "next parameter to bExt" */ /** | Scans the arguments appropriately; the required directories are stored | in the linked list starting at "dirNames". **/ programName = baseName(argv[0]); if ((dirNames = calloc(2, sizeof(Froot))) == 0) { noMemory(); } dirNames->extension = "argv"; while (--argc) { if ((*++argv)[0] == '-') { switch ( (*argv)[1] ) { case 'i': case 'I': confirm = TRUE; break; case 'r': case 'R': recurse = TRUE; break; case 'k': case 'K': keep = TRUE; break; case 'b': case 'B': to_bExt = TRUE; break; case 'q': case 'Q': output_level = QUIET; break; case 'v': case 'V': output_level = VERBOSE; break; case 'd': case 'D': output_level = DEBUG; break; case 'p': case 'P': pretend = TRUE; break; case 'o': case 'O': older = TRUE; break; default: syntax(); } } else { if (to_bExt) { strcpy(bExt, *argv); to_bExt = FALSE; } else { insertNode(*argv, 0, 0, 0, dirNames); } } } if (to_bExt) { syntax(); } n_bExt = strlen(bExt); /** | If no parameter has been given, clean the current directory **/ if ((pFN = dirNames->firstNode) == 0) { clean("."); } else { while (pFN != 0) { clean(pFN->name); pFN = pFN->next; } } releaseTree(dirNames); return EXIT_SUCCESS; }
void DocbookDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(m_langExt); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "<programlisting>"; Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "</programlisting>"; break; case DocVerbatim::Verbatim: m_t << "<programlisting><literallayout>"; filter(s->text()); m_t << "</literallayout></programlisting>"; break; case DocVerbatim::HtmlOnly: break; case DocVerbatim::RtfOnly: break; case DocVerbatim::ManOnly: break; case DocVerbatim::LatexOnly: break; case DocVerbatim::XmlOnly: break; case DocVerbatim::DocbookOnly: break; m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString baseName(4096); QCString stext = s->text(); m_t << "<para>" << endl; baseName.sprintf("%s%d", (Config_getString("DOCBOOK_OUTPUT")+"/inline_dotgraph_").data(), dotindex++ ); QFile file(baseName+".dot"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } file.writeBlock( stext, stext.length() ); file.close(); m_t << " <figure>" << endl; m_t << " <title></title>" << endl; m_t << " <mediaobject>" << endl; m_t << " <imageobject>" << endl; writeDotFile(baseName); m_t << " </imageobject>" << endl; m_t << " </mediaobject>" << endl; m_t << " </figure>" << endl; m_t << "</para>" << endl; } break; case DocVerbatim::Msc: static int mscindex = 1; QCString baseName(4096); QCString stext = s->text(); m_t << "<para>" << endl; baseName.sprintf("%s%d", (Config_getString("DOCBOOK_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=stext; text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << " <figure>" << endl; m_t << " <title></title>" << endl; m_t << " <mediaobject>" << endl; m_t << " <imageobject>" << endl; writeMscFile(baseName); m_t << " </imageobject>" << endl; m_t << " </mediaobject>" << endl; m_t << " </figure>" << endl; m_t << "</para>" << endl; break; } }
bool QtRegelaarInstellingenDialoog::RunDialogOk() { ui->laatsteWagonCheck->setChecked(m_laatsteWagonCheck); ui->eloc->setChecked(m_eloc); ui->minSnelheid->setText(std::to_string(m_minSnelheid).c_str()); ui->maxSnelheid->setText(std::to_string(m_maxSnelheid).c_str()); ui->topSnelheid->setText(std::to_string(m_topSnelheid).c_str()); ui->locType->setText(m_locType.c_str()); ui->totaalAfstand->setText(std::to_string(m_totaalAfstand).c_str()); ui->totaalTijd->setText(m_totaalTijd.c_str()); ui->lengte->setText(std::to_string(m_lengte).c_str()); ui->errors->setText(m_errors.c_str()); ui->alphaRijden->setText(toString(m_alphaRijden).c_str()); ui->alphaStoppen->setText(toString(m_alphaStoppen).c_str()); ui->clipRijden->setText(std::to_string(m_clipRijden).c_str()); ui->clipStoppen->setText(std::to_string(m_clipStoppen).c_str()); ui->stand1->setText(std::to_string(m_stand1).c_str()); ui->stand2->setText(std::to_string(m_stand2).c_str()); ui->afstand1->setText(std::to_string(m_afstand1).c_str()); ui->afstand2->setText(std::to_string(m_afstand2).c_str()); ui->kLpf->setText(toString(m_kLpf).c_str()); ui->plusMinus->setText(toString(m_plusMinus).c_str()); ui->helling->setText(toString(m_helling).c_str()); ui->dodeTijd->setText(toString(m_dodeTijd).c_str()); auto file = QFileInfo(m_programmaNaam.c_str()); ui->programmaNaam->setText(file.baseName()); ui->herlaadProgramma->setChecked(m_laatsteWagonCheck); ui->langzaam->setText(std::to_string(m_langzaam).c_str()); ui->rijden->setText(std::to_string(m_rijden).c_str()); ui->lastStand1->setText(std::to_string(m_lastStand1).c_str()); ui->lastStand2->setText(std::to_string(m_lastStand2).c_str()); ui->lastRegelingKeuze->setText(std::to_string(m_lastKeuze).c_str()); ui->lastGain1->setText(toString(m_lastGain1).c_str()); ui->lastGain2->setText(toString(m_lastGain2).c_str()); auto dialogRet = exec(); if (dialogRet==QDialog::Accepted) { m_laatsteWagonCheck = ui->laatsteWagonCheck->isChecked(); m_eloc = ui->eloc->isChecked(); m_minSnelheid = std::stoi(ui->minSnelheid->text().toStdString()); m_maxSnelheid = std::stoi(ui->maxSnelheid->text().toStdString()); m_topSnelheid = std::stoi(ui->topSnelheid->text().toStdString()); m_locType = ui->locType->text().toStdString(); m_totaalAfstand = std::stoi(ui->totaalAfstand->text().toStdString()); m_totaalTijd = ui->totaalTijd->text().toStdString(); m_lengte = std::stoi(ui->lengte->text().toStdString()); m_alphaRijden = std::stof(ui->alphaRijden->text().toStdString()); m_alphaStoppen = std::stof(ui->alphaStoppen->text().toStdString()); m_clipRijden = std::stoi(ui->clipRijden->text().toStdString()); m_clipStoppen = std::stoi(ui->clipStoppen->text().toStdString()); m_stand1 = std::stoi(ui->stand1->text().toStdString()); m_stand2 = std::stoi(ui->stand2->text().toStdString()); m_afstand1 = std::stoi(ui->afstand1->text().toStdString()); m_afstand2 = std::stoi(ui->afstand2->text().toStdString()); m_kLpf = std::stof(ui->kLpf->text().toStdString()); m_plusMinus = std::stof(ui->plusMinus->text().toStdString()); m_helling = std::stof(ui->helling->text().toStdString()); m_dodeTijd = std::stof(ui->dodeTijd->text().toStdString()); //m_programmaNaam = ui->programmaNaam->text().toStdString(); niet converteren word gedaan in on_programmaNaam_clicked m_herlaadProgramma = ui->herlaadProgramma->isChecked(); m_langzaam = std::stoi(ui->langzaam->text().toStdString()); m_rijden = std::stoi(ui->rijden->text().toStdString()); m_lastStand1 = std::stoi(ui->lastStand1->text().toStdString()); m_lastGain1 = std::stof(ui->lastGain1->text().toStdString()); m_lastStand2 = std::stoi(ui->lastStand2->text().toStdString()); m_lastGain2 = std::stof(ui->lastGain2->text().toStdString()); m_lastKeuze = std::stoi(ui->lastRegelingKeuze->text().toStdString()); return true; } return false; }
static QString metaFileForFileName(const QString &fname) { return baseName(fname) + ".meta"; }
int main( int argc, char * * argv ) { // initialize memory managers MemoryManager::init(); NotePlayHandleManager::init(); // intialize RNG srand( getpid() + time( 0 ) ); disable_denormals(); bool coreOnly = false; bool fullscreen = true; bool exitAfterImport = false; bool allowRoot = false; bool renderLoop = false; QString fileToLoad, fileToImport, renderOut, profilerOutputFile; // first of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" || arg == "--render" || arg == "-r" ) { coreOnly = true; } else if( arg == "--allowroot" ) { allowRoot = true; } else if( arg == "-geometry" ) { // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } #ifndef LMMS_BUILD_WIN32 if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" ); return EXIT_FAILURE; } #endif QCoreApplication * app = coreOnly ? new QCoreApplication( argc, argv ) : new QApplication( argc, argv ) ; Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); ProjectRenderer::OutputSettings os( 44100, false, 160, ProjectRenderer::Depth_16Bit ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; // second of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--version" || arg == "-v" ) { printVersion( argv[0] ); return EXIT_SUCCESS; } else if( arg == "--help" || arg == "-h" ) { printHelp(); return EXIT_SUCCESS; } else if( arg == "--upgrade" || arg == "-u" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } DataFile dataFile( QString::fromLocal8Bit( argv[i] ) ); if( argc > i+1 ) // output file specified { dataFile.writeFile( QString::fromLocal8Bit( argv[i+1] ) ); } else // no output file specified; use stdout { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return EXIT_SUCCESS; } else if( arg == "--allowroot" ) { // Ignore, processed earlier #ifdef LMMS_BUILD_WIN32 if( allowRoot ) { printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" ); } #endif } else if( arg == "--dump" || arg == "-d" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } QFile f( QString::fromLocal8Bit( argv[i] ) ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return EXIT_SUCCESS; } else if( arg == "--render" || arg == "-r" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); renderOut = baseName( fileToLoad ) + "."; } else if( arg == "--loop-mode" || arg == "-l" ) { renderLoop = true; } else if( arg == "--output" || arg == "-o" ) { ++i; if( i == argc ) { printf( "\nNo output file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } renderOut = baseName( QString::fromLocal8Bit( argv[i] ) ) + "."; } else if( arg == "--format" || arg == "-f" ) { ++i; if( i == argc ) { printf( "\nNo output format specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ext = QString( argv[i] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif else { printf( "\nInvalid output format %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--samplerate" || arg == "-s" ) { ++i; if( i == argc ) { printf( "\nNo samplerate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } sample_rate_t sr = QString( argv[i] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.samplerate = sr; } else { printf( "\nInvalid samplerate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--bitrate" || arg == "-b" ) { ++i; if( i == argc ) { printf( "\nNo bitrate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int br = QString( argv[i] ).toUInt(); if( br >= 64 && br <= 384 ) { os.bitrate = br; } else { printf( "\nInvalid bitrate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg =="--float" || arg == "-a" ) { os.depth = ProjectRenderer::Depth_32Bit; } else if( arg == "--interpolation" || arg == "-i" ) { ++i; if( i == argc ) { printf( "\nNo interpolation method specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ip = QString( argv[i] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { printf( "\nInvalid interpolation method %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--oversampling" || arg == "-x" ) { ++i; if( i == argc ) { printf( "\nNo oversampling specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int o = QString( argv[i] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: printf( "\nInvalid oversampling %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--import" ) { ++i; if( i == argc ) { printf( "\nNo file specified for importing.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) if( QString( argv[i + 1] ) == "-e" ) { exitAfterImport = true; ++i; } } else if( arg == "--profile" || arg == "-p" ) { ++i; if( i == argc ) { printf( "\nNo profile specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } profilerOutputFile = QString::fromLocal8Bit( argv[1] ); } else { if( argv[i][0] == '-' ) { printf( "\nInvalid option %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); } } ConfigManager::inst()->loadConfigFile(); // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) { pos = QLocale::system().name().left( 2 ); } #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR ConfigManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif #ifdef LMMS_BUILD_WIN32 if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) { printf( "Notice: could not set high priority.\n" ); } #endif // if we have an output file for rendering, just render the song // without starting the GUI if( !renderOut.isEmpty() ) { Engine::init( true ); QFileInfo fileInfo( fileToLoad ); if ( !fileInfo.exists() ) { printf("The file %s does not exist!\n", fileToLoad.toStdString().c_str()); exit( 1 ); } printf( "Loading project...\n" ); Engine::getSong()->loadProject( fileToLoad ); printf( "Done\n" ); Engine::getSong()->setExportLoop( renderLoop ); // create renderer QString extension = ( eff == ProjectRenderer::WaveFile ) ? "wav" : "ogg"; ProjectRenderer * r = new ProjectRenderer( qs, os, eff, renderOut + extension ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); if( profilerOutputFile.isEmpty() == false ) { Engine::mixer()->profiler().setOutputFile( profilerOutputFile ); } // start now! r->startProcessing(); } else // otherwise, start the GUI { new GuiApplication(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = ConfigManager::inst()->recoveryFile(); if( QFileInfo(recoveryFile).exists() && QMessageBox::question( gui->mainWindow(), MainWindow::tr( "Project recovery" ), MainWindow::tr( "It looks like the last session did not end properly. " "Do you want to recover the project of this session?" ), QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes ) { fileToLoad = recoveryFile; } // we try to load given file if( !fileToLoad.isEmpty() ) { gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } if( fileToLoad == recoveryFile ) { Engine::getSong()->createNewProjectFromTemplate( fileToLoad ); } else { Engine::getSong()->loadProject( fileToLoad ); } } else if( !fileToImport.isEmpty() ) { ImportFilter::import( fileToImport, Engine::getSong() ); if( exitAfterImport ) { return EXIT_SUCCESS; } gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } } else { Engine::getSong()->createNewProject(); // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } } } const int ret = app->exec(); delete app; // cleanup memory managers MemoryManager::cleanup(); return ret; }
void LatexDocVisitor::visit(DocVerbatim *s) { //static bool latexSourceCode = Config_getBool("LATEX_SOURCE_CODE"); if (m_hide) return; switch(s->type()) { case DocVerbatim::Code: //if (latexSourceCode) //{ // m_t << "\n\n\\begin{footnotesize}\\begin{alltt}" << endl; //} //else { m_t << "\n\\begin{DoxyCode}\n"; } Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(), s->isExample(),s->exampleFile()); //if (latexSourceCode) //{ // m_t << "\\end{alltt}\\end{footnotesize}" << endl; //} //else { m_t << "\\end{DoxyCode}\n"; } break; case DocVerbatim::Verbatim: m_t << "\\begin{DoxyVerb}"; m_t << s->text(); m_t << "\\end{DoxyVerb}\n"; break; case DocVerbatim::HtmlOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: /* nothing */ break; case DocVerbatim::LatexOnly: m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString("LATEX_OUTPUT")+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); m_t << "\\begin{center}\n"; startDotFile(fileName,"","",FALSE); endDotFile(FALSE); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d", (Config_getString("LATEX_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << "\\begin{center}\n"; writeMscFile(baseName); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; } }
void Win32DateTimeTest::testLocales(TestLog *log) { SYSTEMTIME winNow; UDate icuNow = 0; SYSTEMTIME st; FILETIME ft; UnicodeString zoneID; const TimeZone *tz = TimeZone::createDefault(); TIME_ZONE_INFORMATION tzi; tz->getID(zoneID); if (! uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length())) { UBool found = FALSE; int32_t ec = TimeZone::countEquivalentIDs(zoneID); for (int z = 0; z < ec; z += 1) { UnicodeString equiv = TimeZone::getEquivalentID(zoneID, z); if (found = uprv_getWindowsTimeZoneInfo(&tzi, equiv.getBuffer(), equiv.length())) { break; } } if (! found) { GetTimeZoneInformation(&tzi); } } GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); SystemTimeToTzSpecificLocalTime(&tzi, &st, &winNow); int64_t wftNow = ((int64_t) ft.dwHighDateTime << 32) + ft.dwLowDateTime; UErrorCode status = U_ZERO_ERROR; int64_t udtsNow = utmscale_fromInt64(wftNow, UDTS_WINDOWS_FILE_TIME, &status); icuNow = (UDate) utmscale_toInt64(udtsNow, UDTS_ICU4C_TIME, &status); int32_t lcidCount = 0; Win32Utilities::LCIDRecord *lcidRecords = Win32Utilities::getLocales(lcidCount); for(int i = 0; i < lcidCount; i += 1) { UErrorCode status = U_ZERO_ERROR; WCHAR longDateFormat[81], longTimeFormat[81], wdBuffer[256], wtBuffer[256]; int32_t calType = 0; // NULL localeID means ICU didn't recognize this locale if (lcidRecords[i].localeID == NULL) { continue; } GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_SLONGDATE, longDateFormat, 81); GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_STIMEFORMAT, longTimeFormat, 81); GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_RETURN_NUMBER|LOCALE_ICALENDARTYPE, (LPWSTR) calType, sizeof(int32_t)); char localeID[64]; uprv_strcpy(localeID, lcidRecords[i].localeID); uprv_strcat(localeID, getCalendarType(calType)); UnicodeString ubBuffer, udBuffer, utBuffer; Locale ulocale(localeID); int32_t wdLength, wtLength; wdLength = GetDateFormatW(lcidRecords[i].lcid, DATE_LONGDATE, &winNow, NULL, wdBuffer, UPRV_LENGTHOF(wdBuffer)); wtLength = GetTimeFormatW(lcidRecords[i].lcid, 0, &winNow, NULL, wtBuffer, UPRV_LENGTHOF(wtBuffer)); if (uprv_strchr(localeID, '@') > 0) { uprv_strcat(localeID, ";"); } else { uprv_strcat(localeID, "@"); } uprv_strcat(localeID, "compat=host"); Locale wlocale(localeID); DateFormat *wbf = DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull, wlocale); DateFormat *wdf = DateFormat::createDateInstance(DateFormat::kFull, wlocale); DateFormat *wtf = DateFormat::createTimeInstance(DateFormat::kFull, wlocale); wbf->format(icuNow, ubBuffer); wdf->format(icuNow, udBuffer); wtf->format(icuNow, utBuffer); if (ubBuffer.indexOf(wdBuffer, wdLength - 1, 0) < 0) { UnicodeString baseName(wlocale.getBaseName()); UnicodeString expected(wdBuffer); log->errln("DateTime format error for locale " + baseName + ": expected date \"" + expected + "\" got \"" + ubBuffer + "\""); } if (ubBuffer.indexOf(wtBuffer, wtLength - 1, 0) < 0) { UnicodeString baseName(wlocale.getBaseName()); UnicodeString expected(wtBuffer); log->errln("DateTime format error for locale " + baseName + ": expected time \"" + expected + "\" got \"" + ubBuffer + "\""); } if (udBuffer.compare(wdBuffer) != 0) { UnicodeString baseName(wlocale.getBaseName()); UnicodeString expected(wdBuffer); log->errln("Date format error for locale " + baseName + ": expected \"" + expected + "\" got \"" + udBuffer + "\""); } if (utBuffer.compare(wtBuffer) != 0) { UnicodeString baseName(wlocale.getBaseName()); UnicodeString expected(wtBuffer); log->errln("Time format error for locale " + baseName + ": expected \"" + expected + "\" got \"" + utBuffer + "\""); } delete wbf; delete wdf; delete wtf; } Win32Utilities::freeLocales(lcidRecords); delete tz; }
void RTFDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; DBG_RTF("{\\comment RTFDocVisitor::visit(DocVerbatim)}\n"); QCString lang = m_langExt; if (!s->language().isEmpty()) // explicit language setting { lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); Doxygen::parserManager->getParser(lang) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::Verbatim: m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); filter(s->text(),TRUE); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::RtfOnly: m_t << s->text(); break; case DocVerbatim::HtmlOnly: case DocVerbatim::LatexOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: case DocVerbatim::DocbookOnly: /* nothing */ break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString(RTF_OUTPUT)+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); writeDotFile(fileName, s->hasCaption()); visitCaption(this, s->children()); includePicturePostRTF(true, s->hasCaption()); if (Config_getBool(DOT_CLEANUP)) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d%s", (Config_getString(RTF_OUTPUT)+"/inline_mscgraph_").data(), mscindex++, ".msc" ); QFile file(baseName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); writeMscFile(baseName, s->hasCaption()); visitCaption(this, s->children()); includePicturePostRTF(true, s->hasCaption()); if (Config_getBool(DOT_CLEANUP)) file.remove(); } break; case DocVerbatim::PlantUML: { static QCString rtfOutput = Config_getString(RTF_OUTPUT); QCString baseName = writePlantUMLSource(rtfOutput,s->exampleFile(),s->text()); writePlantUMLFile(baseName, s->hasCaption()); visitCaption(this, s->children()); includePicturePostRTF(true, s->hasCaption()); } break; } m_lastIsPara=FALSE; }
bool HtmlWriter::write(const vector<InstanceInfo>& instances) { m_Title = baseName(m_Config.roomName); ifstream templateFile; templateFile.open(m_Config.templateName); if(!templateFile.good()) templateFile.open(sdkDir() + "/html/" + m_Config.templateName); if(!templateFile.good()) { cerr << "Could not open template file" << endl; return false; } m_Output.open(m_Config.outputDir + m_Config.outputHtml); m_Output.precision(3); m_Output.setf( std::ios::fixed, std:: ios::floatfield ); for(size_t i=0; i < instances.size(); i++) { const InstanceInfo& inst = instances[i]; if(inst.type == "origin") { m_Origin = inst.transform; } } cout << "Writing room HTML" << endl; while(!templateFile.eof()) { char buffer[300]; templateFile.getline(buffer,sizeof(buffer)); if(strcmp(buffer,"%ROOM_TITLE%") == 0) { m_Output << "<title>" << m_Title << "</title>" << endl; continue; } if(strcmp(buffer,"%ASSETS%") == 0) { writeAssets(instances); continue; } if(strcmp(buffer,"%ROOM_HTML%") == 0) { writeRoomTag(instances); continue; } m_Output << buffer << endl; } m_Output.close(); cout << "HTML Finished" << endl; return true; }
int VirtualMachine::openFileInWorkingDirectory(std::FILE*& f, std::string& baseName_, const char *mode, bool createOnly_) { f = (std::FILE *) 0; try { std::string fullName; bool haveFileName = false; if (baseName_.length() > 0) { haveFileName = true; // convert file name to lower case, replace invalid characters with '_' std::string baseName(baseName_); stringToLowerCase(baseName); for (size_t i = 0; i < baseName.length(); i++) { const std::string& s = baseName; if (!((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= '0' && s[i] <= '9') || s[i] == '.' || s[i] == '+' || s[i] == '-' || s[i] == '_')) baseName[i] = '_'; } fullName = fileIOWorkingDirectory + baseName; } else { if (fileNameCallback) fileNameCallback(fileNameCallbackUserData, fullName); if (fullName.length() == 0) return -2; // error: invalid file name baseName_ = fullName; } // attempt to stat() file #ifndef WIN32 struct stat st; std::memset(&st, 0, sizeof(struct stat)); int err = stat(fullName.c_str(), &st); if (err != 0 && haveFileName) { // not found, try case insensitive file search std::string tmpName(fullName); tmpName[0] = tmpName.c_str()[0]; // unshare string DIR *dir_; dir_ = opendir(fileIOWorkingDirectory.c_str()); if (dir_) { do { struct dirent *ent_ = readdir(dir_); if (!ent_) break; bool foundMatch = true; size_t offs = fileIOWorkingDirectory.length(); const char *s1 = fullName.c_str() + offs; const char *s2 = &(ent_->d_name[0]); size_t i = 0; while (!(s1[i] == '\0' && s2[i] == '\0')) { if (s1[i] != s2[i]) { if (!(s2[i] >= 'A' && s2[i] <= 'Z' && s1[i] == (s2[i] + ('a' - 'A')))) { foundMatch = false; break; } } tmpName[offs + i] = s2[i]; i++; } if (foundMatch) { std::memset(&st, 0, sizeof(struct stat)); err = stat(tmpName.c_str(), &st); } } while (err != 0); closedir(dir_); } if (err == 0) fullName = tmpName; } #else struct _stat st; std::memset(&st, 0, sizeof(struct _stat)); int err = _stat(fullName.c_str(), &st); #endif if (err != 0) { if (mode == (char *) 0 || mode[0] != 'w') return -3; // error: cannot find file } else { #ifndef WIN32 if (!(S_ISREG(st.st_mode))) return -4; // error: not a regular file #else if (!(st.st_mode & _S_IFREG)) return -4; // error: not a regular file #endif if (createOnly_) return -6; // error: the file already exists } // FIXME: the file may possibly be created, changed, or removed between // calling stat() and fopen() f = std::fopen(fullName.c_str(), mode); if (!f) return -5; // error: cannot open file } catch (...) { if (f) { std::fclose(f); f = (std::FILE *) 0; } return -1; } return 0; }
bool GMPChild::LoadPluginLibrary(const std::string& aPluginPath) { nsDependentCString pluginPath(aPluginPath.c_str()); nsCOMPtr<nsIFile> libFile; nsresult rv = NS_NewNativeLocalFile(pluginPath, true, getter_AddRefs(libFile)); if (NS_FAILED(rv)) { return false; } nsAutoString leafName; if (NS_FAILED(libFile->GetLeafName(leafName))) { return false; } nsAutoString baseName(Substring(leafName, 4, leafName.Length() - 1)); #if defined(XP_MACOSX) nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib"); #elif defined(OS_POSIX) nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".so"); #elif defined(XP_WIN) nsAutoString binaryName = baseName + NS_LITERAL_STRING(".dll"); #else #error not defined #endif libFile->AppendRelativePath(binaryName); nsAutoCString nativePath; libFile->GetNativePath(nativePath); #if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX) // Enable sandboxing here -- we know the plugin file's path, but // this process's execution hasn't been affected by its content yet. mozilla::SetMediaPluginSandbox(nativePath.get()); #endif mLib = PR_LoadLibrary(nativePath.get()); if (!mLib) { return false; } GMPInitFunc initFunc = reinterpret_cast<GMPInitFunc>(PR_FindFunctionSymbol(mLib, "GMPInit")); if (!initFunc) { return false; } auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); if (initFunc(platformAPI) != GMPNoErr) { return false; } mGetAPIFunc = reinterpret_cast<GMPGetAPIFunc>(PR_FindFunctionSymbol(mLib, "GMPGetAPI")); if (!mGetAPIFunc) { return false; } return true; }
bool CTemplateLoader::TemplateExists(const std::string& templateName) const { size_t pos = templateName.rfind('|'); std::string baseName(pos != std::string::npos ? templateName.substr(pos+1) : templateName); return VfsFileExists(VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(baseName + ".xml")); }
QVariant ccDBRoot::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); const ccHObject *item = static_cast<ccHObject*>(index.internalPointer()); assert(item); if (!item) return QVariant(); if (role == Qt::DisplayRole) { QString baseName(item->getName()); if (baseName.isEmpty()) baseName = QString("no name"); //specific case if (item->isA(CC_2D_LABEL)) baseName = QString("2D label: ")+baseName; else if (item->isA(CC_2D_VIEWPORT_LABEL)) baseName = QString("2D area label: ")+baseName; return QVariant(baseName); } if (role == Qt::EditRole) { return QVariant(item->getName()); } else if (role == Qt::DecorationRole) { bool locked = item->isLocked(); switch (item->getClassID()) { case CC_HIERARCHY_OBJECT: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbHObjectSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbHObjectSymbol.png")); case CC_POINT_CLOUD: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbCloudSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbCloudSymbol.png")); //all primitives case CC_PLANE: case CC_SPHERE: case CC_TORUS: case CC_CYLINDER: case CC_CONE: case CC_BOX: case CC_DISH: case CC_EXTRU: case CC_FACET: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbMiscGeomSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbMiscGeomSymbol.png")); case CC_MESH: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbMeshSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbMeshSymbol.png")); case CC_MESH_GROUP: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbMeshGroupSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbMeshGroupSymbol.png")); case CC_POINT_OCTREE: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbOctreeSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbOctreeSymbol.png")); case CC_CALIBRATED_IMAGE: return QIcon(QString::fromUtf8(":/CC/images/dbCalibratedImageSymbol.png")); case CC_IMAGE: return QIcon(QString::fromUtf8(":/CC/images/dbImageSymbol.png")); case CC_SENSOR: case CC_GBL_SENSOR: return QIcon(QString::fromUtf8(":/CC/images/dbSensorSymbol.png")); case CC_MATERIAL_SET: return QIcon(QString::fromUtf8(":/CC/images/dbMaterialSymbol.png")); case CC_NORMALS_ARRAY: case CC_NORMAL_INDEXES_ARRAY: case CC_RGB_COLOR_ARRAY: case CC_TEX_COORDS_ARRAY: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbContainerSymbolLocked.png")); else return QIcon(QString::fromUtf8(":/CC/images/dbContainerSymbol.png")); case CC_2D_LABEL: return QIcon(QString::fromUtf8(":/CC/images/dbLabelSymbol.png")); case CC_2D_VIEWPORT_OBJECT: return QIcon(QString::fromUtf8(":/CC/images/dbViewportSymbol.png")); case CC_2D_VIEWPORT_LABEL: return QIcon(QString::fromUtf8(":/CC/images/dbAreaLabelSymbol.png")); default: if (locked) return QIcon(QString::fromUtf8(":/CC/images/dbLockSymbol.png")); else return QVariant(); } } else if (role == Qt::CheckStateRole) { if (item->isEnabled()) return Qt::Checked; else return Qt::Unchecked; } return QVariant(); }
void NBFolderView::doOpen( QModelIndex idx ) { /* This slot is triggered when the user double clicks or presses enter */ Q_UNUSED( idx ); QList<QModelIndex> selectedList = getSelection(); foreach( QModelIndex index, selectedList ) { QString fileToBeOpened = fsModel->nodePath( index ); if ( not isReadable( fileToBeOpened ) ) { QString title = tr( "Access Error" ); QString text = tr( "You do not have enough permissions to open <b>%1</b>. " ).arg( baseName( fileToBeOpened ) ); if ( isDir( fileToBeOpened ) ) text += tr( "Please change the permissions of the directory to enter it." ); else text += tr( "Please change the permissions of the file to edit/view it." ); NBMessageDialog::error( this, title, text ); return; } if ( isDir( fileToBeOpened ) ) { qDebug() << "Opening dir:" << fileToBeOpened.toLocal8Bit().data(); if ( index == idx ) { setCursor( QCursor( Qt::WaitCursor ) ); fsModel->setRootPath( fileToBeOpened ); setCursor( QCursor( Qt::ArrowCursor ) ); } else { emit newTab( fileToBeOpened ); } } else if ( isFile( fileToBeOpened ) ) { if ( isExec( fileToBeOpened ) and not isText( fileToBeOpened ) ) { /* * * We make sure that @v fileToBeOpened is really an executable file, * i.e it is one of shellscript, install file, or x-exec or x-sharedlib * or something of the sort and not a jpg file with exec perms * */ qDebug( "Executing %s... [%s]", fileToBeOpened.toLocal8Bit().data(), ( QProcess::startDetached( fileToBeOpened ) ? "DONE" : " FAILED" ) ); } else { NBAppFile app = NBAppEngine::instance()->xdgDefaultApp( mimeDb.mimeTypeForFile( fileToBeOpened ) ); if ( not app.isValid() ) doOpenWithCmd(); QStringList exec = app.execArgs(); // Prepare @v exec if ( app.takesArgs() ) { if ( app.multipleArgs() ) { int idx = exec.indexOf( "<#NEWBREEZE-ARG-FILES#>" ); exec.removeAt( idx ); exec.insert( idx, fileToBeOpened ); } else { int idx = exec.indexOf( "<#NEWBREEZE-ARG-FILE#>" ); exec.removeAt( idx ); exec.insert( idx, fileToBeOpened ); } } else { exec << fileToBeOpened; } qDebug( "Opening file: %s [%s]", fileToBeOpened.toLocal8Bit().data(), ( QProcess::startDetached( exec.takeFirst(), exec ) ? "DONE" : " FAILED" ) ); } } else { QString title = QString( "Error" ); QString text = QString( "I really do not have any idea how to open <b>%1</b>." ).arg( index.data().toString() ); NBMessageDialog::error( this, title, text ); qDebug() << "Cannot open file:" << fileToBeOpened.toLocal8Bit().data(); return; } }
int main( int argc, char * * argv ) { // initialize memory managers MemoryManager::init(); NotePlayHandleManager::init(); // intialize RNG srand( getpid() + time( 0 ) ); disable_denormals(); bool coreOnly = false; bool fullscreen = true; bool exitAfterImport = false; bool allowRoot = false; bool renderLoop = false; bool renderTracks = false; QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile; // first of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" || arg == "--render" || arg == "-r" ) { coreOnly = true; } else if( arg == "--rendertracks" ) { coreOnly = true; renderTracks = true; } else if( arg == "--allowroot" ) { allowRoot = true; } else if( arg == "--geometry" || arg == "-geometry") { if( arg == "--geometry" ) { // Delete the first "-" so Qt recognize the option strcpy(argv[i], "-geometry"); } // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } #ifndef LMMS_BUILD_WIN32 if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" ); return EXIT_FAILURE; } #endif QCoreApplication * app = coreOnly ? new QCoreApplication( argc, argv ) : new QApplication( argc, argv ) ; Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); ProjectRenderer::OutputSettings os( 44100, false, 160, ProjectRenderer::Depth_16Bit ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; // second of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--version" || arg == "-v" ) { printVersion( argv[0] ); return EXIT_SUCCESS; } else if( arg == "--help" || arg == "-h" ) { printHelp(); return EXIT_SUCCESS; } else if( arg == "--upgrade" || arg == "-u" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } DataFile dataFile( QString::fromLocal8Bit( argv[i] ) ); if( argc > i+1 ) // output file specified { dataFile.writeFile( QString::fromLocal8Bit( argv[i+1] ) ); } else // no output file specified; use stdout { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return EXIT_SUCCESS; } else if( arg == "--allowroot" ) { // Ignore, processed earlier #ifdef LMMS_BUILD_WIN32 if( allowRoot ) { printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" ); } #endif } else if( arg == "--dump" || arg == "-d" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } QFile f( QString::fromLocal8Bit( argv[i] ) ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return EXIT_SUCCESS; } else if( arg == "--render" || arg == "-r" || arg == "--rendertracks" ) { ++i; if( i == argc ) { printf( "\nNo input file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); renderOut = fileToLoad; } else if( arg == "--loop" || arg == "-l" ) { renderLoop = true; } else if( arg == "--output" || arg == "-o" ) { ++i; if( i == argc ) { printf( "\nNo output file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } renderOut = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--format" || arg == "-f" ) { ++i; if( i == argc ) { printf( "\nNo output format specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ext = QString( argv[i] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif else { printf( "\nInvalid output format %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--samplerate" || arg == "-s" ) { ++i; if( i == argc ) { printf( "\nNo samplerate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } sample_rate_t sr = QString( argv[i] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.samplerate = sr; } else { printf( "\nInvalid samplerate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--bitrate" || arg == "-b" ) { ++i; if( i == argc ) { printf( "\nNo bitrate specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int br = QString( argv[i] ).toUInt(); if( br >= 64 && br <= 384 ) { os.bitrate = br; } else { printf( "\nInvalid bitrate %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg =="--float" || arg == "-a" ) { os.depth = ProjectRenderer::Depth_32Bit; } else if( arg == "--interpolation" || arg == "-i" ) { ++i; if( i == argc ) { printf( "\nNo interpolation method specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } const QString ip = QString( argv[i] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { printf( "\nInvalid interpolation method %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--oversampling" || arg == "-x" ) { ++i; if( i == argc ) { printf( "\nNo oversampling specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } int o = QString( argv[i] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: printf( "\nInvalid oversampling %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } } else if( arg == "--import" ) { ++i; if( i == argc ) { printf( "\nNo file specified for importing.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) if( QString( argv[i + 1] ) == "-e" ) { exitAfterImport = true; ++i; } } else if( arg == "--profile" || arg == "-p" ) { ++i; if( i == argc ) { printf( "\nNo profile specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } profilerOutputFile = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--config" || arg == "-c" ) { ++i; if( i == argc ) { printf( "\nNo configuration file specified.\n\n" "Try \"%s --help\" for more information.\n\n", argv[0] ); return EXIT_FAILURE; } configFile = QString::fromLocal8Bit( argv[i] ); } else { if( argv[i][0] == '-' ) { printf( "\nInvalid option %s.\n\n" "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); return EXIT_FAILURE; } fileToLoad = QString::fromLocal8Bit( argv[i] ); } } // Test file argument before continuing if( !fileToLoad.isEmpty() ) { fileCheck( fileToLoad ); } else if( !fileToImport.isEmpty() ) { fileCheck( fileToImport ); } ConfigManager::inst()->loadConfigFile(configFile); // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) { pos = QLocale::system().name().left( 2 ); } #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR ConfigManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif #ifdef LMMS_BUILD_WIN32 if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) { printf( "Notice: could not set high priority.\n" ); } #endif #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_SIGINFO; if ( sigemptyset( &sa.sa_mask ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } if ( sigaction( SIGPIPE, &sa, NULL ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } #endif bool destroyEngine = false; // if we have an output file for rendering, just render the song // without starting the GUI if( !renderOut.isEmpty() ) { Engine::init( true ); destroyEngine = true; printf( "Loading project...\n" ); Engine::getSong()->loadProject( fileToLoad ); if( Engine::getSong()->isEmpty() ) { printf("The project %s is empty, aborting!\n", fileToLoad.toUtf8().constData() ); exit( EXIT_FAILURE ); } printf( "Done\n" ); Engine::getSong()->setExportLoop( renderLoop ); // when rendering multiple tracks, renderOut is a directory // otherwise, it is a file, so we need to append the file extension if ( !renderTracks ) { renderOut = baseName( renderOut ) + ProjectRenderer::getFileExtensionFromFormat(eff); } // create renderer RenderManager * r = new RenderManager( qs, os, eff, renderOut ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); if( profilerOutputFile.isEmpty() == false ) { Engine::mixer()->profiler().setOutputFile( profilerOutputFile ); } // start now! if ( renderTracks ) { r->renderTracks(); } else { r->renderProject(); } } else // otherwise, start the GUI { new GuiApplication(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = ConfigManager::inst()->recoveryFile(); bool recoveryFilePresent = QFileInfo( recoveryFile ).exists() && QFileInfo( recoveryFile ).isFile(); bool autoSaveEnabled = ConfigManager::inst()->value( "ui", "enableautosave" ).toInt(); if( recoveryFilePresent ) { QMessageBox mb; mb.setWindowTitle( MainWindow::tr( "Project recovery" ) ); mb.setText( QString( "<html>" "<p style=\"margin-left:6\">%1</p>" "<table cellpadding=\"3\">" " <tr>" " <td><b>%2</b></td>" " <td>%3</td>" " </tr>" " <tr>" " <td><b>%4</b></td>" " <td>%5</td>" " </tr>" " <tr>" " <td><b>%6</b></td>" " <td>%7</td>" " </tr>" "</table>" "</html>" ).arg( MainWindow::tr( "There is a recovery file present. " "It looks like the last session did not end " "properly or another instance of LMMS is " "already running. Do you want to recover the " "project of this session?" ), MainWindow::tr( "Recover" ), MainWindow::tr( "Recover the file. Please don't run " "multiple instances of LMMS when you do this." ), MainWindow::tr( "Ignore" ), MainWindow::tr( "Launch LMMS as usual but with " "automatic backup disabled to prevent the " "present recover file from being overwritten." ), MainWindow::tr( "Discard" ), MainWindow::tr( "Launch a default session and delete " "the restored files. This is not reversible." ) ) ); mb.setIcon( QMessageBox::Warning ); mb.setWindowIcon( embed::getIconPixmap( "icon" ) ); mb.setWindowFlags( Qt::WindowCloseButtonHint ); QPushButton * recover; QPushButton * discard; QPushButton * ignore; QPushButton * exit; #if QT_VERSION >= 0x050000 // setting all buttons to the same roles allows us // to have a custom layout discard = mb.addButton( MainWindow::tr( "Discard" ), QMessageBox::AcceptRole ); ignore = mb.addButton( MainWindow::tr( "Ignore" ), QMessageBox::AcceptRole ); recover = mb.addButton( MainWindow::tr( "Recover" ), QMessageBox::AcceptRole ); # else // in qt4 the button order is reversed recover = mb.addButton( MainWindow::tr( "Recover" ), QMessageBox::AcceptRole ); ignore = mb.addButton( MainWindow::tr( "Ignore" ), QMessageBox::AcceptRole ); discard = mb.addButton( MainWindow::tr( "Discard" ), QMessageBox::AcceptRole ); #endif // have a hidden exit button exit = mb.addButton( "", QMessageBox::RejectRole); exit->setVisible(false); // set icons recover->setIcon( embed::getIconPixmap( "recover" ) ); discard->setIcon( embed::getIconPixmap( "discard" ) ); ignore->setIcon( embed::getIconPixmap( "ignore" ) ); mb.setDefaultButton( recover ); mb.setEscapeButton( exit ); mb.exec(); if( mb.clickedButton() == discard ) { gui->mainWindow()->sessionCleanup(); } else if( mb.clickedButton() == recover ) // Recover { fileToLoad = recoveryFile; gui->mainWindow()->setSession( MainWindow::SessionState::Recover ); } else if( mb.clickedButton() == ignore ) { if( autoSaveEnabled ) { gui->mainWindow()->setSession( MainWindow::SessionState::Limited ); } } else // Exit { return 0; } } // first show the Main Window and then try to load given file // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } if( !fileToLoad.isEmpty() ) { if( fileToLoad == recoveryFile ) { Engine::getSong()->createNewProjectFromTemplate( fileToLoad ); } else { Engine::getSong()->loadProject( fileToLoad ); } } else if( !fileToImport.isEmpty() ) { ImportFilter::import( fileToImport, Engine::getSong() ); if( exitAfterImport ) { return EXIT_SUCCESS; } } // If enabled, open last project if there is one. Else, create // a new one. Also skip recently opened file if limited session to // lower the chance of opening an already opened file. else if( ConfigManager::inst()-> value( "app", "openlastproject" ).toInt() && !ConfigManager::inst()-> recentlyOpenedProjects().isEmpty() && gui->mainWindow()->getSession() != MainWindow::SessionState::Limited ) { QString f = ConfigManager::inst()-> recentlyOpenedProjects().first(); QFileInfo recentFile( f ); if ( recentFile.exists() ) { Engine::getSong()->loadProject( f ); } else { Engine::getSong()->createNewProject(); } } else { Engine::getSong()->createNewProject(); } // Finally we start the auto save timer and also trigger the // autosave one time as recover.mmp is a signal to possible other // instances of LMMS. if( autoSaveEnabled && gui->mainWindow()->getSession() != MainWindow::SessionState::Limited ) { gui->mainWindow()->autoSaveTimerReset(); gui->mainWindow()->autoSave(); } } const int ret = app->exec(); delete app; if( destroyEngine ) { Engine::destroy(); } // cleanup memory managers MemoryManager::cleanup(); // ProjectRenderer::updateConsoleProgress() doesn't return line after render if( coreOnly ) { printf( "\n" ); } return ret; }
void RTFDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; DBG_RTF("{\\comment RTFDocVisitor::visit(DocVerbatim)}\n"); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(), s->isExample(),s->exampleFile()); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::Verbatim: m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); filter(s->text(),TRUE); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::HtmlOnly: case DocVerbatim::LatexOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: /* nothing */ break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString("RTF_OUTPUT")+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); m_t << "\\par{\\qc "; // center picture writeDotFile(fileName); m_t << "} "; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d", (Config_getString("RTF_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << "\\par{\\qc "; // center picture writeMscFile(baseName); m_t << "} "; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; } m_lastIsPara=FALSE; }
void MidiMusicPlayer::playSEQ(uint32 size, bool loop) { // MIDI.DAT holds the file names in DW1 PSX Common::String baseName((char *)g_midiBuffer.pDat, size); Common::String seqName = baseName + ".SEQ"; // TODO: Load the instrument bank (<baseName>.VB and <baseName>.VH) Common::File seqFile; if (!seqFile.open(seqName)) error("Failed to open SEQ file '%s'", seqName.c_str()); if (seqFile.readUint32LE() != MKTAG('S', 'E', 'Q', 'p')) error("Failed to find SEQp tag"); // Make sure we don't have a SEP file (with multiple SEQ's inside) if (seqFile.readUint32BE() != 1) error("Can only play SEQ files, not SEP"); uint16 ppqn = seqFile.readUint16BE(); uint32 tempo = seqFile.readUint16BE() << 8; tempo |= seqFile.readByte(); /* uint16 beat = */ seqFile.readUint16BE(); // SEQ is directly based on SMF and we'll use that to our advantage here // and convert to SMF and then use the SMF MidiParser. // Calculate the SMF size we'll need uint32 dataSize = seqFile.size() - 15; uint32 actualSize = dataSize + 7 + 22; // Resize the buffer if necessary if (g_midiBuffer.size < actualSize) { g_midiBuffer.pDat = (byte *)realloc(g_midiBuffer.pDat, actualSize); assert(g_midiBuffer.pDat); } // Now construct the header WRITE_BE_UINT32(g_midiBuffer.pDat, MKTAG('M', 'T', 'h', 'd')); WRITE_BE_UINT32(g_midiBuffer.pDat + 4, 6); // header size WRITE_BE_UINT16(g_midiBuffer.pDat + 8, 0); // type 0 WRITE_BE_UINT16(g_midiBuffer.pDat + 10, 1); // one track WRITE_BE_UINT16(g_midiBuffer.pDat + 12, ppqn); WRITE_BE_UINT32(g_midiBuffer.pDat + 14, MKTAG('M', 'T', 'r', 'k')); WRITE_BE_UINT32(g_midiBuffer.pDat + 18, dataSize + 7); // SEQ data size + tempo change event size // Add in a fake tempo change event WRITE_BE_UINT32(g_midiBuffer.pDat + 22, 0x00FF5103); // no delta, meta event, tempo change, param size = 3 WRITE_BE_UINT16(g_midiBuffer.pDat + 26, tempo >> 8); g_midiBuffer.pDat[28] = tempo & 0xFF; // Now copy in the rest of the events seqFile.read(g_midiBuffer.pDat + 29, dataSize); seqFile.close(); MidiParser *parser = MidiParser::createParser_SMF(); if (parser->loadMusic(g_midiBuffer.pDat, actualSize)) { parser->setTrack(0); parser->setMidiDriver(this); parser->setTimerRate(getBaseTempo()); parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); parser->property(MidiParser::mpSendSustainOffOnNotesOff, 1); _parser = parser; _isLooping = loop; _isPlaying = true; } else { delete parser; } }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(finalPath.get())); GRefPtr<GFile> dir = adoptGRef(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GRefPtr<GFile> resolvedFile = adoptGRef(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } if (moduleMixesGtkSymbols(m_module)) { LOG(Plugins, "Ignoring module '%s' to avoid mixing GTK+ 2 and GTK+ 3 symbols.\n", m_path.utf8().data()); return false; } m_isLoaded = true; if (!g_strcmp0(baseName.get(), "libflashplayer.so")) { // Flash plugin can produce X errors that are handled by the GDK X error handler, which // exits the process. Since we don't want to crash due to flash bugs, we install a // custom error handler to show a warning when a X error happens without aborting. XSetErrorHandler(webkitgtkXError); } NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
int main( int argc, char * * argv ) { #ifdef LMMS_DEBUG_FPE // Enable exceptions for certain floating point results feenableexcept( FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW); // Install the trap handler // register signal SIGFPE and signal handler signal(SIGFPE, signalHandler); #endif #ifdef LMMS_BUILD_WIN32 // Don't touch redirected streams here // GetStdHandle should be called before AttachConsole HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hStdErr = GetStdHandle(STD_ERROR_HANDLE); FILE *fIn, *fOut, *fErr; // Enable console output if available if (AttachConsole(ATTACH_PARENT_PROCESS)) { if (!hStdIn) { freopen_s(&fIn, "CONIN$", "r", stdin); } if (!hStdOut) { freopen_s(&fOut, "CONOUT$", "w", stdout); } if (!hStdErr) { freopen_s(&fErr, "CONOUT$", "w", stderr); } } // Make Qt's debug message handlers work qInstallMessageHandler(consoleMessageHandler); #endif // initialize memory managers NotePlayHandleManager::init(); // intialize RNG srand( getpid() + time( 0 ) ); disable_denormals(); bool coreOnly = false; bool fullscreen = true; bool exitAfterImport = false; bool allowRoot = false; bool renderLoop = false; bool renderTracks = false; QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile; // first of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" || arg == "render" || arg == "--render" || arg == "-r" ) { coreOnly = true; } else if( arg == "rendertracks" || arg == "--rendertracks" ) { coreOnly = true; renderTracks = true; } else if( arg == "--allowroot" ) { allowRoot = true; } else if( arg == "--geometry" || arg == "-geometry") { if( arg == "--geometry" ) { // Delete the first "-" so Qt recognize the option strcpy(argv[i], "-geometry"); } // option -geometry is filtered by Qt later, // so we need to check its presence now to // determine, if the application should run in // fullscreen mode (default, no -geometry given). fullscreen = false; } } #if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BUILD_HAIKU) if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" ); return EXIT_FAILURE; } #endif #ifdef LMMS_BUILD_LINUX // don't let OS steal the menu bar. FIXME: only effective on Qt4 QCoreApplication::setAttribute( Qt::AA_DontUseNativeMenuBar ); #endif #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QCoreApplication * app = coreOnly ? new QCoreApplication( argc, argv ) : new MainApplication( argc, argv ); Mixer::qualitySettings qs( Mixer::qualitySettings::Mode_HighQuality ); OutputSettings os( 44100, OutputSettings::BitRateSettings(160, false), OutputSettings::Depth_16Bit, OutputSettings::StereoMode_JointStereo ); ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile; // second of two command-line parsing stages for( int i = 1; i < argc; ++i ) { QString arg = argv[i]; if( arg == "--version" || arg == "-v" ) { printVersion( argv[0] ); return EXIT_SUCCESS; } else if( arg == "--help" || arg == "-h" ) { printHelp(); return EXIT_SUCCESS; } else if( arg == "upgrade" || arg == "--upgrade" || arg == "-u") { ++i; if( i == argc ) { return noInputFileError(); } DataFile dataFile( QString::fromLocal8Bit( argv[i] ) ); if( argc > i+1 ) // output file specified { dataFile.writeFile( QString::fromLocal8Bit( argv[i+1] ) ); } else // no output file specified; use stdout { QTextStream ts( stdout ); dataFile.write( ts ); fflush( stdout ); } return EXIT_SUCCESS; } else if( arg == "--allowroot" ) { // Ignore, processed earlier #ifdef LMMS_BUILD_WIN32 if( allowRoot ) { printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" ); } #endif } else if( arg == "dump" || arg == "--dump" || arg == "-d" ) { ++i; if( i == argc ) { return noInputFileError(); } QFile f( QString::fromLocal8Bit( argv[i] ) ); f.open( QIODevice::ReadOnly ); QString d = qUncompress( f.readAll() ); printf( "%s\n", d.toUtf8().constData() ); return EXIT_SUCCESS; } else if( arg == "render" || arg == "--render" || arg == "-r" || arg == "rendertracks" || arg == "--rendertracks" ) { ++i; if( i == argc ) { return noInputFileError(); } fileToLoad = QString::fromLocal8Bit( argv[i] ); renderOut = fileToLoad; } else if( arg == "--loop" || arg == "-l" ) { renderLoop = true; } else if( arg == "--output" || arg == "-o" ) { ++i; if( i == argc ) { return usageError( "No output file specified" ); } renderOut = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--format" || arg == "-f" ) { ++i; if( i == argc ) { return usageError( "No output format specified" ); } const QString ext = QString( argv[i] ); if( ext == "wav" ) { eff = ProjectRenderer::WaveFile; } #ifdef LMMS_HAVE_OGGVORBIS else if( ext == "ogg" ) { eff = ProjectRenderer::OggFile; } #endif #ifdef LMMS_HAVE_MP3LAME else if( ext == "mp3" ) { eff = ProjectRenderer::MP3File; } #endif else if (ext == "flac") { eff = ProjectRenderer::FlacFile; } else { return usageError( QString( "Invalid output format %1" ).arg( argv[i] ) ); } } else if( arg == "--samplerate" || arg == "-s" ) { ++i; if( i == argc ) { return usageError( "No samplerate specified" ); } sample_rate_t sr = QString( argv[i] ).toUInt(); if( sr >= 44100 && sr <= 192000 ) { os.setSampleRate(sr); } else { return usageError( QString( "Invalid samplerate %1" ).arg( argv[i] ) ); } } else if( arg == "--bitrate" || arg == "-b" ) { ++i; if( i == argc ) { return usageError( "No bitrate specified" ); } int br = QString( argv[i] ).toUInt(); if( br >= 64 && br <= 384 ) { OutputSettings::BitRateSettings bitRateSettings = os.getBitRateSettings(); bitRateSettings.setBitRate(br); os.setBitRateSettings(bitRateSettings); } else { return usageError( QString( "Invalid bitrate %1" ).arg( argv[i] ) ); } } else if( arg == "--mode" || arg == "-m" ) { ++i; if( i == argc ) { return usageError( "No stereo mode specified" ); } QString const mode( argv[i] ); if( mode == "s" ) { os.setStereoMode(OutputSettings::StereoMode_Stereo); } else if( mode == "j" ) { os.setStereoMode(OutputSettings::StereoMode_JointStereo); } else if( mode == "m" ) { os.setStereoMode(OutputSettings::StereoMode_Mono); } else { return usageError( QString( "Invalid stereo mode %1" ).arg( argv[i] ) ); } } else if( arg =="--float" || arg == "-a" ) { os.setBitDepth(OutputSettings::Depth_32Bit); } else if( arg == "--interpolation" || arg == "-i" ) { ++i; if( i == argc ) { return usageError( "No interpolation method specified" ); } const QString ip = QString( argv[i] ); if( ip == "linear" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_Linear; } else if( ip == "sincfastest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincFastest; } else if( ip == "sincmedium" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincMedium; } else if( ip == "sincbest" ) { qs.interpolation = Mixer::qualitySettings::Interpolation_SincBest; } else { return usageError( QString( "Invalid interpolation method %1" ).arg( argv[i] ) ); } } else if( arg == "--oversampling" || arg == "-x" ) { ++i; if( i == argc ) { return usageError( "No oversampling specified" ); } int o = QString( argv[i] ).toUInt(); switch( o ) { case 1: qs.oversampling = Mixer::qualitySettings::Oversampling_None; break; case 2: qs.oversampling = Mixer::qualitySettings::Oversampling_2x; break; case 4: qs.oversampling = Mixer::qualitySettings::Oversampling_4x; break; case 8: qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: return usageError( QString( "Invalid oversampling %1" ).arg( argv[i] ) ); } } else if( arg == "--import" ) { ++i; if( i == argc ) { return usageError( "No file specified for importing" ); } fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) if( QString( argv[i + 1] ) == "-e" ) { exitAfterImport = true; ++i; } } else if( arg == "--profile" || arg == "-p" ) { ++i; if( i == argc ) { return usageError( "No profile specified" ); } profilerOutputFile = QString::fromLocal8Bit( argv[i] ); } else if( arg == "--config" || arg == "-c" ) { ++i; if( i == argc ) { return usageError( "No configuration file specified" ); } configFile = QString::fromLocal8Bit( argv[i] ); } else { if( argv[i][0] == '-' ) { return usageError( QString( "Invalid option %1" ).arg( argv[i] ) ); } fileToLoad = QString::fromLocal8Bit( argv[i] ); } } // Test file argument before continuing if( !fileToLoad.isEmpty() ) { fileCheck( fileToLoad ); } else if( !fileToImport.isEmpty() ) { fileCheck( fileToImport ); } ConfigManager::inst()->loadConfigFile(configFile); // Hidden settings MixHelpers::setNaNHandler( ConfigManager::inst()->value( "app", "nanhandler", "1" ).toInt() ); // set language QString pos = ConfigManager::inst()->value( "app", "language" ); if( pos.isEmpty() ) { pos = QLocale::system().name().left( 2 ); } #ifdef LMMS_BUILD_WIN32 #undef QT_TRANSLATIONS_DIR #define QT_TRANSLATIONS_DIR ConfigManager::inst()->localeDir() #endif #ifdef QT_TRANSLATIONS_DIR // load translation for Qt-widgets/-dialogs loadTranslation( QString( "qt_" ) + pos, QString( QT_TRANSLATIONS_DIR ) ); #endif // load actual translation for LMMS loadTranslation( pos ); // try to set realtime priority #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H #ifndef __OpenBSD__ struct sched_param sparam; sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) + sched_get_priority_min( SCHED_FIFO ) ) / 2; if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 ) { printf( "Notice: could not set realtime priority.\n" ); } #endif #endif #endif #ifdef LMMS_BUILD_WIN32 if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) { printf( "Notice: could not set high priority.\n" ); } #endif #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_SIGINFO; if ( sigemptyset( &sa.sa_mask ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } if ( sigaction( SIGPIPE, &sa, NULL ) ) { fprintf( stderr, "Signal initialization failed.\n" ); } #endif bool destroyEngine = false; // if we have an output file for rendering, just render the song // without starting the GUI if( !renderOut.isEmpty() ) { Engine::init( true ); destroyEngine = true; printf( "Loading project...\n" ); Engine::getSong()->loadProject( fileToLoad ); if( Engine::getSong()->isEmpty() ) { printf("The project %s is empty, aborting!\n", fileToLoad.toUtf8().constData() ); exit( EXIT_FAILURE ); } printf( "Done\n" ); Engine::getSong()->setExportLoop( renderLoop ); // when rendering multiple tracks, renderOut is a directory // otherwise, it is a file, so we need to append the file extension if ( !renderTracks ) { renderOut = baseName( renderOut ) + ProjectRenderer::getFileExtensionFromFormat(eff); } // create renderer RenderManager * r = new RenderManager( qs, os, eff, renderOut ); QCoreApplication::instance()->connect( r, SIGNAL( finished() ), SLOT( quit() ) ); // timer for progress-updates QTimer * t = new QTimer( r ); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); if( profilerOutputFile.isEmpty() == false ) { Engine::mixer()->profiler().setOutputFile( profilerOutputFile ); } // start now! if ( renderTracks ) { r->renderTracks(); } else { r->renderProject(); } } else // otherwise, start the GUI { new GuiApplication(); // re-intialize RNG - shared libraries might have srand() or // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); // recover a file? QString recoveryFile = ConfigManager::inst()->recoveryFile(); bool recoveryFilePresent = QFileInfo( recoveryFile ).exists() && QFileInfo( recoveryFile ).isFile(); bool autoSaveEnabled = ConfigManager::inst()->value( "ui", "enableautosave" ).toInt(); if( recoveryFilePresent ) { QMessageBox mb; mb.setWindowTitle( MainWindow::tr( "Project recovery" ) ); mb.setText( QString( "<html>" "<p style=\"margin-left:6\">%1</p>" "<table cellpadding=\"3\">" " <tr>" " <td><b>%2</b></td>" " <td>%3</td>" " </tr>" " <tr>" " <td><b>%4</b></td>" " <td>%5</td>" " </tr>" "</table>" "</html>" ).arg( MainWindow::tr( "There is a recovery file present. " "It looks like the last session did not end " "properly or another instance of LMMS is " "already running. Do you want to recover the " "project of this session?" ), MainWindow::tr( "Recover" ), MainWindow::tr( "Recover the file. Please don't run " "multiple instances of LMMS when you do this." ), MainWindow::tr( "Discard" ), MainWindow::tr( "Launch a default session and delete " "the restored files. This is not reversible." ) ) ); mb.setIcon( QMessageBox::Warning ); mb.setWindowIcon( embed::getIconPixmap( "icon_small" ) ); mb.setWindowFlags( Qt::WindowCloseButtonHint ); QPushButton * recover; QPushButton * discard; QPushButton * exit; // setting all buttons to the same roles allows us // to have a custom layout discard = mb.addButton( MainWindow::tr( "Discard" ), QMessageBox::AcceptRole ); recover = mb.addButton( MainWindow::tr( "Recover" ), QMessageBox::AcceptRole ); // have a hidden exit button exit = mb.addButton( "", QMessageBox::RejectRole); exit->setVisible(false); // set icons recover->setIcon( embed::getIconPixmap( "recover" ) ); discard->setIcon( embed::getIconPixmap( "discard" ) ); mb.setDefaultButton( recover ); mb.setEscapeButton( exit ); mb.exec(); if( mb.clickedButton() == discard ) { gui->mainWindow()->sessionCleanup(); } else if( mb.clickedButton() == recover ) // Recover { fileToLoad = recoveryFile; gui->mainWindow()->setSession( MainWindow::SessionState::Recover ); } else // Exit { return 0; } } // first show the Main Window and then try to load given file // [Settel] workaround: showMaximized() doesn't work with // FVWM2 unless the window is already visible -> show() first gui->mainWindow()->show(); if( fullscreen ) { gui->mainWindow()->showMaximized(); } // Handle macOS-style FileOpen QEvents QString queuedFile = static_cast<MainApplication *>( app )->queuedFile(); if ( !queuedFile.isEmpty() ) { fileToLoad = queuedFile; } if( !fileToLoad.isEmpty() ) { if( fileToLoad == recoveryFile ) { Engine::getSong()->createNewProjectFromTemplate( fileToLoad ); } else { Engine::getSong()->loadProject( fileToLoad ); } } else if( !fileToImport.isEmpty() ) { ImportFilter::import( fileToImport, Engine::getSong() ); if( exitAfterImport ) { return EXIT_SUCCESS; } } // If enabled, open last project if there is one. Else, create // a new one. else if( ConfigManager::inst()-> value( "app", "openlastproject" ).toInt() && !ConfigManager::inst()-> recentlyOpenedProjects().isEmpty() && !recoveryFilePresent ) { QString f = ConfigManager::inst()-> recentlyOpenedProjects().first(); QFileInfo recentFile( f ); if ( recentFile.exists() && recentFile.suffix().toLower() != "mpt" ) { Engine::getSong()->loadProject( f ); } else { Engine::getSong()->createNewProject(); } } else { Engine::getSong()->createNewProject(); } // Finally we start the auto save timer and also trigger the // autosave one time as recover.mmp is a signal to possible other // instances of LMMS. if( autoSaveEnabled ) { gui->mainWindow()->autoSaveTimerReset(); } } const int ret = app->exec(); delete app; if( destroyEngine ) { Engine::destroy(); } // ProjectRenderer::updateConsoleProgress() doesn't return line after render if( coreOnly ) { printf( "\n" ); } #ifdef LMMS_BUILD_WIN32 // Cleanup console HWND hConsole = GetConsoleWindow(); if (hConsole) { SendMessage(hConsole, WM_CHAR, (WPARAM)VK_RETURN, (LPARAM)0); FreeConsole(); } #endif return ret; }