/[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 1199 by iliev, Wed May 16 14:22:26 2007 UTC revision 1200 by iliev, Thu May 24 14:04:18 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&);  
     };  
   
     class SearchQuery {  
         public:  
             enum InstrumentType {  
                 CHROMATIC = 0,  
                 DRUM = 1,  
                 BOTH = 2  
             };  
   
             String Name;  
             std::vector<String> FormatFamilies;  
             long long MinSize;  
             long long MaxSize;  
             String CreatedBefore;  
             String CreatedAfter;  
             String ModifiedBefore;  
             String ModifiedAfter;  
             String Description;  
             String Product;  
             String Artists;  
             String Keywords;  
             InstrumentType InstrType;  
               
             SearchQuery();  
             void SetFormatFamilies(String s);  
             void SetSize(String s);  
             void SetCreated(String s);  
             void SetModified(String s);  
   
         private:  
             String GetMin(String s);  
             String GetMax(String s);  
     };  
   
     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 159  namespace LinuxSampler { Line 97  namespace LinuxSampler {
97                       * @param NewName The new name of the directory.                       * @param NewName The new name of the directory.
98                       */                       */
99                      virtual void InstrumentNameChanged(String Instr, String NewName) = 0;                      virtual void InstrumentNameChanged(String Instr, String NewName) = 0;
100    
101                        /**
102                         * Invoked when the status of particular job is changed.
103                         * @param JobId The ID of the job.
104                         */
105                        virtual void JobStatusChanged(int JobId) = 0;
106              };              };
107    
108              /**              /**
# Line 314  namespace LinuxSampler { Line 258  namespace LinuxSampler {
258               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
259               * the supplied instrument file will be added. Error is thrown if               * the supplied instrument file will be added. Error is thrown if
260               * a directory is supplied and Index is not equal to -1.               * a directory is supplied and Index is not equal to -1.
261                 * @param bBackground Determines whether
262                 * the task should be done in the background.
263                 * @returns If bBackground is true, the ID of the scan job;
264                 * -1 otherwise.
265               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
266               */               */
267              void AddInstruments(String DbDir, String FilePath, int Index = -1);              int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground);
268    
269              /**              /**
270               * Adds all supported instruments in the specified directory               * Adds the instruments in the specified file
271               * to the specified instruments database directory. The               * to the specified instruments database directory.
              * instruments in the subdirectories will not be processed  
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               * @param FsDir The absolute path name of a directory in the file               * @param FilePath The absolute path name of the instrument file.
276               * system.               * @param Index The index of the instrument (in the given
277                 * instrument file) to add. If -1 is specified, all instruments in
278                 * the supplied instrument file will be added.
279                 * @param pProgress The progress used to monitor the scan process.
280               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
281               */               */
282              void AddInstrumentsNonrecursive(String DbDir, String FsDir);              void AddInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL);
283    
284              /**              /**
285               * Adds all supported instruments in the specified file system               * Adds all supported instruments in the specified file system
286               * direcotry to the specified instruments database directory,               * direcotry to the specified instruments database directory.
287               * including the instruments in the subdirectories of the               * @param Mode Determines the scanning mode. If RECURSIVE is
288               * supplied directory.               * specified, all supported instruments in the specified file system
289                 * direcotry will be added to the specified instruments database
290                 * directory, including the instruments in subdirectories
291                 * of the supplied directory. If NON_RECURSIVE is specified,
292                 * the instruments in the subdirectories will not be processed.
293                 * If FLAT is specified, all supported instruments in the specified
294                 * file system direcotry will be added, including the instruments in
295                 * subdirectories of the supplied directory, but the respective
296                 * subdirectory structure will not be recreated in the instruments
297                 * database and all instruments will be added directly in the
298                 * specified database directory.
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 an existing               * @param FsDir The absolute path name of an existing
303               * directory in the file system.               * directory in the file system.
304               * @param Flat If true, the respective subdirectory structure will               * @param bBackground Determines whether
305               * not be recreated in the instruments database and all instruments               * the task should be done in the background.
306               * will be added directly in the specified database directory.               * @returns If bBackground is true, the ID of the scan job;
307                 * -1 otherwise.
308               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
309               */               */
310              void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false);              int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground);
311    
312              /**              /**
313               * Gets the number of instruments in the specified directory.               * Gets the number of instruments in the specified directory.
# Line 442  namespace LinuxSampler { Line 403  namespace LinuxSampler {
403               */               */
404              static void Destroy();              static void Destroy();
405    
406                JobList Jobs;
407    
408          private:          private:
             class DirectoryHandler {  
                 public:  
                     virtual void ProcessDirectory(String Path, int DirId) = 0;  
             };  
               
             class AbstractFinder : public DirectoryHandler {  
                 public:  
                     virtual void ProcessDirectory(String Path, int DirId) = 0;  
                       
                     bool IsRegex(String Pattern);  
                     void AddSql(String Col, String Pattern, std::stringstream& Sql);  
   
                 protected:  
                     std::vector<String> Params;  
             };  
               
             class DirectoryFinder : public AbstractFinder {  
                 public:  
                     DirectoryFinder(SearchQuery* pQuery);  
                     ~DirectoryFinder();  
                     StringListPtr GetDirectories();  
                     virtual void ProcessDirectory(String Path, int DirId);  
   
                 private:  
                     sqlite3_stmt* pStmt;  
                     String SqlQuery;  
                     SearchQuery* pQuery;  
                     StringListPtr pDirectories;  
                       
             };  
               
             class InstrumentFinder : public AbstractFinder {  
                 public:  
                     InstrumentFinder(SearchQuery* pQuery);  
                     ~InstrumentFinder();  
                     StringListPtr GetInstruments();  
                     virtual void ProcessDirectory(String Path, int DirId);  
   
                 private:  
                     sqlite3_stmt* pStmt;  
                     String SqlQuery;  
                     SearchQuery* pQuery;  
                     StringListPtr pInstruments;  
             };  
               
             class DirectoryCounter : public DirectoryHandler {  
                 public:  
                     DirectoryCounter() { count = 0; }  
                     virtual void ProcessDirectory(String Path, int DirId);  
                     int GetDirectoryCount() { return count; }  
   
                 private:  
                     int count;  
             };  
               
             class InstrumentCounter : public DirectoryHandler {  
                 public:  
                     InstrumentCounter() { count = 0; }  
                     virtual void ProcessDirectory(String Path, int DirId);  
                     int GetInstrumentCount() { return count; }  
   
                 private:  
                     int count;  
             };  
               
             class DirectoryCopier : public DirectoryHandler {  
                 public:  
                     DirectoryCopier(String SrcParentDir, String DestDir);  
                     virtual void ProcessDirectory(String Path, int DirId);  
   
                 private:  
                     String SrcParentDir;  
                     String DestDir;  
             };  
               
409              sqlite3* db;              sqlite3* db;
410              String DbFile;              String DbFile;
411              static InstrumentsDb* pInstrumentsDb;              static InstrumentsDb* pInstrumentsDb;
412              Mutex DbInstrumentsMutex;              Mutex DbInstrumentsMutex;
413              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
414              bool InTransaction;              bool InTransaction;
415                WorkerThread InstrumentsDbThread;
416                            
417              InstrumentsDb();              InstrumentsDb();
418              ~InstrumentsDb();              ~InstrumentsDb();
# Line 711  namespace LinuxSampler { Line 599  namespace LinuxSampler {
599              void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);              void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);
600    
601              /**              /**
602                 * Adds all supported instruments in the specified directory
603                 * to the specified instruments database directory. The
604                 * instruments in the subdirectories will not be processed.
605                 * @param DbDir The absolute path name of a directory in the
606                 * instruments database in which only the new instruments
607                 * (that are not already in the database) will be added.
608                 * @param FsDir The absolute path name of a directory in the file
609                 * system.
610                 * @param pProgress The progress used to monitor the scan process.
611                 * @throws Exception if the operation failed.
612                 */
613                void AddInstrumentsNonrecursive(String DbDir, String FsDir, ScanProgress* pProgress = NULL);
614    
615                /**
616                 * Adds all supported instruments in the specified file system
617                 * direcotry to the specified instruments database directory,
618                 * including the instruments in the subdirectories of the
619                 * supplied directory.
620                 * @param DbDir The absolute path name of a directory in the
621                 * instruments database in which only the new instruments
622                 * (that are not already in the database) will be added.
623                 * @param FsDir The absolute path name of an existing
624                 * directory in the file system.
625                 * @param Flat If true, the respective subdirectory structure will
626                 * not be recreated in the instruments database and all instruments
627                 * will be added directly in the specified database directory.
628                 * @param pProgress The progress used to monitor the scan process.
629                 * @throws Exception if the operation failed.
630                 */
631                void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, ScanProgress* pProgress = NULL);
632    
633                /**
634               * Adds the instruments in the specified file               * Adds the instruments in the specified file
635               * to the specified instruments database directory.               * to the specified instruments database directory.
636               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
# Line 720  namespace LinuxSampler { Line 640  namespace LinuxSampler {
640               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
641               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
642               * the supplied instrument file will be added.               * the supplied instrument file will be added.
643                 * @param pProgress The progress used to monitor the scan process.
644                 * Specify NULL if you don't want to monitor the scanning process.
645               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
646               */               */
647              void AddInstrumentsFromFile(String DbDir, String File, int Index = -1);              void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
648    
649              /**              /**
650               * Adds the specified GIG instrument(s) to the specified location               * Adds the specified GIG instrument(s) to the specified location
# Line 733  namespace LinuxSampler { Line 655  namespace LinuxSampler {
655               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
656               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
657               * the supplied instrument file will be added.               * the supplied instrument file will be added.
658                 * @param pProgress The progress used to monitor the scan process.
659                 * Specify NULL if you don't want to monitor the scanning process.
660               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
661               */               */
662              void AddGigInstruments(String DbDir, String File, int Index = -1);              void AddGigInstruments(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
663    
664              /**              /**
665               * Adds the specified GIG instrument.               * Adds the specified GIG instrument.
# Line 816  namespace LinuxSampler { Line 740  namespace LinuxSampler {
740              void FireInstrumentCountChanged(String Dir);              void FireInstrumentCountChanged(String Dir);
741              void FireInstrumentInfoChanged(String Instr);              void FireInstrumentInfoChanged(String Instr);
742              void FireInstrumentNameChanged(String Instr, String NewName);              void FireInstrumentNameChanged(String Instr, String NewName);
743                void FireJobStatusChanged(int JobId);
744    
745              /**              /**
746               * 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 852  namespace LinuxSampler { Line 777  namespace LinuxSampler {
777              /** SQLite user function for handling regular expressions */              /** SQLite user function for handling regular expressions */
778              static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);              static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);
779      };      };
       
     /**  
      * 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);  
     };  
780    
781  } // namespace LinuxSampler  } // namespace LinuxSampler
782    

Legend:
Removed from v.1199  
changed lines
  Added in v.1200

  ViewVC Help
Powered by ViewVC