/[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 1345 by iliev, Thu Sep 13 21:46:25 2007 UTC revision 1727 by iliev, Tue Apr 29 15:44:09 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    
# Line 56  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 66  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    
# Line 118  namespace LinuxSampler { Line 124  namespace LinuxSampler {
124    
125              /**              /**
126               * Creates an instruments database file.               * Creates an instruments database file.
127               * @param File the pathname of the file to create.               * @param FilePath the pathname of the file to create.
128               * @throws Exception If the creation of the database file failed.               * @throws Exception If the creation of the database file failed.
129               */               */
130              static void CreateInstrumentsDb(String File);              static void CreateInstrumentsDb(String FilePath);
131    
132              /**              /**
133               * This method is used to access the instruments database.               * This method is used to access the instruments database.
# Line 252  namespace LinuxSampler { Line 258  namespace LinuxSampler {
258               * Finds all directories that match the search query.               * Finds all directories that match the search query.
259               * @param Dir The absolute path name of the database               * @param Dir The absolute path name of the database
260               * directory to search in.               * directory to search in.
261                 * All slashes in the directory names should be replaced with '\0'.
262               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
263               * if the specified path name is invalid.               * if the specified path name is invalid.
264               * @returns The absolute path names of all directories               * @returns The absolute path names of all directories
# Line 265  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 289  namespace LinuxSampler { Line 297  namespace LinuxSampler {
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                 * All slashes in the directory names should be replaced with '\0'.
301               * @param FilePath The absolute path name of the instrument file.               * @param FilePath The absolute path name of the instrument file.
302               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
303               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
# Line 316  namespace LinuxSampler { Line 325  namespace LinuxSampler {
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 bBackground Determines whether               * @param bBackground Determines whether
# Line 329  namespace LinuxSampler { Line 339  namespace LinuxSampler {
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               * @param Recursive If true, the number of all instruments
344               * in the specified subtree will be returned.               * in the specified subtree will be returned.
345               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
# Line 340  namespace LinuxSampler { Line 351  namespace LinuxSampler {
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               * @param Recursive If true, all instruments
356               * in the specified subtree will be returned.               * in the specified subtree will be returned.
357               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
# Line 350  namespace LinuxSampler { Line 362  namespace LinuxSampler {
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 358  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 366  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 377  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 410  namespace LinuxSampler { Line 426  namespace LinuxSampler {
426               * Finds all instruments that match the search query.               * Finds all instruments that match the search query.
427               * @param Dir The absolute path name of the database               * @param Dir The absolute path name of the database
428               * directory to search in.               * directory to search in.
429                 * All slashes in the directory names should be replaced with '\0'.
430               * @throws Exception - if database error occurs, or               * @throws Exception - if database error occurs, or
431               * if the specified path name is invalid.               * if the specified path name is invalid.
432               * @returns The absolute path names of all instruments               * @returns The absolute path names of all instruments
433               * that match the search query.               * that match the search query.
434               */               */
435              StringListPtr FindInstruments(String Dir, SearchQuery* pQuery, bool Recursive);              StringListPtr FindInstruments(String Dir, SearchQuery* pQuery, bool Recursive);
436                
437                /**
438                 * Checks all instrument files in the database and returns a list
439                 * of all files that dosn't exist in the filesystem.
440                 * @throws Exception - if database error occurs.
441                 * @returns The absolute path names of all lost instrument files.
442                 */
443                StringListPtr FindLostInstrumentFiles();
444    
445                /**
446                 * Substitutes all occurrences of the instrument file
447                 * OldPath in the database, with NewPath.
448                 * @throws Exception - If error occurs.
449                 */
450                void SetInstrumentFilePath(String OldPath, String NewPath);
451                
452                /**
453                 * Gets a list of all instruments in the instruments database
454                 * that are located in the specified instrument file.
455                 * @param File The absolute path name of the instrument file.
456                 * @throws Exception If database error occurs.
457                 */
458                StringListPtr GetInstrumentsByFile(String File);
459    
460              /**              /**
461               * All '\0' chars in the string are replaced with "\/";               * Removes the old instruments datbase and re-creates
462                 * the instruments database from scratch.
463                 */
464                void Format();
465    
466                /**
467                 * All '\0' chars in the string are replaced with "\x2f";
468               * ', ", \ are escaped with backslash and               * ', ", \ are escaped with backslash and
469               * <CR> and <LF> are replaced with \r and \n.               * <CR> and <LF> are replaced with \r and \n.
470               */               */
# Line 430  namespace LinuxSampler { Line 476  namespace LinuxSampler {
476               */               */
477              static String toEscapedText(String text);              static String toEscapedText(String text);
478    
479              /**              static String toNonEscapedText(String text);
              *  All '\0' chars in the string are replaced with '/';  
              * The characthers ', ", \ are escaped with backslash and  
              * <CR> and <LF> are replaced with \r and \n.  
              */  
             static String toEscapedName(String AbstractName);  
480                            
             /**  
              * Closes the database connection if opened and deletes  
              * the InstrumentsDb instance.  
              */  
             static void Destroy();  
   
481              JobList Jobs;              JobList Jobs;
482    
483          private:          private:
484              sqlite3* db;              sqlite3* db;
485              String DbFile;              String DbFile;
486              static InstrumentsDb* pInstrumentsDb;              static InstrumentsDb instance;
487              Mutex DbInstrumentsMutex;              Mutex DbInstrumentsMutex;
488              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;              ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
489              bool InTransaction;              bool InTransaction;
# Line 513  namespace LinuxSampler { Line 548  namespace LinuxSampler {
548              int GetDirectoryId(int ParentDirId, String DirName);              int GetDirectoryId(int ParentDirId, String DirName);
549    
550              /**              /**
551                 * Gets the ID of the directory, in which the specified instrument is located.
552                 * @param InstrId The ID of the instrument.
553                 * @returns The directory ID or -1 if the directory is not found.
554                 * @throws Exception - if database error occurs.
555                 */
556                int GetDirectoryId(int InstrId);
557    
558                /**
559               * Gets the name of the specified directory.               * Gets the name of the specified directory.
560               * @throws Exception - if the directory is not found               * @throws Exception - if the directory is not found
561               * or if database error occurs.               * or if database error occurs.
# Line 638  namespace LinuxSampler { Line 681  namespace LinuxSampler {
681               * Copies the specified instrument into the specified directory.               * Copies the specified instrument into the specified directory.
682               * @param InstrId The ID of the instrument to copy.               * @param InstrId The ID of the instrument to copy.
683               * @param InstrName The name of the instrument to copy.               * @param InstrName The name of the instrument to copy.
684                 * All slashes in the instrument name should be replaced with '\0'.
685               * @param DstDirId The ID of the directory where the               * @param DstDirId The ID of the directory where the
686               * instrument will be copied to.               * instrument will be copied to.
687               * @param DstDir The name of the directory where the               * @param DstDir The name of the directory where the
# Line 653  namespace LinuxSampler { Line 697  namespace LinuxSampler {
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 FsDir The absolute path name of a directory in the file               * @param FsDir The absolute path name of a directory in the file
702               * system.               * system.
703               * @param pProgress The progress used to monitor the scan process.               * @param pProgress The progress used to monitor the scan process.
# Line 668  namespace LinuxSampler { Line 713  namespace LinuxSampler {
713               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
714               * instruments database in which only the new instruments               * instruments database in which only the new instruments
715               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
716                 * All slashes in the directory names should be replaced with '\0'.
717               * @param FsDir The absolute path name of an existing               * @param FsDir The absolute path name of an existing
718               * directory in the file system.               * directory in the file system.
719               * @param Flat If true, the respective subdirectory structure will               * @param Flat If true, the respective subdirectory structure will
# Line 684  namespace LinuxSampler { Line 730  namespace LinuxSampler {
730               * @param DbDir The absolute path name of a directory in the               * @param DbDir The absolute path name of a directory in the
731               * instruments database in which only the new instruments               * instruments database in which only the new instruments
732               * (that are not already in the database) will be added.               * (that are not already in the database) will be added.
733                 * All slashes in the directory names should be replaced with '\0'.
734               * @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.
735               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
736               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
# Line 699  namespace LinuxSampler { Line 746  namespace LinuxSampler {
746               * in the instruments database.               * in the instruments database.
747               * @param DbDir The instruments database directory               * @param DbDir The instruments database directory
748               * in which the instrument will be added.               * in which the instrument will be added.
749               * @param File The absolute path name of the instrument file.               * All slashes in the directory names should be replaced with '\0'.
750                 * @param FilePath The absolute path name of the instrument file.
751               * @param Index The index of the instrument (in the given               * @param Index The index of the instrument (in the given
752               * instrument file) to add. If -1 is specified, all instruments in               * instrument file) to add. If -1 is specified, all instruments in
753               * the supplied instrument file will be added.               * the supplied instrument file will be added.
# Line 707  namespace LinuxSampler { Line 755  namespace LinuxSampler {
755               * Specify NULL if you don't want to monitor the scanning process.               * Specify NULL if you don't want to monitor the scanning process.
756               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
757               */               */
758              void AddGigInstruments(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);              void AddGigInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL);
759    
760              /**              /**
761               * Adds the specified GIG instrument.               * Adds the specified GIG instrument.
762                 * @param DbDir The instruments database directory
763                 * in which the instrument will be added.
764                 * All slashes in the directory names should be replaced with '\0'.
765               * @throws Exception if the operation failed.               * @throws Exception if the operation failed.
766               */               */
767              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);
# Line 736  namespace LinuxSampler { Line 787  namespace LinuxSampler {
787              void ExecSql(String Sql, String Param);              void ExecSql(String Sql, String Param);
788    
789              /**              /**
790                 * Used to execute SQL commands which return empty result set.
791                 */
792                void ExecSql(String Sql, std::vector<String>& Params);
793    
794                /**
795               * Used to execute SQL commands which returns integer.               * Used to execute SQL commands which returns integer.
796               */               */
797              int ExecSqlInt(String Sql);              int ExecSqlInt(String Sql);
# Line 746  namespace LinuxSampler { Line 802  namespace LinuxSampler {
802              int ExecSqlInt(String Sql, String Param);              int ExecSqlInt(String Sql, String Param);
803    
804              /**              /**
805               * Used to execute SQL commands which returns integer.               * Used to execute SQL commands which returns string.
806               */               */
807              String ExecSqlString(String Sql);              String ExecSqlString(String Sql);
808    
# Line 756  namespace LinuxSampler { Line 812  namespace LinuxSampler {
812              IntListPtr ExecSqlIntList(String Sql);              IntListPtr ExecSqlIntList(String Sql);
813    
814              /**              /**
815                 * Used to execute SQL commands which returns integer list.
816                 */
817                IntListPtr ExecSqlIntList(String Sql, String Param);
818    
819                /**
820                 * Used to execute SQL commands which returns integer list.
821                 */
822                IntListPtr ExecSqlIntList(String Sql, std::vector<String>& Params);
823    
824                /**
825               * Used to execute SQL commands which returns string list.               * Used to execute SQL commands which returns string list.
826               */               */
827              StringListPtr ExecSqlStringList(String Sql);              StringListPtr ExecSqlStringList(String Sql);
# Line 792  namespace LinuxSampler { Line 858  namespace LinuxSampler {
858               */               */
859              static String toAbstractName(String DbName);              static String toAbstractName(String DbName);
860    
861                static String toEscapedFsPath(String FsPath);
862                
863                static String toNonEscapedFsPath(String FsPath);
864    
865              void FireDirectoryCountChanged(String Dir);              void FireDirectoryCountChanged(String Dir);
866              void FireDirectoryInfoChanged(String Dir);              void FireDirectoryInfoChanged(String Dir);
867              void FireDirectoryNameChanged(String Dir, String NewName);              void FireDirectoryNameChanged(String Dir, String NewName);
# Line 839  namespace LinuxSampler { Line 909  namespace LinuxSampler {
909  } // namespace LinuxSampler  } // namespace LinuxSampler
910    
911  #endif // __LS_INSTRUMENTSDB_H__  #endif // __LS_INSTRUMENTSDB_H__
   
 #endif // HAVE_SQLITE3  

Legend:
Removed from v.1345  
changed lines
  Added in v.1727

  ViewVC Help
Powered by ViewVC