// Backend for OnMRUFile and OnMRUProject bool AudacityApp::MRUOpen(wxString fileName) { // Most of the checks below are copied from AudacityProject::ShowFileDialog // - some rationalisation might be possible. AudacityProject *proj = GetActiveProject(); if(!fileName.IsEmpty()) { // verify that the file exists if(wxFile::Exists(fileName)) { wxFileName newFileName(fileName); gPrefs->Write(wxT("/DefaultOpenPath"), wxPathOnly(fileName)); // Make sure it isn't already open size_t numProjects = gAudacityProjects.Count(); for (size_t i = 0; i < numProjects; i++) { if (newFileName.SameAs(gAudacityProjects[i]->GetFileName())) { wxMessageBox(wxString::Format(_("%s is already open in another window."), newFileName.GetName().c_str()), _("Error opening project"), wxOK | wxCENTRE); continue; } } // DMM: If the project is dirty, that means it's been touched at // all, and it's not safe to open a new project directly in its // place. Only if the project is brand-new clean and the user // hasn't done any action at all is it safe for Open to take place // inside the current project. // // If you try to Open a new project inside the current window when // there are no tracks, but there's an Undo history, etc, then // bad things can happen, including data files moving to the new // project directory, etc. if (!proj || proj->GetDirty() || !proj->GetIsEmpty()) { proj = CreateNewAudacityProject(gParentWindow); } // This project is clean; it's never been touched. Therefore // all relevant member variables are in their initial state, // and it's okay to open a new project inside this window. proj->OpenFile(fileName); // Add file to "recent files" list. proj->GetRecentFiles()->AddFileToHistory(fileName); gPrefs->SetPath(wxT("/RecentFiles")); proj->GetRecentFiles()->Save(*gPrefs); gPrefs->SetPath(wxT("..")); } else { // File doesn't exist - remove file from history wxMessageBox(wxString::Format(_("%s does not exist and could not be opened.\n\nIt has been removed from the history list."), fileName.c_str())); return(false); } } return(true); }
// in response of a print-document apple event void AudacityApp::MacPrintFile(const wxString &fileName) { AudacityProject *project = GetActiveProject(); if (project == NULL || !project->GetTracks()->IsEmpty()) { project = CreateNewAudacityProject(gParentWindow); } project->OpenFile(fileName); }
pascal OSErr AEOpenFiles(const AppleEvent * theAppleEvent, AppleEvent * theReply, long Refcon) { AEDescList docList; AEKeyword keywd; DescType returnedType; Size actualSize; long itemsInList; FSSpec theSpec; CInfoPBRec pb; Handle nameh; short namelen; OSErr err; short i; err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList); if (err != noErr) return err; err = AECountItems(&docList, &itemsInList); if (err != noErr) return err; for (i = 1; i <= itemsInList; i++) { AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType, (Ptr) & theSpec, sizeof(theSpec), &actualSize); if (noErr == FSpGetFullPath(&theSpec, &namelen, &nameh)) { HLock(nameh); char *str = new char[namelen + 1]; memcpy(str, (char *) *nameh, namelen); str[namelen] = 0; HUnlock(nameh); DisposeHandle(nameh); AudacityProject *project = GetActiveProject(); if (project == NULL || !project->GetTracks()->IsEmpty()) { project = CreateNewAudacityProject(gParentWindow); } project->OpenFile(str); delete[]str; } } return noErr; }
void AudacityProject::OnOpen(wxCommandEvent & event) { wxString path = gPrefs->Read("/DefaultOpenPath",::wxGetCwd()); wxString fileName = wxFileSelector(_("Select an audio file..."), path, // Path "", // Name "", // Extension _("All files (*.*)|*.*|" "Audacity projects (*.aup)|*.aup|" "WAV files (*.wav)|*.wav|" "AIFF files (*.aif)|*.aif|" "AU files (*.au)|*.au|" "IRCAM files (*.snd)|*.snd|" "MP3 files (*.mp3)|*.mp3"), 0, // Flags this); // Parent if (fileName != "") { gPrefs->Write("/DefaultOpenPath", wxPathOnly(fileName)); // Make sure it isn't already open int numProjects = gAudacityProjects.Count(); for (int i = 0; i < numProjects; i++) if (gAudacityProjects[i]->mFileName == fileName) { wxMessageBox ("That project is already open in another window."); return; } // Open in a new window if this one is in use if (mDirty || !mTracks->IsEmpty()) { AudacityProject *project = CreateNewAudacityProject(gParentWindow); project->OpenFile(fileName); } else OpenFile(fileName); } }
void LOFImportFileHandle::lofOpenFiles(wxString* ln) { wxStringTokenizer tok(*ln, wxT(" ")); wxStringTokenizer temptok1(*ln, wxT("\"")); wxStringTokenizer temptok2(*ln, wxT(" ")); int tokenplace = 0; wxString targetfile; wxString tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("window"), false)) { // set any duration/offset factors for last window, as all files were called doDuration(); doScrollOffset(); if (windowCalledOnce) { mProject = CreateNewAudacityProject(gParentWindow); } windowCalledOnce = true; while (tok.HasMoreTokens()) { tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("offset"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); if (Internat::CompatibleToDouble(tokenholder, &scrollOffset)) { callScrollOffset = true; } else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid window offset in LOF file."), /* i18n-hint: You do not need to translate "LOF" */ _("LOF Error"), wxOK | wxCENTRE, gParentWindow); } if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); } if (tokenholder.IsSameAs(wxT("duration"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); if (Internat::CompatibleToDouble(tokenholder, &durationFactor)) { callDurationFactor = true; } else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid duration in LOF file."), /* i18n-hint: You do not need to translate "LOF" */ _("LOF Error"), wxOK | wxCENTRE, gParentWindow); } } // End if statement if (tokenholder.IsSameAs(wxT("#"))) { // # indicates comments; ignore line tok = wxStringTokenizer(wxT(""), wxT(" ")); } } // End while loop } // End if statement else if (tokenholder.IsSameAs(wxT("file"), false)) { // To identify filename and open it tokenholder = temptok1.GetNextToken(); targetfile = temptok1.GetNextToken(); #ifdef USE_MIDI // If file is a midi if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false) || targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false)) { NoteTrack *nTrack = new NoteTrack(mProject->GetDirManager()); if (::ImportMIDI(targetfile, nTrack)) mProject->GetTracks()->Add(nTrack); else delete nTrack; } // If not a midi, open audio file else { #else // !USE_MIDI /* if we don't have midi support, go straight on to opening as an * audio file. TODO: Some sort of message here? */ { #endif // USE_MIDI mProject->OpenFile(targetfile); } // Set tok to right after filename temptok2.SetString(targetfile); tokenplace = temptok2.CountTokens(); for (int i = 0; i < tokenplace; i++) tokenholder = tok.GetNextToken(); if (tok.HasMoreTokens()) { tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("#"))) { // # indicates comments; ignore line tok = wxStringTokenizer(wxT(""), wxT(" ")); } if (tokenholder.IsSameAs(wxT("offset"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); double offset; if (Internat::CompatibleToDouble(tokenholder, &offset)) { Track *t; TrackListIterator iter(mProject->GetTracks()); t = iter.First(); for (int i = 1; i < CountNumTracks(mProject) - 1; i++) t = iter.Next(); #ifdef USE_MIDI if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false) || targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false)) { wxMessageBox(_("MIDI tracks cannot be offset individually, only audio files can be."), _("LOF Error"), wxOK | wxCENTRE, gParentWindow); } else #endif { if (CountNumTracks(mProject) == 1) t->SetOffset(offset); else { if (t->GetLinked()) t->SetOffset(offset); t = iter.Next(); t->SetOffset(offset); } } } else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid track offset in LOF file."), _("LOF Error"), wxOK | wxCENTRE, gParentWindow); } } // End if statement } // End if statement } // End if statement else if (tokenholder.IsSameAs(wxT("#")))
void AudacityProject::OpenFile(wxString fileName) { if (mDirty || !mTracks->IsEmpty()) { AudacityProject *project = CreateNewAudacityProject(gParentWindow); project->OpenFile(fileName); } // We want to open projects using wxTextFile, but if it's NOT a project // file (but actually a WAV file, for example), then wxTextFile will spin // for a long time searching for line breaks. So, we look for our // signature at the beginning of the file first: bool isProjectFile; wxString firstLine = "AudacityProject"; char temp[16]; if (!::wxFileExists(fileName)) { wxMessageBox(_("Could not open file: ") + mFileName); return; } // Make sure it isn't already open int numProjects = gAudacityProjects.Count(); for (int i = 0; i < numProjects; i++) if (gAudacityProjects[i]->mFileName == fileName) { wxMessageBox("That project is already open in another window."); return; } wxFile ff(fileName); if (!ff.IsOpened()) { wxMessageBox(_("Could not open file: ") + mFileName); return; } ff.Read(temp, 15); temp[15] = 0; isProjectFile = (firstLine == temp); ff.Close(); if (!isProjectFile) { // Try opening it as any other form of audio Import(fileName); return; } wxTextFile f; f.Open(fileName); if (!f.IsOpened()) { wxMessageBox(_("Could not open file: ") + mFileName); return; } mFileName = fileName; mName = wxFileNameFromPath(mFileName); SetTitle(mName); /// /// Parse project file /// wxString projName; wxString projPath; wxString version; long longVpos; f.GetFirstLine(); // This should say "AudacityProject" if (f.GetNextLine() != "Version") goto openFileError; version = f.GetNextLine(); if (version != AUDACITY_FILE_FORMAT_VERSION) { wxMessageBox(_("This project was saved by a different version of " "Audacity and is no longer supported.")); return; } if (f.GetNextLine() != "projName") goto openFileError; projName = f.GetNextLine(); projPath = wxPathOnly(mFileName); if (!mDirManager.SetProject(projPath, projName, false)) return; if (f.GetNextLine() != "sel0") goto openFileError; if (!(f.GetNextLine().ToDouble(&mViewInfo.sel0))) goto openFileError; if (f.GetNextLine() != "sel1") goto openFileError; if (!(f.GetNextLine().ToDouble(&mViewInfo.sel1))) goto openFileError; if (f.GetNextLine() != "vpos") goto openFileError; if (!(f.GetNextLine().ToLong(&longVpos))) goto openFileError; mViewInfo.vpos = longVpos; if (f.GetNextLine() != "h") goto openFileError; if (!(f.GetNextLine().ToDouble(&mViewInfo.h))) goto openFileError; if (f.GetNextLine() != "zoom") goto openFileError; if (!(f.GetNextLine().ToDouble(&mViewInfo.zoom))) goto openFileError; if (version != "0.9") { if (f.GetNextLine() != "rate") goto openFileError; if (!(f.GetNextLine().ToDouble(&mRate))) goto openFileError; mStatus->SetRate(mRate); } mTracks->Clear(); mTracks->Load(&f, &mDirManager); // By making a duplicate set of pointers to the existing blocks // on disk, we add one to their reference count, guaranteeing // that their reference counts will never reach zero and thus // the version saved on disk will be preserved until the // user selects Save(). if (1) { VTrack *t; TrackListIterator iter(mTracks); mLastSavedTracks = new TrackList(); t = iter.First(); while (t) { mLastSavedTracks->Add(t->Duplicate()); t = iter.Next(); } } f.Close(); InitialState(); FixScrollbars(); mTrackPanel->Refresh(false); return; openFileError: wxMessageBox(wxString:: Format(_("Error reading Audacity Project %s in line %d"), (const char *) mFileName, f.GetCurrentLine())); f.Close(); return; }
// The `main program' equivalent, creating the windows and returning the // main frame bool AudacityApp::OnInit() { // Unused strings that we want to be translated, even though // we're not using them yet... wxString future1 = _("Master Gain Control"); wxString future2 = _("Input Meter"); wxString future3 = _("Output Meter"); ::wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); InitPreferences(); #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__) this->AssociateFileTypes(); #endif // // Paths: set search path and temp dir path // wxString home = wxGetHomeDir(); mAppHomeDir = home; // On Unix systems, the default temp dir is in /tmp. // Search path (in this order): // * The AUDACITY_PATH environment variable // * The current directory // * The user's .audacity-files directory in their home directory // * The "share" and "share/doc" directories in their install path #ifdef __WXGTK__ defaultTempDir.Printf(wxT("/tmp/audacity1.2-%s"), wxGetUserId().c_str()); wxString pathVar = wxGetenv(wxT("AUDACITY_PATH")); if (pathVar != wxT("")) AddMultiPathsToPathList(pathVar, audacityPathList); AddUniquePathToPathList(FROMFILENAME(::wxGetCwd()), audacityPathList); AddUniquePathToPathList(wxString::Format(wxT("%s/.audacity-files"), home.c_str()), audacityPathList); #ifdef AUDACITY_NAME AddUniquePathToPathList(wxString::Format(wxT("%s/share/%s"), wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)), audacityPathList); AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/%s"), wxT(INSTALL_PREFIX), wxT(AUDACITY_NAME)), audacityPathList); #else AddUniquePathToPathList(wxString::Format(wxT("%s/share/audacity"), wxT(INSTALL_PREFIX)), audacityPathList); AddUniquePathToPathList(wxString::Format(wxT("%s/share/doc/audacity"), wxT(INSTALL_PREFIX)), audacityPathList); #endif AddUniquePathToPathList(wxString::Format(wxT("%s/share/locale"), wxT(INSTALL_PREFIX)), audacityPathList); #endif wxFileName tmpFile; tmpFile.AssignTempFileName(wxT("nn")); wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME); ::wxRemoveFile(FILENAME(tmpFile.GetFullPath())); // On Mac and Windows systems, use the directory which contains Audacity. #ifdef __WXMSW__ // On Windows, the path to the Audacity program is in argv[0] wxString progPath = wxPathOnly(argv[0]); AddUniquePathToPathList(progPath, audacityPathList); AddUniquePathToPathList(progPath+wxT("\\Languages"), audacityPathList); defaultTempDir.Printf(wxT("%s\\audacity_1_2_temp"), tmpDirLoc.c_str()); #endif #ifdef __MACOSX__ // On Mac OS X, the path to the Audacity program is in argv[0] wxString progPath = wxPathOnly(argv[0]); AddUniquePathToPathList(progPath, audacityPathList); // If Audacity is a "bundle" package, then the root directory is // the great-great-grandparent of the directory containing the executable. AddUniquePathToPathList(progPath+wxT("/../../../"), audacityPathList); AddUniquePathToPathList(progPath+wxT("/Languages"), audacityPathList); AddUniquePathToPathList(progPath+wxT("/../../../Languages"), audacityPathList); defaultTempDir.Printf(wxT("%s/audacity1.2-%s"), tmpDirLoc.c_str(), wxGetUserId().c_str()); #endif #ifdef __MACOS9__ // On Mac OS 9, the initial working directory is the one that // contains the program. wxString progPath = wxGetCwd(); AddUniquePathToPathList(progPath, audacityPathList); AddUniquePathToPathList(progPath+wxT(":Languages"), audacityPathList); defaultTempDir.Printf(wxT("%s/audacity_1_2_temp"), tmpDirLoc.c_str()); #endif // BG: Create a temporary window to set as the top window wxFrame *temporarywindow = new wxFrame(NULL, -1, wxT("temporarytopwindow")); SetTopWindow(temporarywindow); // Locale // wxWindows 2.3 has a much nicer wxLocale API. We can make this code much // better once we move to wx 2.3/2.4. wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT("")); // Pop up a dialog the first time the program is run if (lang == wxT("")) lang = ChooseLanguage(NULL); #ifdef NOT_RQD //TIDY-ME: (CleanSpeech) Language prompt?? // The prompt for language only happens ONCE on a system. // I don't think we should disable it JKC wxString lang = gPrefs->Read(wxT("/Locale/Language"), "en"); //lda // Pop up a dialog the first time the program is run //lda if (lang == "") //lda lang = ChooseLanguage(NULL); #endif gPrefs->Write(wxT("/Locale/Language"), lang); if (lang != wxT("en")) { wxLogNull nolog; mLocale = new wxLocale(wxT(""), lang, wxT(""), true, true); for(unsigned int i=0; i<audacityPathList.GetCount(); i++) mLocale->AddCatalogLookupPathPrefix(audacityPathList[i]); #ifdef AUDACITY_NAME mLocale->AddCatalog(wxT(AUDACITY_NAME)); #else mLocale->AddCatalog(wxT("audacity")); #endif } else mLocale = NULL; // Initialize internationalisation (number formats etc.) // // This must go _after_ creating the wxLocale instance because // creating the wxLocale instance sets the application-wide locale. Internat::Init(); // Init DirManager, which initializes the temp directory // If this fails, we must exit the program. if (!InitTempDir()) { FinishPreferences(); return false; } // More initialization InitCleanSpeech(); InitDitherers(); InitAudioIO(); LoadEffects(); #ifdef __WXMAC__ // On the Mac, users don't expect a program to quit when you close the last window. // Create an offscreen frame with a menu bar. The frame should never // be visible, but when all other windows are closed, this menu bar should // become visible. gParentFrame = new wxFrame(NULL, -1, wxT("invisible"), wxPoint(5000, 5000), wxSize(100, 100)); wxMenu *fileMenu = new wxMenu(); fileMenu->Append(wxID_NEW, wxT("&New\tCtrl+N")); fileMenu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O")); /* i18n-hint: Mac OS X shortcut should be Ctrl+, */ fileMenu->Append(wxID_PREFERENCES, _("&Preferences...\tCtrl+,")); wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, wxT("&File")); gParentFrame->SetMenuBar(menuBar); gParentFrame->Show(); SetTopWindow(gParentFrame); #endif SetExitOnFrameDelete(true); /////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// //Initiate pointers to toolbars here, and create //the toolbars that should be loaded at startup. gControlToolBarStub = LoadToolBar( wxT(""),true, gParentWindow,ControlToolBarID); gMixerToolBarStub = LoadToolBar( wxT("/GUI/EnableMixerToolBar"),true, gParentWindow,MixerToolBarID); gMeterToolBarStub = LoadToolBar( wxT("/GUI/EnableMeterToolBar"),true, gParentWindow,MeterToolBarID); gEditToolBarStub = LoadToolBar( wxT("/GUI/EnableEditToolBar"),true, gParentWindow,EditToolBarID); gTranscriptionToolBarStub = LoadToolBar( wxT("/GUI/EnableTranscriptionToolBar"),false, gParentWindow,TranscriptionToolBarID); /// ToolBar Initiation Complete. //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// AudacityProject *project = CreateNewAudacityProject(gParentWindow); SetTopWindow(project); delete temporarywindow; // Can't handle command-line args on Mac OS X yet... // Cygwin command-line parser below... #if !defined(__MACOSX__) && !defined(__CYGWIN__) // Parse command-line arguments if (argc > 1) { for (int option = 1; option < argc; option++) { if (!argv[option]) continue; bool handled = false; if (!wxString(wxT("-help")).CmpNoCase(argv[option])) { wxPrintf(/* i18n-hint: '-help', '-test' and '-blocksize' need to stay in English. */ _("Command-line options supported:\n -help (this message)\n -test (run self diagnostics)\n -blocksize ### (set max disk block size in bytes)\n\nIn addition, specify the name of an audio file or Audacity project\nto open it.\n\n")); exit(0); } if (option < argc - 1 && argv[option + 1] && !wxString(wxT("-blocksize")).CmpNoCase(argv[option])) { long theBlockSize; if (wxString(argv[option + 1]).ToLong(&theBlockSize)) { if (theBlockSize >= 256 && theBlockSize < 100000000) { wxFprintf(stderr, _("Using block size of %ld\n"), theBlockSize); Sequence::SetMaxDiskBlockSize(theBlockSize); } } option++; handled = true; } if (!handled && !wxString(wxT("-test")).CmpNoCase(argv[option])) { RunBenchmark(NULL); exit(0); } if (argv[option][0] == wxT('-') && !handled) { wxPrintf(_("Unknown command line option: %s\n"), argv[option]); exit(0); } if (!handled) project->OpenFile(argv[option]); } // for option... } // if (argc>1) #endif // not Mac OS X // Cygwin command line parser (by Dave Fancella) #if defined(__CYGWIN__) if (argc > 1) { int optionstart = 1; bool startAtOffset = false; // Scan command line arguments looking for trouble for (int option = 1; option < argc; option++) { if (!argv[option]) continue; // Check to see if argv[0] is copied across other arguments. // This is the reason Cygwin gets its own command line parser. if (wxString(argv[option]).Lower().Contains(wxString(wxT("audacity.exe")))) { startAtOffset = true; optionstart = option + 1; } } for (int option = optionstart; option < argc; option++) { if (!argv[option]) continue; bool handled = false; bool openThisFile = false; wxString fileToOpen; if (!wxString(wxT("-help")).CmpNoCase(argv[option])) { wxPrintf(/* i18n-hint: '-help', '-test' and '-blocksize' need to stay in English. */ _("Command-line options supported:\n" " -help (this message)\n" " -test (run self diagnostics)\n" " -blocksize ### (set max disk block size in bytes)\n" "\n" "In addition, specify the name of an audio file or " "Audacity project\n" "to open it.\n" "\n")); exit(0); } if (option < argc - 1 && argv[option + 1] && !wxString(wxT("-blocksize")).CmpNoCase(argv[option])) { long theBlockSize; if (wxString(argv[option + 1]).ToLong(&theBlockSize)) { if (theBlockSize >= 256 && theBlockSize < 100000000) { wxFprintf(stderr, _("Using block size of %ld\n"), theBlockSize); Sequence::SetMaxDiskBlockSize(theBlockSize); } } option++; handled = true; } if (!handled && !wxString(wxT("-test")).CmpNoCase(argv[option])) { RunBenchmark(NULL); exit(0); } if (argv[option][0] == wxT('-') && !handled) { wxPrintf(_("Unknown command line option: %s\n"), argv[option]); exit(0); } if(handled) fileToOpen.Clear(); if (!handled) fileToOpen = fileToOpen + wxT(" ") + argv[option]; if(wxString(argv[option]).Lower().Contains(wxT(".aup"))) openThisFile = true; if(openThisFile) { openThisFile = false; project->OpenFile(fileToOpen); } } // for option... } // if (argc>1) #endif // Cygwin command-line parser gInited = true; return TRUE; }
/** @brief Processes a single line from a LOF text file, doing whatever is * indicated on the line. * * This function should just return for lines it cannot deal with, and the * caller will continue to the next line of the input file */ void LOFImportFileHandle::lofOpenFiles(wxString* ln) { wxStringTokenizer tok(*ln, wxT(" ")); wxStringTokenizer temptok1(*ln, wxT("\"")); wxStringTokenizer temptok2(*ln, wxT(" ")); int tokenplace = 0; wxString targetfile; wxString tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("window"), false)) { // set any duration/offset factors for last window, as all files were called doDuration(); doScrollOffset(); if (windowCalledOnce) { mProject = CreateNewAudacityProject(); } windowCalledOnce = true; while (tok.HasMoreTokens()) { tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("offset"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); if (Internat::CompatibleToDouble(tokenholder, &scrollOffset)) { callScrollOffset = true; } else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid window offset in LOF file."), /* i18n-hint: You do not need to translate "LOF" */ _("LOF Error"), wxOK | wxCENTRE); } if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); } if (tokenholder.IsSameAs(wxT("duration"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); if (Internat::CompatibleToDouble(tokenholder, &durationFactor)) { callDurationFactor = true; } else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid duration in LOF file."), /* i18n-hint: You do not need to translate "LOF" */ _("LOF Error"), wxOK | wxCENTRE); } } // End if statement if (tokenholder.IsSameAs(wxT("#"))) { // # indicates comments; ignore line tok = wxStringTokenizer(wxT(""), wxT(" ")); } } // End while loop } // End if statement handling "window" lines else if (tokenholder.IsSameAs(wxT("file"), false)) { // To identify filename and open it tokenholder = temptok1.GetNextToken(); targetfile = temptok1.GetNextToken(); // If path is relative, make absolute path from LOF path if(!wxIsAbsolutePath(targetfile)) { wxFileName fName(targetfile); fName.Normalize(wxPATH_NORM_ALL, mLOFFileName->GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)); if(fName.FileExists()) { targetfile = fName.GetFullPath(); } } #ifdef USE_MIDI // If file is a midi if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false) || targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false)) { NoteTrack *nTrack = new NoteTrack(mProject->GetDirManager()); if (::ImportMIDI(targetfile, nTrack)) mProject->GetTracks()->Add(nTrack); else delete nTrack; } // If not a midi, open audio file else { #else // !USE_MIDI /* if we don't have midi support, go straight on to opening as an * audio file. TODO: Some sort of message here? */ { #endif // USE_MIDI mProject->OpenFile(targetfile); } // Set tok to right after filename temptok2.SetString(targetfile); tokenplace = temptok2.CountTokens(); for (int i = 0; i < tokenplace; i++) tokenholder = tok.GetNextToken(); if (tok.HasMoreTokens()) { tokenholder = tok.GetNextToken(); if (tokenholder.IsSameAs(wxT("#"))) { // # indicates comments; ignore line tok = wxStringTokenizer(wxT(""), wxT(" ")); } if (tokenholder.IsSameAs(wxT("offset"), false)) { if (tok.HasMoreTokens()) tokenholder = tok.GetNextToken(); double offset; // handle an "offset" specifier if (Internat::CompatibleToDouble(tokenholder, &offset)) { Track *t; TrackListIterator iter(mProject->GetTracks()); t = iter.First(); for (int i = 1; i < CountNumTracks(mProject) - 1; i++) t = iter.Next(); // t is now the last track in the project, unless the import of // all tracks failed, in which case it will be null. In that // case we return because we cannot offset a non-existent track. if (t == NULL) return; #ifdef USE_MIDI if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false) || targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false)) { wxMessageBox(_("MIDI tracks cannot be offset individually, only audio files can be."), _("LOF Error"), wxOK | wxCENTRE); } else #endif { if (CountNumTracks(mProject) == 1) t->SetOffset(offset); else { if (t->GetLinked()) t->SetOffset(offset); t = iter.Next(); t->SetOffset(offset); } } } // end of converting "offset" argument else { /* i18n-hint: You do not need to translate "LOF" */ wxMessageBox(_("Invalid track offset in LOF file."), _("LOF Error"), wxOK | wxCENTRE); } } // End if statement for "offset" parameters } // End if statement (more tokens after file name) } // End if statement "file" lines else if (tokenholder.IsSameAs(wxT("#")))
// The `main program' equivalent, creating the windows and returning the // main frame bool AudacityApp::OnInit() { // mChecker = new wxSingleInstanceChecker(GetAppName()); ::wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); #ifdef __WXMSW__ //BG: On Windows, associate the aup file type with Audacity { wxRegKey associateFileTypes; associateFileTypes.SetName("HKCR\\.AUP"); associateFileTypes.Create(true); associateFileTypes = "Audacity.Project"; associateFileTypes.SetName("HKCR\\Audacity.Project"); associateFileTypes.Create(true); associateFileTypes = "Audacity Project File"; associateFileTypes.SetName("HKCR\\Audacity.Project\\shell"); associateFileTypes.Create(true); associateFileTypes = ""; associateFileTypes.SetName("HKCR\\Audacity.Project\\shell\\open"); associateFileTypes.Create(true); associateFileTypes.SetName("HKCR\\Audacity.Project\\shell\\open\\command"); associateFileTypes.Create(true); associateFileTypes = (wxString)argv[0] + (wxString)" %1"; } #endif InitPreferences(); InitAudioIO(); // Locale // wxWindows 2.3 has a much nicer wxLocale API. We can make this code much // better once we move to wx 2.3/2.4. wxString lang = gPrefs->Read("/Locale/Language", "en"); if (lang != "en") { wxLogNull nolog; mLocale = new wxLocale("", lang, "", true, true); mLocale->AddCatalog("audacity"); } else mLocale = NULL; LoadEffects(wxPathOnly(argv[0])); #ifdef __WXMAC__ // Install AppleEvent handlers (allows us to open documents // that are dragged to our application's icon) AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(AEOpenFiles), 0, 0); AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(AEQuit), 0, 0); // On the Mac, users don't expect a program to quit when you close the last window. // Create an offscreen frame with a menu bar. The frame should never // be visible, but when all other windows are closed, this menu bar should // become visible. gParentFrame = new wxFrame(NULL, -1, "invisible", wxPoint(5000, 5000), wxSize(100, 100)); wxMenu *fileMenu = new wxMenu(); fileMenu->Append(NewID, "&New\tCtrl+N"); fileMenu->Append(OpenID, "&Open...\tCtrl+O"); fileMenu->AppendSeparator(); fileMenu->Append(PreferencesID, "&Preferences...\tCtrl+P"); fileMenu->AppendSeparator(); fileMenu->Append(ExitID, "Quit\tCtrl+Q"); wxMenu *helpMenu = new wxMenu(); helpMenu->Append(AboutID, "About Audacity..."); wxApp::s_macAboutMenuItemId = AboutID; wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, "&File"); menuBar->Append(helpMenu, "&Help"); gParentFrame->SetMenuBar(menuBar); gParentFrame->Show(); SetTopWindow(gParentFrame); #endif SetExitOnFrameDelete(true); //Initiate pointers to toolbars here, and create //the toolbars that should be loaded at startup. //Initiate globally-held toolbar stubs here. gControlToolBarStub = new ToolBarStub(gParentWindow, ControlToolBarID); // Changing the following to NULL will make the application // load without the toolbar in memory at all. bool editToolBar; gPrefs->Read("/GUI/EnableEditToolBar", &editToolBar, true); if(editToolBar) gEditToolBarStub = new ToolBarStub(gParentWindow, EditToolBarID); else gEditToolBarStub = NULL; InitFreqWindow(gParentWindow); AudacityProject *project = CreateNewAudacityProject(gParentWindow); SetTopWindow(project); // Can't handle command-line args on Mac OS X yet... #ifndef __MACOSX__ // Parse command-line arguments if (argc > 1) { for (int option = 1; option < argc; option++) { if (!argv[option]) continue; bool handled = false; if (!wxString("-help").CmpNoCase(argv[option])) { printf(_("Command-line options supported:\n" " -help (this message)\n" " -test (run self diagnostics)\n" " -blocksize ### (set max disk block size in bytes)\n" "\n" "In addition, specify the name of an audio file or " "Audacity project\n" "to open it.\n" "\n")); exit(0); } if (option < argc - 1 && argv[option + 1] && !wxString("-blocksize").CmpNoCase(argv[option])) { long theBlockSize; if (wxString(argv[option + 1]).ToLong(&theBlockSize)) { if (theBlockSize >= 256 && theBlockSize < 100000000) { fprintf(stderr, _("Using block size of %ld\n"), theBlockSize); Sequence::SetMaxDiskBlockSize(theBlockSize); } } option++; handled = true; } if (!handled && !wxString("-test").CmpNoCase(argv[option])) { RunBenchmark(NULL); exit(0); } if (argv[option][0] == '-' && !handled) { printf(_("Unknown command line option: %s\n"), argv[option]); exit(0); } if (!handled) project->OpenFile(argv[option]); } // for option... } // if (argc>1) #endif // not Mac OS X return TRUE; }