/[svn]/linuxsampler/trunk/src/db/InstrumentsDb.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/db/InstrumentsDb.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1161 by iliev, Mon Apr 16 15:51:18 2007 UTC revision 1350 by iliev, Sun Sep 16 23:06:10 2007 UTC
# Line 26  Line 26 
26  #define __LS_INSTRUMENTSDB_H__  #define __LS_INSTRUMENTSDB_H__
27    
28  #include <sqlite3.h>  #include <sqlite3.h>
 #include <vector>  
 #include <sys/stat.h>  
29  #include <gig.h>  #include <gig.h>
30  #include "../common/Mutex.h"  #include "../common/Mutex.h"
31    #include "../common/WorkerThread.h"
32  #include "../EventListeners.h"  #include "../EventListeners.h"
33    #include "InstrumentsDbUtilities.h"
34    
35  namespace LinuxSampler {  namespace LinuxSampler {
   
     class DbInstrument {  
         public:  
             String InstrFile;  
             int    InstrNr;  
             String FormatFamily;  
             String FormatVersion;  
             long long int Size;  
             String Created;  
             String Modified;  
             String Description;  
             bool   IsDrum;  
             String Product;  
             String Artists;  
             String Keywords;  
   
             DbInstrument() { }  
             DbInstrument(const DbInstrument& Instr) { Copy(Instr); }  
             void operator=(const DbInstrument& Instr) { Copy(Instr); }  
             void Copy(const DbInstrument&);  
     };  
   
     class DbDirectory {  
         public:  
             String Created;  
             String Modified;  
             String Description;  
   
             DbDirectory() { }  
             DbDirectory(const DbDirectory& Dir) { Copy(Dir); }  
             void operator=(const DbDirectory& Dir) { Copy(Dir); }  
             void Copy(const DbDirectory&);  
     };  
       
     typedef std::auto_ptr<std::vector<int> > IntListPtr;  
     typedef std::auto_ptr<std::vector<String> > StringListPtr;  
   
36      /**      /**
37       * @brief Provides access to the instruments database.       * @brief Provides access to the instruments database.
38       */       */
39      class InstrumentsDb {      class InstrumentsDb {
40            friend class DirectoryScanner;
41            friend class DirectoryFinder;
42            friend class InstrumentFinder;
43            friend class DirectoryCounter;
44            friend class InstrumentCounter;
45            friend class DirectoryCopier;
46            friend class AddInstrumentsJob;
47            friend class ScanProgress;
48            
49          public:          public:
   
50              /**              /**
51               * This class is used as a listener, which is notified when               * This class is used as a listener, which is notified when
52               * changes to the instruments database are made.               * changes to the instruments database are made.
# Line 85  namespace LinuxSampler { Line 56  namespace LinuxSampler {
56                      /**                      /**
57                       * Invoked when the number of instrument directories                       * Invoked when the number of instrument directories
58                       * in a specific directory has changed.                       * in a specific directory has changed.
59                       * @param Dir The absolute pathname of the directory in                       * @param Dir The absolute pathname of the directory
60                       * which the number of directories is changed.                       * in which the number of directories is changed.
61                         * All slashes in the directory names are replaced with '\0'.
62                       */                       */
63                      virtual void DirectoryCountChanged(String Dir) = 0;                      virtual void DirectoryCountChanged(String Dir) = 0;
64    
# Line 95  namespace LinuxSampler { Line 67  namespace LinuxSampler {
67                       * are changed.                       * are changed.
68                       * @param Dir The absolute pathname of the directory                       * @param Dir The absolute pathname of the directory
69                       * whose settings are changed.                       * whose settings are changed.
70                         * All slashes in the directory names are replaced with '\0'.
71                       */                       */
72                      virtual void DirectoryInfoChanged(String Dir) = 0;                      virtual void DirectoryInfoChanged(String Dir) = 0;
73    
74                      /**                      /**
75                       * Invoked when an instrument directory is renamed.                       * Invoked when an instrument directory is renamed.
76                       * @param Dir The old absolute pathname of the directory.                       * @param Dir The old absolute pathname of the directory.
77                         * All slashes in the directory names are replaced with '\0'.
78                       * @param NewName The new name of the directory.                       * @param NewName The new name of the directory.
79                         * All slashes in the name are replaced with '\0'.
80                       */                       */
81                      virtual void DirectoryNameChanged(String Dir, String NewName) = 0;                      virtual void DirectoryNameChanged(String Dir, String NewName) = 0;
82    
83                      /**                      /**
84                       * Invoked when the number of instruments                       * Invoked when the number of instruments
85                       * in a specific directory has changed.                       * in a specific directory has changed.
86                       * @param Dir The absolute pathname of the directory in                       * @param Dir The absolute pathname of the directory
87                       * which the number of instruments is changed.                       * in which the number of instruments is changed.
88                         * All slashes in the directory names are replaced with '\0'.
89                       */                       */
90                      virtual void InstrumentCountChanged(String Dir) = 0;                      virtual void InstrumentCountChanged(String Dir) = 0;
91    
92                      /**                      /**
93                       * Invoked when the settings of an instrument are changed.                       * Invoked when the settings of an instrument are changed.
94                       * @param Instr The absolute pathname of the instrument                       * @param Instr The absolute pathname of the
95                       * whose settings are changed.                       * instrument whose settings are changed.
96                         * All slashes in the directory/instrument names are replaced with '\0'.
97                       */                       */
98                      virtual void InstrumentInfoChanged(String Instr) = 0;                      virtual void InstrumentInfoChanged(String Instr) = 0;
99    
100                      /**                      /**
101                       * Invoked when an instrument is renamed.                       * Invoked when an instrument is renamed.
102                       * @param Instr The old absolute pathname of the instrument.                       * @param Instr The old absolute pathname of the instrument.
103                         * All slashes in the directory/instrument names are replaced with '\0'.
104                       * @param NewName The new name of the directory.                       * @param NewName The new name of the directory.
105                         * All slashes in the name are replaced with '\0'.
106                       */                       */
107                      virtual void InstrumentNameChanged(String Instr, String NewName) = 0;                      virtual void InstrumentNameChanged(String Instr, String NewName) = 0;
108    
109                        /**
110                         * Invoked when the status of particular job is changed.
111                         * @param JobId The ID of the job.
112                         */
113                        virtual void JobStatusChanged(int JobId) = 0;
114              };              };
115    
116              /**              /**
# Line 140  namespace LinuxSampler { Line 125  namespace LinuxSampler {
125              void RemoveInstrumentsDbListener(InstrumentsDb::Listener* l);              void RemoveInstrumentsDbListener(InstrumentsDb::Listener* l);
126    
127              /**              /**
128                 * Creates an instruments database file.
129                 * @param File the pathname of the file to create.
130                 * @throws Exception If the creation of the database file failed.
131                 */
132                static void CreateInstrumentsDb(String File);
133    
134                /**
135               * This method is used to access the instruments database.               * This method is used to access the instruments database.
136               */               */
137              static InstrumentsDb* GetInstrumentsDb();              static InstrumentsDb* GetInstrumentsDb();
# Line 156  namespace LinuxSampler { Line 148  namespace LinuxSampler {
148              /**              /**
149               * Gets the number of directories in the specified directory.               * Gets the number of directories in the specified directory.
150               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
151                 * All slashes in the directory names should be replaced with '\0'.
152                 * @param Recursive If true, the number of all directories
153                 * in the specified subtree will be returned.
154               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
155               * the specified path name is invalid.               * the specified path name is invalid.
156               * @returns The number of directories in the specified directory               * @returns The number of directories in the specified directory.
              * or -1 if the directory doesn't exist.  
157               */               */
158              int GetDirectoryCount(String Dir);              int GetDirectoryCount(String Dir, bool Recursive);
159    
160              /**              /**
161               * Gets the list of directories in the specified directory.               * Gets the list of directories in the specified directory.
162               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
163                 * All slashes in the directory names should be replaced with '\0'.
164                 * @param Recursive If true, all directories
165                 * in the specified subtree will be returned.
166               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
167               * the specified path name is invalid.               * the specified path name is invalid.
168                 * @returns The list of directories, where the directories are
169                 * represented in abstract path - all slashes in the directory
170                 * names are replaced with '\0'.
171               */               */
172              StringListPtr GetDirectories(String Dir);              StringListPtr GetDirectories(String Dir, bool Recursive);
173    
174              /**              /**
175               * Adds the specified directory to the database.               * Adds the specified directory to the database.
176               * @param Dir The absolute path name of the directory to add.               * @param Dir The absolute path name of the directory to add.
177                 * All slashes in the directory names should be replaced with '\0'.
178               * @throws Exception - if database error occurs, or the               * @throws Exception - if database error occurs, or the
179               * specified path is invalid.               * specified path is invalid.
180               */               */
# Line 182  namespace LinuxSampler { Line 183  namespace LinuxSampler {
183              /**              /**
184               * Removes the specified directory from the database.               * Removes the specified directory from the database.
185               * @param Dir The absolute path name of the directory to remove.               * @param Dir The absolute path name of the directory to remove.
186                 * All slashes in the directory names should be replaced with '\0'.
187               * @throws Exception - If the specified path is invalid, or               * @throws Exception - If the specified path is invalid, or
188               * Force is false and the specified directory is               * Force is false and the specified directory is
189               * not empty, or if database error occurs.               * not empty, or if database error occurs.
# Line 190  namespace LinuxSampler { Line 192  namespace LinuxSampler {
192    
193              /**              /**
194               * Determines whether the specified directory exists in the database.               * Determines whether the specified directory exists in the database.
195                 * @param Dir The absolute path name of the directory.
196                 * All slashes in the directory names should be replaced with '\0'.
197               * @throws Exception - If database error occurs.               * @throws Exception - If database error occurs.
198               */               */
199              bool DirectoryExist(String Dir);              bool DirectoryExist(String Dir);
# Line 197  namespace LinuxSampler { Line 201  namespace LinuxSampler {
201              /**              /**
202               * Gets information about the specified directory.               * Gets information about the specified directory.
203               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
204                 * All slashes in the directory names should be replaced with '\0'.
205               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
206               * the specified directory is not found.               * the specified directory is not found.
207               */               */
# Line 205  namespace LinuxSampler { Line 210  namespace LinuxSampler {
210              /**              /**
211               * Renames the specified directory.               * Renames the specified directory.
212               * @param Dir The absolute path name of the directory to rename.               * @param Dir The absolute path name of the directory to rename.
213                 * All slashes in the directory names should be replaced with '\0'.
214               * @param Name The new name for the directory.               * @param Name The new name for the directory.
215               * @throws Exception - In case the given directory does not exists,               * @throws Exception - In case the given directory does not exists,
216               * or the specified name is not a valid name,               * or the specified name is not a valid name,
# Line 216  namespace LinuxSampler { Line 222  namespace LinuxSampler {
222              /**              /**
223               * Moves the specified directory into the specified location.               * Moves the specified directory into the specified location.
224               * @param Dir The absolute path name of the directory to move.               * @param Dir The absolute path name of the directory to move.
225                 * All slashes in the directory names should be replaced with '\0'.
226               * @param Dst The location where the directory will be moved to.               * @param Dst The location where the directory will be moved to.
227                 * All slashes in the directory names should be replaced with '\0'.
228               * @throws Exception - In case a given directory does not exists,               * @throws Exception - In case a given directory does not exists,
229               * or if a directory with name equal to the directory name already               * or if a directory with name equal to the directory name already
230               * exists in the specified destination directory, or if database error               * exists in the specified destination directory, or if database error
# Line 226  namespace LinuxSampler { Line 234  namespace LinuxSampler {
234              void MoveDirectory(String Dir, String Dst);              void MoveDirectory(String Dir, String Dst);
235    
236              /**              /**
237                 * Copies the specified directory into the specified location.
238                 * @param Dir The absolute path name of the directory to copy.
239                 * All slashes in the directory names should be replaced with '\0'.
240                 * @param Dst The location where the directory will be copied to.
241                 * All slashes in the directory names should be replaced with '\0'.
242                 * @throws Exception - In case a given directory does not exists,
243                 * or if a directory with name equal to the directory name already
244                 * exists in the specified destination directory, or if database error
245                 * occurs. Error is also thrown when trying to copy a directory to a
246                 * subdirectory of itself.
247                 */
248                void CopyDirectory(String Dir, String Dst);
249    
250                /**
251               * Changes the description of the specified directory.               * Changes the description of the specified directory.
252                 * @param Dir The absolute path name of the directory.
253                 * All slashes in the directory names should be replaced with '\0'.
254               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
255               * the specified directory is not found.               * the specified directory is not found.
256               */               */
257              void SetDirectoryDescription(String Dir, String Desc);              void SetDirectoryDescription(String Dir, String Desc);
258                
259                /**
260                 * Finds all directories that match the search query.
261                 * @param Dir The absolute path name of the database
262                 * directory to search in.
263                 * All slashes in the directory names should be replaced with '\0'.
264                 * @throws Exception - if database error occurs, or
265                 * if the specified path name is invalid.
266                 * @returns The absolute path names of all directories
267                 * that match the search query.
268                 */
269                StringListPtr FindDirectories(String Dir, SearchQuery* pQuery, bool Recursive);
270    
271              /**              /**
272               * Adds the instruments in the specified file or               * Adds the instruments in the specified file or
# Line 238  namespace LinuxSampler { Line 274  namespace LinuxSampler {
274               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
275               * instruments database in which only the new instruments               * instruments database in which only the new instruments
276               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
277                 * All slashes in the directory names should be replaced with '\0'.
278               * @param FilePath The absolute path name of a file or               * @param FilePath The absolute path name of a file or
279               * directory in the file system. In case a directory is               * directory in the file system. In case a directory is
280               * supplied, all supported instruments in the specified directory               * supplied, all supported instruments in the specified directory
# Line 248  namespace LinuxSampler { Line 285  namespace LinuxSampler {
285               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
286               * the supplied instrument file will be added. Error is thrown if               * the supplied instrument file will be added. Error is thrown if
287               * a directory is supplied and Index is not equal to -1.               * a directory is supplied and Index is not equal to -1.
288                 * @param bBackground Determines whether
289                 * the task should be done in the background.
290                 * @returns If bBackground is true, the ID of the scan job;
291                 * -1 otherwise.
292               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
293               */               */
294              void AddInstruments(String DbDir, String FilePath, int Index = -1);              int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground);
295    
296              /**              /**
297               * Adds all supported instruments in the specified directory               * Adds the instruments in the specified file
298               * to the specified instruments database directory. The               * to the specified instruments database directory.
              * instruments in the subdirectories will not be processed  
299               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
300               * instruments database in which only the new instruments               * instruments database in which only the new instruments
301               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
302               * @param FsDir The absolute path name of a directory in the file               * All slashes in the directory names should be replaced with '\0'.
303               * system.               * @param FilePath The absolute path name of the instrument file.
304                 * @param Index The index of the instrument (in the given
305                 * instrument file) to add. If -1 is specified, all instruments in
306                 * the supplied instrument file will be added.
307                 * @param pProgress The progress used to monitor the scan process.
308               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
309               */               */
310              void AddInstrumentsNonrecursive(String DbDir, String FsDir);              void AddInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL);
311    
312              /**              /**
313               * Adds all supported instruments in the specified file system               * Adds all supported instruments in the specified file system
314               * direcotry to the specified instruments database directory,               * direcotry to the specified instruments database directory.
315               * including the instruments in the subdirectories of the               * @param Mode Determines the scanning mode. If RECURSIVE is
316               * supplied directory.               * specified, all supported instruments in the specified file system
317                 * direcotry will be added to the specified instruments database
318                 * directory, including the instruments in subdirectories
319                 * of the supplied directory. If NON_RECURSIVE is specified,
320                 * the instruments in the subdirectories will not be processed.
321                 * If FLAT is specified, all supported instruments in the specified
322                 * file system direcotry will be added, including the instruments in
323                 * subdirectories of the supplied directory, but the respective
324                 * subdirectory structure will not be recreated in the instruments
325                 * database and all instruments will be added directly in the
326                 * specified database directory.
327               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
328               * instruments database in which only the new instruments               * instruments database in which only the new instruments
329               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
330                 * All slashes in the directory names should be replaced with '\0'.
331               * @param FsDir The absolute path name of an existing               * @param FsDir The absolute path name of an existing
332               * directory in the file system.               * directory in the file system.
333               * @param Flat If true, the respective subdirectory structure will               * @param bBackground Determines whether
334               * not be recreated in the instruments database and all instruments               * the task should be done in the background.
335               * will be added directly in the specified database directory.               * @returns If bBackground is true, the ID of the scan job;
336                 * -1 otherwise.
337               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
338               */               */
339              void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false);              int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground);
340    
341              /**              /**
342               * Gets the number of instruments in the specified directory.               * Gets the number of instruments in the specified directory.
343               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
344                 * All slashes in the directory names should be replaced with '\0'.
345                 * @param Recursive If true, the number of all instruments
346                 * in the specified subtree will be returned.
347               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
348               * the specified path name is invalid.               * the specified path name is invalid.
349               * @returns The number of instruments in the specified directory               * @returns The number of instruments in the specified directory.
              * or -1 if the directory doesn't exist.  
350               */               */
351              int GetInstrumentCount(String Dir);              int GetInstrumentCount(String Dir, bool Recursive);
352    
353              /**              /**
354               * Gets the list of instruments in the specified directory.               * Gets the list of instruments in the specified directory.
355               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
356                 * All slashes in the directory names should be replaced with '\0'.
357                 * @param Recursive If true, all instruments
358                 * in the specified subtree will be returned.
359               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
360               * the specified path name is invalid.               * the specified path name is invalid.
361               */               */
362              StringListPtr GetInstruments(String Dir);              StringListPtr GetInstruments(String Dir, bool Recursive);
363    
364              /**              /**
365               * Removes the specified instrument from the database.               * Removes the specified instrument from the database.
366               * @param Instr The absolute path name of the instrument to remove.               * @param Instr The absolute path name of the instrument to remove.
367                 * All slashes in the directory/instrument names should be replaced with '\0'.
368               * @throws Exception - If the specified instrument does not exist,               * @throws Exception - If the specified instrument does not exist,
369               * or database error occurs.               * or database error occurs.
370               */               */
# Line 311  namespace LinuxSampler { Line 373  namespace LinuxSampler {
373              /**              /**
374               * Gets information about the specified instrument.               * Gets information about the specified instrument.
375               * @param Instr The absolute path name of the instrument.               * @param Instr The absolute path name of the instrument.
376                 * All slashes in the directory/instrument names should be replaced with '\0'.
377               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
378               * the specified instrument is not found.               * the specified instrument is not found.
379               */               */
# Line 319  namespace LinuxSampler { Line 382  namespace LinuxSampler {
382              /**              /**
383               * Renames the specified instrument.               * Renames the specified instrument.
384               * @param Instr The absolute path name of the instrument to rename.               * @param Instr The absolute path name of the instrument to rename.
385                 * All slashes in the directory/instrument names should be replaced with '\0'.
386               * @param Name The new name for the instrument.               * @param Name The new name for the instrument.
387               * @throws Exception - In case the given instrument does not exists,               * @throws Exception - In case the given instrument does not exists,
388               * or the specified name is not a valid name, or if an instrument               * or the specified name is not a valid name, or if an instrument
# Line 330  namespace LinuxSampler { Line 394  namespace LinuxSampler {
394              /**              /**
395               * Moves the specified instrument into the specified directory.               * Moves the specified instrument into the specified directory.
396               * @param Instr The absolute path name of the instrument to move.               * @param Instr The absolute path name of the instrument to move.
397                 * All slashes in the directory/instrument names should be replaced with '\0'.
398               * @param Dst The directory where the instrument will be moved to.               * @param Dst The directory where the instrument will be moved to.
399               * @throws Exception - In case the given directory or instrument               * @throws Exception - In case the given directory or instrument
400               * does not exist, or if an instrument with name equal to the name               * does not exist, or if an instrument with name equal to the name
# Line 339  namespace LinuxSampler { Line 404  namespace LinuxSampler {
404              void MoveInstrument(String Instr, String Dst);              void MoveInstrument(String Instr, String Dst);
405    
406              /**              /**
407                 * Copies the specified instrument into the specified directory.
408                 * @param Instr The absolute path name of the instrument to copy.
409                 * All slashes in the directory/instrument names should be replaced with '\0'.
410                 * @param Dst The absolute path name of the directory where the
411                 * instrument will be copied to. All slashes in the directory names
412                 * should be replaced with '\0'.
413                 * @throws Exception - In case the given directory or instrument
414                 * does not exist, or if an instrument with name equal to the name
415                 * of the specified instrument already exists in the specified
416                 * destination directory, or if database error occurs.
417                 */
418                void CopyInstrument(String Instr, String Dst);
419    
420                /**
421               * Changes the description of the specified instrument.               * Changes the description of the specified instrument.
422               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
423               * the specified instrument is not found.               * the specified instrument is not found.
# Line 346  namespace LinuxSampler { Line 425  namespace LinuxSampler {
425              void SetInstrumentDescription(String Instr, String Desc);              void SetInstrumentDescription(String Instr, String Desc);
426                            
427              /**              /**
428                 * Finds all instruments that match the search query.
429                 * @param Dir The absolute path name of the database
430                 * directory to search in.
431                 * All slashes in the directory names should be replaced with '\0'.
432                 * @throws Exception - if database error occurs, or
433                 * if the specified path name is invalid.
434                 * @returns The absolute path names of all instruments
435                 * that match the search query.
436                 */
437                StringListPtr FindInstruments(String Dir, SearchQuery* pQuery, bool Recursive);
438    
439                /**
440                 * All '\0' chars in the string are replaced with "\x2f";
441                 * ', ", \ are escaped with backslash and
442                 * <CR> and <LF> are replaced with \r and \n.
443                 */
444                static String toEscapedPath(String AbstractPath);
445    
446                /**
447                 * The characters ', ", \ are escaped with backslash and
448                 * <CR> and <LF> are replaced with \r and \n.
449                 */
450                static String toEscapedText(String text);
451                
452                /**
453               * Closes the database connection if opened and deletes               * Closes the database connection if opened and deletes
454               * the InstrumentsDb instance.               * the InstrumentsDb instance.
455               */               */
456              static void Destroy();              static void Destroy();
457    
458                            JobList Jobs;
459    
460          private:          private:
461              sqlite3* db;              sqlite3* db;
462              String DbFile;              String DbFile;
463              static InstrumentsDb* pInstrumentsDb;              static InstrumentsDb* pInstrumentsDb;
464              Mutex DbInstrumentsMutex;              Mutex DbInstrumentsMutex;
465              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
466                bool InTransaction;
467                WorkerThread InstrumentsDbThread;
468                            
469              InstrumentsDb();              InstrumentsDb();
470              ~InstrumentsDb();              ~InstrumentsDb();
# Line 387  namespace LinuxSampler { Line 494  namespace LinuxSampler {
494              IntListPtr GetDirectoryIDs(int DirId);              IntListPtr GetDirectoryIDs(int DirId);
495    
496              /**              /**
497                 * Gets the list of directories in the specified directory.
498                 * @param DirId The ID of the directory.
499                 * @returns The list of directories, where the directories are
500                 * represented in abstract path - all slashes in the directory
501                 * names are replaced with '\0'.
502                 * @throws Exception - if database error occurs, or
503                 * the specified ID is invalid.
504                 */
505                StringListPtr GetDirectories(int DirId);
506    
507                /**
508               * Gets the directory ID.               * Gets the directory ID.
509               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
510                 * All slashes in the directory names should be replaced with '\0'.
511               * @returns The directory ID or -1 if the directory is not found.               * @returns The directory ID or -1 if the directory is not found.
512               * @throws Exception - if database error occurs.               * @throws Exception - if database error occurs.
513               */               */
# Line 398  namespace LinuxSampler { Line 517  namespace LinuxSampler {
517               * Gets the directory ID.               * Gets the directory ID.
518               * @param ParentDirId The ID of the parent directory.               * @param ParentDirId The ID of the parent directory.
519               * @param DirName The directory name.               * @param DirName The directory name.
520                 * All slashes in the directory name should be replaced with '\0'.
521               * @throws Exception - if database error occurs.               * @throws Exception - if database error occurs.
522               * @returns The ID of the specified directory               * @returns The ID of the specified directory
523               * or -1 if the directory doesn't exist.               * or -1 if the directory doesn't exist.
# Line 405  namespace LinuxSampler { Line 525  namespace LinuxSampler {
525              int GetDirectoryId(int ParentDirId, String DirName);              int GetDirectoryId(int ParentDirId, String DirName);
526    
527              /**              /**
528                 * Gets the name of the specified directory.
529                 * @throws Exception - if the directory is not found
530                 * or if database error occurs.
531                 */
532                String GetDirectoryName(int DirId);
533    
534                /**
535                 * Gets the ID of the parent directory.
536                 * @throws Exception - if the root directory is specified, or if the
537                 * specified directory is not found, or if database error occurs.
538                 */
539                int GetParentDirectoryId(int DirId);
540    
541                /**
542                 * Gets the absolute path name of the specified directory.
543                 * @param DirId The ID of the directory, which absolute
544                 * path name should be returned.
545                 * @throws Exception If the specified directory is not
546                 * found or if database error occurs.
547                 */
548                String GetDirectoryPath(int DirId);
549    
550                /**
551               * Removes the specified directory from the database.               * Removes the specified directory from the database.
552               * @param DirId The ID of the directory to remove.               * @param DirId The ID of the directory to remove.
553               * @throws Exception - If the specified directory is not empty.               * @throws Exception - If the specified directory is not empty.
# Line 441  namespace LinuxSampler { Line 584  namespace LinuxSampler {
584              /**              /**
585               * Gets the ID of the specified database instrument.               * Gets the ID of the specified database instrument.
586               * @param Instr The absolute path name of the instrument.               * @param Instr The absolute path name of the instrument.
587                 * All slashes in the directory/instrument names should be replaced with '\0'.
588               * @returns The instrument ID or -1 if the instrument is not found.               * @returns The instrument ID or -1 if the instrument is not found.
589               * @throws Exception - if database error occurs.               * @throws Exception - if database error occurs.
590               */               */
# Line 450  namespace LinuxSampler { Line 594  namespace LinuxSampler {
594               * Gets the ID of the specified database instrument.               * Gets the ID of the specified database instrument.
595               * @param DirId The ID of the directory containing the instrument.               * @param DirId The ID of the directory containing the instrument.
596               * @param InstrName The name of the instrument.               * @param InstrName The name of the instrument.
597                 * All slashes in the instrument name should be replaced with '\0'.
598               * @returns The instrument ID or -1 if the instrument is not found.               * @returns The instrument ID or -1 if the instrument is not found.
599               * @throws Exception - if database error occurs.               * @throws Exception - if database error occurs.
600               */               */
601              int GetInstrumentId(int DirId, String InstrName);              int GetInstrumentId(int DirId, String InstrName);
602    
603              /**              /**
604                 * Gets the name of the instrument with the specified ID.
605                 * @param InstrId The ID of the instrument, which name should be obtained.
606                 * @returns The name of the specified instrument, where all slashes
607                 * in the name are replaced with '\0'.
608                 * @throws Exception - if database error occurs.
609                 */
610                String GetInstrumentName(int InstrId);
611    
612                /**
613               * Removes the specified instrument from the database.               * Removes the specified instrument from the database.
614               * @param InstrId The ID of the instrument to remove.               * @param InstrId The ID of the instrument to remove.
615               * @throws Exception - If the specified instrument does not exist.               * @throws Exception - If the specified instrument does not exist.
# Line 486  namespace LinuxSampler { Line 640  namespace LinuxSampler {
640              IntListPtr GetInstrumentIDs(int DirId);              IntListPtr GetInstrumentIDs(int DirId);
641    
642              /**              /**
643                 * Gets information about the specified instrument.
644                 * @param InstrId The ID of the instrument.
645                 * @throws Exception - if database error occurs.
646                 */
647                DbInstrument GetInstrumentInfo(int InstrId);
648    
649                /**
650                 * Copies the specified instrument into the specified directory.
651                 * @param InstrId The ID of the instrument to copy.
652                 * @param InstrName The name of the instrument to copy.
653                 * All slashes in the instrument name should be replaced with '\0'.
654                 * @param DstDirId The ID of the directory where the
655                 * instrument will be copied to.
656                 * @param DstDir The name of the directory where the
657                 * instrument will be copied to.
658                 * @throws Exception - If database error occurs.
659                 */
660                void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);
661    
662                /**
663                 * Adds all supported instruments in the specified directory
664                 * to the specified instruments database directory. The
665                 * instruments in the subdirectories will not be processed.
666                 * @param DbDir The absolute path name of a directory in the
667                 * instruments database in which only the new instruments
668                 * (that are not already in the database) will be added.
669                 * All slashes in the directory names should be replaced with '\0'.
670                 * @param FsDir The absolute path name of a directory in the file
671                 * system.
672                 * @param pProgress The progress used to monitor the scan process.
673                 * @throws Exception if the operation failed.
674                 */
675                void AddInstrumentsNonrecursive(String DbDir, String FsDir, ScanProgress* pProgress = NULL);
676    
677                /**
678                 * Adds all supported instruments in the specified file system
679                 * direcotry to the specified instruments database directory,
680                 * including the instruments in the subdirectories of the
681                 * supplied directory.
682                 * @param DbDir The absolute path name of a directory in the
683                 * instruments database in which only the new instruments
684                 * (that are not already in the database) will be added.
685                 * All slashes in the directory names should be replaced with '\0'.
686                 * @param FsDir The absolute path name of an existing
687                 * directory in the file system.
688                 * @param Flat If true, the respective subdirectory structure will
689                 * not be recreated in the instruments database and all instruments
690                 * will be added directly in the specified database directory.
691                 * @param pProgress The progress used to monitor the scan process.
692                 * @throws Exception if the operation failed.
693                 */
694                void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, ScanProgress* pProgress = NULL);
695    
696                /**
697               * Adds the instruments in the specified file               * Adds the instruments in the specified file
698               * to the specified instruments database directory.               * to the specified instruments database directory.
699               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
700               * instruments database in which only the new instruments               * instruments database in which only the new instruments
701               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
702                 * All slashes in the directory names should be replaced with '\0'.
703               * @param File The absolute path name of a file in the file system.               * @param File The absolute path name of a file in the file system.
704               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
705               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
706               * the supplied instrument file will be added.               * the supplied instrument file will be added.
707                 * @param pProgress The progress used to monitor the scan process.
708                 * Specify NULL if you don't want to monitor the scanning process.
709               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
710               */               */
711              void AddInstrumentsFromFile(String DbDir, String File, int Index = -1);              void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
712    
713              /**              /**
714               * Adds the specified GIG instrument(s) to the specified location               * Adds the specified GIG instrument(s) to the specified location
715               * in the instruments database.               * in the instruments database.
716               * @param DbDir The instruments database directory               * @param DbDir The instruments database directory
717               * in which the instrument will be added.               * in which the instrument will be added.
718                 * All slashes in the directory names should be replaced with '\0'.
719               * @param File The absolute path name of the instrument file.               * @param File The absolute path name of the instrument file.
720               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
721               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
722               * the supplied instrument file will be added.               * the supplied instrument file will be added.
723                 * @param pProgress The progress used to monitor the scan process.
724                 * Specify NULL if you don't want to monitor the scanning process.
725               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
726               */               */
727              void AddGigInstruments(String DbDir, String File, int Index = -1);              void AddGigInstruments(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
728    
729              /**              /**
730               * Adds the specified GIG instrument.               * Adds the specified GIG instrument.
731                 * @param DbDir The instruments database directory
732                 * in which the instrument will be added.
733                 * All slashes in the directory names should be replaced with '\0'.
734               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
735               */               */
736              void AddGigInstrument(sqlite3_stmt* pStmt, String DbDir, int DirId, String File, ::gig::Instrument* pInstrument, int Index);              void AddGigInstrument(sqlite3_stmt* pStmt, String DbDir, int DirId, String File, ::gig::Instrument* pInstrument, int Index);
737                
738                void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler);
739    
740                void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level);
741    
742                /** Locks the DbInstrumentsMutex and starts a transaction. */
743                void BeginTransaction();
744    
745                /** Commits the transaction and unocks the DbInstrumentsMutex. */
746                void EndTransaction();
747                
748              /**              /**
749               * Used to execute SQL commands which return empty result set.               * Used to execute SQL commands which return empty result set.
750               */               */
# Line 575  namespace LinuxSampler { Line 802  namespace LinuxSampler {
802               */               */
803              String GetUniqueInstrumentName(int DirId, String Name);              String GetUniqueInstrumentName(int DirId, String Name);
804    
805                /**
806                 * All '\0' chars in the string are replaced with '/'.
807                 */
808                static String toDbName(String AbstractName);
809    
810                /**
811                 * All slashes are replaced with '\0'.
812                 */
813                static String toAbstractName(String DbName);
814    
815                static String toEscapedFsPath(String FsPath);
816    
817              void FireDirectoryCountChanged(String Dir);              void FireDirectoryCountChanged(String Dir);
818              void FireDirectoryInfoChanged(String Dir);              void FireDirectoryInfoChanged(String Dir);
819              void FireDirectoryNameChanged(String Dir, String NewName);              void FireDirectoryNameChanged(String Dir, String NewName);
820              void FireInstrumentCountChanged(String Dir);              void FireInstrumentCountChanged(String Dir);
821              void FireInstrumentInfoChanged(String Instr);              void FireInstrumentInfoChanged(String Instr);
822              void FireInstrumentNameChanged(String Instr, String NewName);              void FireInstrumentNameChanged(String Instr, String NewName);
823                void FireJobStatusChanged(int JobId);
824    
825              /**              /**
826               * Strips the non-directory suffix from the file name. If the string               * Strips the non-directory suffix from the file name. If the string
# Line 613  namespace LinuxSampler { Line 853  namespace LinuxSampler {
853               * @throws Exception - if the specified file name is invalid.               * @throws Exception - if the specified file name is invalid.
854               */               */
855              static void CheckFileName(String File);              static void CheckFileName(String File);
856      };              
857                    /** SQLite user function for handling regular expressions */
858      /**              static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);
      * This class is used for recursive  
      */  
     class DirectoryScanner {  
         public:  
             /**  
              * Recursively scans all subdirectories of the specified  
              * directory and adds the supported instruments to the database.  
              * @throws Exception - if the specified directories are invalid.  
              */  
             static void Scan(String DbDir, String FsDir, bool Flat);  
   
         private:  
             static String DbDir;  
             static String FsDir;  
             static bool Flat;  
             static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);  
859      };      };
860    
861  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1161  
changed lines
  Added in v.1350

  ViewVC Help
Powered by ViewVC