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

Legend:
Removed from v.1163  
changed lines
  Added in v.1644

  ViewVC Help
Powered by ViewVC