/[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 1186 by iliev, Mon Apr 16 21:56:18 2007 UTC revision 1187 by iliev, Wed May 16 14:22:26 2007 UTC
# Line 66  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66              void operator=(const DbDirectory& Dir) { Copy(Dir); }              void operator=(const DbDirectory& Dir) { Copy(Dir); }
67              void Copy(const DbDirectory&);              void Copy(const DbDirectory&);
68      };      };
69        
70        class SearchQuery {
71            public:
72                enum InstrumentType {
73                    CHROMATIC = 0,
74                    DRUM = 1,
75                    BOTH = 2
76                };
77    
78                String Name;
79                std::vector<String> FormatFamilies;
80                long long MinSize;
81                long long MaxSize;
82                String CreatedBefore;
83                String CreatedAfter;
84                String ModifiedBefore;
85                String ModifiedAfter;
86                String Description;
87                String Product;
88                String Artists;
89                String Keywords;
90                InstrumentType InstrType;
91                
92                SearchQuery();
93                void SetFormatFamilies(String s);
94                void SetSize(String s);
95                void SetCreated(String s);
96                void SetModified(String s);
97    
98            private:
99                String GetMin(String s);
100                String GetMax(String s);
101        };
102    
103      typedef std::auto_ptr<std::vector<int> > IntListPtr;      typedef std::auto_ptr<std::vector<int> > IntListPtr;
104      typedef std::auto_ptr<std::vector<String> > StringListPtr;      typedef std::auto_ptr<std::vector<String> > StringListPtr;
105    
# Line 140  namespace LinuxSampler { Line 173  namespace LinuxSampler {
173              void RemoveInstrumentsDbListener(InstrumentsDb::Listener* l);              void RemoveInstrumentsDbListener(InstrumentsDb::Listener* l);
174    
175              /**              /**
176                 * Creates an instruments database file.
177                 * @param File the pathname of the file to create.
178                 * @throws Exception If the creation of the database file failed.
179                 */
180                static void CreateInstrumentsDb(String File);
181    
182                /**
183               * This method is used to access the instruments database.               * This method is used to access the instruments database.
184               */               */
185              static InstrumentsDb* GetInstrumentsDb();              static InstrumentsDb* GetInstrumentsDb();
# Line 156  namespace LinuxSampler { Line 196  namespace LinuxSampler {
196              /**              /**
197               * Gets the number of directories in the specified directory.               * Gets the number of directories in the specified directory.
198               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
199                 * @param Recursive If true, the number of all directories
200                 * in the specified subtree will be returned.
201               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
202               * the specified path name is invalid.               * the specified path name is invalid.
203               * @returns The number of directories in the specified directory.               * @returns The number of directories in the specified directory.
204               */               */
205              int GetDirectoryCount(String Dir);              int GetDirectoryCount(String Dir, bool Recursive);
206    
207              /**              /**
208               * Gets the list of directories in the specified directory.               * Gets the list of directories in the specified directory.
209               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
210                 * @param Recursive If true, all directories
211                 * in the specified subtree will be returned.
212               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
213               * the specified path name is invalid.               * the specified path name is invalid.
214               */               */
215              StringListPtr GetDirectories(String Dir);              StringListPtr GetDirectories(String Dir, bool Recursive);
216    
217              /**              /**
218               * Adds the specified directory to the database.               * Adds the specified directory to the database.
# Line 225  namespace LinuxSampler { Line 269  namespace LinuxSampler {
269              void MoveDirectory(String Dir, String Dst);              void MoveDirectory(String Dir, String Dst);
270    
271              /**              /**
272                 * Copies the specified directory into the specified location.
273                 * @param Dir The absolute path name of the directory to copy.
274                 * @param Dst The location where the directory will be copied to.
275                 * @throws Exception - In case a given directory does not exists,
276                 * or if a directory with name equal to the directory name already
277                 * exists in the specified destination directory, or if database error
278                 * occurs. Error is also thrown when trying to copy a directory to a
279                 * subdirectory of itself.
280                 */
281                void CopyDirectory(String Dir, String Dst);
282    
283                /**
284               * Changes the description of the specified directory.               * Changes the description of the specified directory.
285               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
286               * the specified directory is not found.               * the specified directory is not found.
287               */               */
288              void SetDirectoryDescription(String Dir, String Desc);              void SetDirectoryDescription(String Dir, String Desc);
289                
290                /**
291                 * Finds all directories that match the search query.
292                 * @param Dir The absolute path name of the database
293                 * directory to search in.
294                 * @throws Exception - if database error occurs, or
295                 * if the specified path name is invalid.
296                 * @returns The absolute path names of all directories
297                 * that match the search query.
298                 */
299                StringListPtr FindDirectories(String Dir, SearchQuery* pQuery, bool Recursive);
300    
301              /**              /**
302               * Adds the instruments in the specified file or               * Adds the instruments in the specified file or
# Line 284  namespace LinuxSampler { Line 351  namespace LinuxSampler {
351              /**              /**
352               * Gets the number of instruments in the specified directory.               * Gets the number 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                 * @param Recursive If true, the number of all instruments
355                 * in the specified subtree will be returned.
356               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
357               * the specified path name is invalid.               * the specified path name is invalid.
358               * @returns The number of instruments in the specified directory.               * @returns The number of instruments in the specified directory.
359               */               */
360              int GetInstrumentCount(String Dir);              int GetInstrumentCount(String Dir, bool Recursive);
361    
362              /**              /**
363               * Gets the list of instruments in the specified directory.               * Gets the list of instruments in the specified directory.
364               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
365                 * @param Recursive If true, all instruments
366                 * in the specified subtree will be returned.
367               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
368               * the specified path name is invalid.               * the specified path name is invalid.
369               */               */
370              StringListPtr GetInstruments(String Dir);              StringListPtr GetInstruments(String Dir, bool Recursive);
371    
372              /**              /**
373               * Removes the specified instrument from the database.               * Removes the specified instrument from the database.
# Line 337  namespace LinuxSampler { Line 408  namespace LinuxSampler {
408              void MoveInstrument(String Instr, String Dst);              void MoveInstrument(String Instr, String Dst);
409    
410              /**              /**
411                 * Copies the specified instrument into the specified directory.
412                 * @param Instr The absolute path name of the instrument to copy.
413                 * @param Dst The directory where the instrument will be copied to.
414                 * @throws Exception - In case the given directory or instrument
415                 * does not exist, or if an instrument with name equal to the name
416                 * of the specified instrument already exists in the specified
417                 * destination directory, or if database error occurs.
418                 */
419                void CopyInstrument(String Instr, String Dst);
420    
421                /**
422               * Changes the description of the specified instrument.               * Changes the description of the specified instrument.
423               * @throws Exception - if database error occurs, or if               * @throws Exception - if database error occurs, or if
424               * the specified instrument is not found.               * the specified instrument is not found.
# Line 344  namespace LinuxSampler { Line 426  namespace LinuxSampler {
426              void SetInstrumentDescription(String Instr, String Desc);              void SetInstrumentDescription(String Instr, String Desc);
427                            
428              /**              /**
429                 * Finds all instruments that match the search query.
430                 * @param Dir The absolute path name of the database
431                 * directory to search in.
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               * Closes the database connection if opened and deletes               * Closes the database connection if opened and deletes
441               * the InstrumentsDb instance.               * the InstrumentsDb instance.
442               */               */
443              static void Destroy();              static void Destroy();
444    
445                
446          private:          private:
447                class DirectoryHandler {
448                    public:
449                        virtual void ProcessDirectory(String Path, int DirId) = 0;
450                };
451                
452                class AbstractFinder : public DirectoryHandler {
453                    public:
454                        virtual void ProcessDirectory(String Path, int DirId) = 0;
455                        
456                        bool IsRegex(String Pattern);
457                        void AddSql(String Col, String Pattern, std::stringstream& Sql);
458    
459                    protected:
460                        std::vector<String> Params;
461                };
462                
463                class DirectoryFinder : public AbstractFinder {
464                    public:
465                        DirectoryFinder(SearchQuery* pQuery);
466                        ~DirectoryFinder();
467                        StringListPtr GetDirectories();
468                        virtual void ProcessDirectory(String Path, int DirId);
469    
470                    private:
471                        sqlite3_stmt* pStmt;
472                        String SqlQuery;
473                        SearchQuery* pQuery;
474                        StringListPtr pDirectories;
475                        
476                };
477                
478                class InstrumentFinder : public AbstractFinder {
479                    public:
480                        InstrumentFinder(SearchQuery* pQuery);
481                        ~InstrumentFinder();
482                        StringListPtr GetInstruments();
483                        virtual void ProcessDirectory(String Path, int DirId);
484    
485                    private:
486                        sqlite3_stmt* pStmt;
487                        String SqlQuery;
488                        SearchQuery* pQuery;
489                        StringListPtr pInstruments;
490                };
491                
492                class DirectoryCounter : public DirectoryHandler {
493                    public:
494                        DirectoryCounter() { count = 0; }
495                        virtual void ProcessDirectory(String Path, int DirId);
496                        int GetDirectoryCount() { return count; }
497    
498                    private:
499                        int count;
500                };
501                
502                class InstrumentCounter : public DirectoryHandler {
503                    public:
504                        InstrumentCounter() { count = 0; }
505                        virtual void ProcessDirectory(String Path, int DirId);
506                        int GetInstrumentCount() { return count; }
507    
508                    private:
509                        int count;
510                };
511                
512                class DirectoryCopier : public DirectoryHandler {
513                    public:
514                        DirectoryCopier(String SrcParentDir, String DestDir);
515                        virtual void ProcessDirectory(String Path, int DirId);
516    
517                    private:
518                        String SrcParentDir;
519                        String DestDir;
520                };
521                
522              sqlite3* db;              sqlite3* db;
523              String DbFile;              String DbFile;
524              static InstrumentsDb* pInstrumentsDb;              static InstrumentsDb* pInstrumentsDb;
525              Mutex DbInstrumentsMutex;              Mutex DbInstrumentsMutex;
526              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
527                bool InTransaction;
528                            
529              InstrumentsDb();              InstrumentsDb();
530              ~InstrumentsDb();              ~InstrumentsDb();
# Line 385  namespace LinuxSampler { Line 554  namespace LinuxSampler {
554              IntListPtr GetDirectoryIDs(int DirId);              IntListPtr GetDirectoryIDs(int DirId);
555    
556              /**              /**
557                 * Gets the list of directories in the specified directory.
558                 * @param DirId The ID of the directory.
559                 * @throws Exception - if database error occurs, or
560                 * the specified ID is invalid.
561                 */
562                StringListPtr GetDirectories(int DirId);
563    
564                /**
565               * Gets the directory ID.               * Gets the directory ID.
566               * @param Dir The absolute path name of the directory.               * @param Dir The absolute path name of the directory.
567               * @returns The directory ID or -1 if the directory is not found.               * @returns The directory ID or -1 if the directory is not found.
# Line 403  namespace LinuxSampler { Line 580  namespace LinuxSampler {
580              int GetDirectoryId(int ParentDirId, String DirName);              int GetDirectoryId(int ParentDirId, String DirName);
581    
582              /**              /**
583                 * Gets the name of the specified directory.
584                 * @throws Exception - if the directory is not found
585                 * or if database error occurs.
586                 */
587                String GetDirectoryName(int DirId);
588    
589                /**
590                 * Gets the ID of the parent directory.
591                 * @throws Exception - if the root directory is specified, or if the
592                 * specified directory is not found, or if database error occurs.
593                 */
594                int GetParentDirectoryId(int DirId);
595    
596                /**
597                 * Gets the absolute path name of the specified directory.
598                 * @param DirId The ID of the directory, which absolute
599                 * path name should be returned.
600                 * @throws Exception If the specified directory is not
601                 * found or if database error occurs.
602                 */
603                String GetDirectoryPath(int DirId);
604    
605                /**
606               * Removes the specified directory from the database.               * Removes the specified directory from the database.
607               * @param DirId The ID of the directory to remove.               * @param DirId The ID of the directory to remove.
608               * @throws Exception - If the specified directory is not empty.               * @throws Exception - If the specified directory is not empty.
# Line 454  namespace LinuxSampler { Line 654  namespace LinuxSampler {
654              int GetInstrumentId(int DirId, String InstrName);              int GetInstrumentId(int DirId, String InstrName);
655    
656              /**              /**
657                 * Gets the name of the instrument with the specified ID.
658                 * @param InstrId The ID of the instrument, which name should be obtained.
659                 * @returns The name of the specified instrument.
660                 * @throws Exception - if database error occurs.
661                 */
662                String GetInstrumentName(int InstrId);
663    
664                /**
665               * Removes the specified instrument from the database.               * Removes the specified instrument from the database.
666               * @param InstrId The ID of the instrument to remove.               * @param InstrId The ID of the instrument to remove.
667               * @throws Exception - If the specified instrument does not exist.               * @throws Exception - If the specified instrument does not exist.
# Line 484  namespace LinuxSampler { Line 692  namespace LinuxSampler {
692              IntListPtr GetInstrumentIDs(int DirId);              IntListPtr GetInstrumentIDs(int DirId);
693    
694              /**              /**
695                 * Gets information about the specified instrument.
696                 * @param InstrId The ID of the instrument.
697                 * @throws Exception - if database error occurs.
698                 */
699                DbInstrument GetInstrumentInfo(int InstrId);
700    
701                /**
702                 * Copies the specified instrument into the specified directory.
703                 * @param InstrId The ID of the instrument to copy.
704                 * @param InstrId The name of the instrument to copy.
705                 * @param DstDirId The ID of the directory where the
706                 * instrument will be copied to.
707                 * @param DstDirId The name of the directory where the
708                 * instrument will be copied to.
709                 * @throws Exception - If database error occurs.
710                 */
711                void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);
712    
713                /**
714               * Adds the instruments in the specified file               * Adds the instruments in the specified file
715               * to the specified instruments database directory.               * to the specified instruments database directory.
716               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
# Line 515  namespace LinuxSampler { Line 742  namespace LinuxSampler {
742               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
743               */               */
744              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);
745                
746                void DirectoryTreeWalk(String Path, DirectoryHandler* pHandler);
747    
748                void DirectoryTreeWalk(DirectoryHandler* pHandler, String Path, int DirId, int Level);
749    
750                /** Locks the DbInstrumentsMutex and starts a transaction. */
751                void BeginTransaction();
752    
753                /** Commits the transaction and unocks the DbInstrumentsMutex. */
754                void EndTransaction();
755                
756              /**              /**
757               * Used to execute SQL commands which return empty result set.               * Used to execute SQL commands which return empty result set.
758               */               */
# Line 611  namespace LinuxSampler { Line 848  namespace LinuxSampler {
848               * @throws Exception - if the specified file name is invalid.               * @throws Exception - if the specified file name is invalid.
849               */               */
850              static void CheckFileName(String File);              static void CheckFileName(String File);
851                
852                /** SQLite user function for handling regular expressions */
853                static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);
854      };      };
855            
856      /**      /**

Legend:
Removed from v.1186  
changed lines
  Added in v.1187

  ViewVC Help
Powered by ViewVC