1 /* 2 * Copyright (C) 2002 - David W. Durham 3 * 4 * This file is part of ReZound, an audio editing application. 5 * 6 * ReZound is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published 8 * by the Free Software Foundation; either version 2 of the License, 9 * or (at your option) any later version. 10 * 11 * ReZound is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 */ 20 21 #ifndef __ASoundFileManager_H__ 22 #define __ASoundFileManager_H__ 23 24 #include "../../config/common.h" 25 26 class ASoundFileManager; 27 28 #include <string> 29 #include <vector> 30 #include <map> 31 32 class CLoadedSound; 33 class CNestedDataFile; 34 class ASoundPlayer; 35 class ASoundTranslator; 36 37 #include "CSound_defs.h" 38 39 struct EStopClosing { }; 40 41 42 43 class ASoundFileManager 44 { 45 public: 46 47 ASoundFileManager(ASoundPlayer *soundPlayer,CNestedDataFile *loadedRegistryFile); 48 // should a destructor be responsible for closing all files??? ~ASoundFileManager()49 virtual ~ASoundFileManager() { } 50 51 void createNew(); 52 CLoadedSound *createNew(const string filename,unsigned channelCount,unsigned sampleRate,sample_pos_t length=1,bool rawFormat=false); 53 // returns false if a prompt for filename was cancelled, or if there was an error loading 54 bool open(const string filename="",bool openAsRaw=false); 55 bool open(const vector<string> &filenames,bool openAsRaw=false); 56 57 //#warning "do this.. I can call soundFileManager->getActive() from actions when necessary" 58 // ??? should rename these to, saveActive... or pass them a CSound * (I prefer that), perhaps optionally pass saveAs a filename which can be "" 59 // returns false if something was cancelled 60 bool save(); 61 // returns false if something was cancelled 62 bool saveAs(const string filename="",bool saveAsRaw=false); 63 // returns false if something was cancelled 64 bool savePartial(const CSound *sound,const string filename,const sample_pos_t saveStart,const sample_pos_t saveLength,bool useLastUserPrefs); 65 66 enum CloseTypes { ctSaveYesNoStop,ctSaveYesNoCancel,ctSaveNone }; 67 // returns false if something was cancelled 68 bool close(CloseTypes closeType,CLoadedSound *closeWhichSound=NULL); // if nothing is passed for closeWhichSound, then the active sound is closed 69 70 void revert(); 71 void recordToNew(); 72 73 const string getUntitledFilename(const string directory,const string extension); 74 75 const size_t getReopenHistorySize() const; 76 const string getReopenHistoryItem(const size_t index) const; 77 78 // return the CLoadedSound object associated with the sound window which is currently 'focused' 79 // return NULL if there is no focused window 80 virtual CLoadedSound *getActive()=0; 81 82 // should be implemented to return the number of currently opened sound files 83 virtual const size_t getOpenedCount() const=0; 84 85 // given an index from 0 to getOpenedCount()-1 should be implemented to 86 // run the CLoadedSound pointer 87 virtual CLoadedSound *getSound(size_t index)=0; 88 89 // should be implemented to change the active sound to the one specified at the given index 90 virtual void setActiveSound(size_t index)=0; 91 92 // is called after an action is performed to update the screen or when the title 93 // bar and other status information of a loaded sound window needs to be modified 94 virtual void updateAfterEdit(CLoadedSound *sound=NULL,bool undoing=false)=0; // if NULL, then use the active one 95 96 // these two methods should be implemented to get and set the positional information (i.e. zoom 97 // factors and scroll positions) of the window with the given sound (or the active one if sound 98 // is not passed in). 99 virtual const map<string,string> getPositionalInfo(CLoadedSound *sound=NULL)=0; // would be 'const' but have to call getActive() 100 virtual void setPositionalInfo(const map<string,string> positionalInfo,CLoadedSound *sound=NULL)=0; 101 102 // returns a list of error messages 103 const vector<string> loadFilesInRegistry(); 104 105 protected: 106 107 // should create a new sound window with the given CLoadedSound object 108 virtual void createWindow(CLoadedSound *loaded)=0; 109 110 // should destroy the window which was created with the given CLoadedSound object 111 // Note: it is possible that this called with a CLoadedSound object which doesn't have a window. If so, just ignore 112 virtual void destroyWindow(CLoadedSound *loaded)=0; 113 114 115 // invoked whenever a file is successfully opened, new file created, file recorded, saveAs-ed, etc 116 void updateReopenHistory(const string filename); 117 118 private: 119 120 ASoundPlayer *soundPlayer; 121 122 CNestedDataFile *loadedRegistryFile; 123 124 // returns false if cancelled 125 bool prvOpen(const string filename,bool readOnly,bool registerFilename,bool asRaw=false,const ASoundTranslator *translatorToUse=NULL); 126 127 void registerFilename(const string filename); 128 void unregisterFilename(const string filename); 129 bool isFilenameRegistered(const string filename); 130 CLoadedSound *prvCreateNew(sample_pos_t length,bool askForLength,unsigned sampleRate,bool askForSampleRate); 131 132 }; 133 134 #endif 135