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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3092 - (hide annotations) (download) (as text)
Mon Jan 16 22:02:36 2017 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 44459 byte(s)
* Instruments DB: Added support for scanning SFZ (.sfz) files.
* Instruments DB: Added support for scanning Sound Font (.sf2) files.
* Bumped version (2.0.0.svn40).

1 iliev 1161 /***************************************************************************
2     * *
3 persson 1908 * Copyright (C) 2007 - 2009 Grigor Iliev *
4 iliev 1161 * *
5     * 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 *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the Free Software *
17     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
18     * MA 02110-1301 USA *
19     ***************************************************************************/
20    
21     #include "../common/global.h"
22    
23     #ifndef __LS_INSTRUMENTSDB_H__
24     #define __LS_INSTRUMENTSDB_H__
25    
26     #include <sqlite3.h>
27 schoenebeck 3091 #if AC_APPLE_UNIVERSAL_BUILD
28     # include <libgig/gig.h>
29     #else
30     # include <gig.h>
31     #endif
32 iliev 1161 #include "../common/Mutex.h"
33 iliev 1200 #include "../common/WorkerThread.h"
34 iliev 1161 #include "../EventListeners.h"
35 iliev 1200 #include "InstrumentsDbUtilities.h"
36 iliev 1161
37     namespace LinuxSampler {
38     /**
39     * @brief Provides access to the instruments database.
40     */
41     class InstrumentsDb {
42 iliev 1200 friend class DirectoryScanner;
43     friend class DirectoryFinder;
44     friend class InstrumentFinder;
45     friend class DirectoryCounter;
46     friend class InstrumentCounter;
47     friend class DirectoryCopier;
48     friend class AddInstrumentsJob;
49     friend class ScanProgress;
50    
51 iliev 1161 public:
52     /**
53     * This class is used as a listener, which is notified when
54     * changes to the instruments database are made.
55     */
56     class Listener {
57     public:
58     /**
59     * Invoked when the number of instrument directories
60     * in a specific directory has changed.
61 iliev 1350 * @param Dir The absolute pathname of the directory
62     * in which the number of directories is changed.
63     * All slashes in the directory names are replaced with '\0'.
64 iliev 1161 */
65     virtual void DirectoryCountChanged(String Dir) = 0;
66    
67     /**
68     * Invoked when the settings of an instrument directory
69     * are changed.
70     * @param Dir The absolute pathname of the directory
71     * whose settings are changed.
72 iliev 1350 * All slashes in the directory names are replaced with '\0'.
73 iliev 1161 */
74     virtual void DirectoryInfoChanged(String Dir) = 0;
75    
76     /**
77     * Invoked when an instrument directory is renamed.
78     * @param Dir The old absolute pathname of the directory.
79 iliev 1350 * All slashes in the directory names are replaced with '\0'.
80 iliev 1161 * @param NewName The new name of the directory.
81 iliev 1350 * All slashes in the name are replaced with '\0'.
82 iliev 1161 */
83     virtual void DirectoryNameChanged(String Dir, String NewName) = 0;
84    
85     /**
86     * Invoked when the number of instruments
87     * in a specific directory has changed.
88 iliev 1350 * @param Dir The absolute pathname of the directory
89     * in which the number of instruments is changed.
90     * All slashes in the directory names are replaced with '\0'.
91 iliev 1161 */
92     virtual void InstrumentCountChanged(String Dir) = 0;
93    
94     /**
95     * Invoked when the settings of an instrument are changed.
96 iliev 1350 * @param Instr The absolute pathname of the
97     * instrument whose settings are changed.
98     * All slashes in the directory/instrument names are replaced with '\0'.
99 iliev 1161 */
100     virtual void InstrumentInfoChanged(String Instr) = 0;
101    
102     /**
103     * Invoked when an instrument is renamed.
104     * @param Instr The old absolute pathname of the instrument.
105 iliev 1350 * All slashes in the directory/instrument names are replaced with '\0'.
106 iliev 1161 * @param NewName The new name of the directory.
107 iliev 1350 * All slashes in the name are replaced with '\0'.
108 iliev 1161 */
109     virtual void InstrumentNameChanged(String Instr, String NewName) = 0;
110 iliev 1200
111     /**
112     * Invoked when the status of particular job is changed.
113     * @param JobId The ID of the job.
114     */
115     virtual void JobStatusChanged(int JobId) = 0;
116 iliev 1161 };
117    
118     /**
119     * Registers the specified listener to be notified
120     * when changes to the instruments database are made.
121     */
122     void AddInstrumentsDbListener(InstrumentsDb::Listener* l);
123    
124     /**
125     * Removes the specified listener.
126     */
127     void RemoveInstrumentsDbListener(InstrumentsDb::Listener* l);
128    
129     /**
130 iliev 1187 * Creates an instruments database file.
131 schoenebeck 3091 * @param FilePath optional pathname of the file to create.
132 iliev 1187 * @throws Exception If the creation of the database file failed.
133     */
134 schoenebeck 3091 void CreateInstrumentsDb(String FilePath = "");
135 iliev 1187
136     /**
137 iliev 1161 * This method is used to access the instruments database.
138     */
139     static InstrumentsDb* GetInstrumentsDb();
140    
141     /**
142     * Sets the absolute path name of the instruments database file to use.
143     * The instruments database file location should be set before
144     * any attempt to access the database and once set could not be changed.
145     * @throws Exception - if an empty string is provided or if
146     * the method is called more than once.
147     */
148     void SetDbFile(String File);
149    
150     /**
151     * Gets the number of directories in the specified directory.
152     * @param Dir The absolute path name of the directory.
153 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
154 iliev 1187 * @param Recursive If true, the number of all directories
155     * in the specified subtree will be returned.
156 iliev 1161 * @throws Exception - if database error occurs, or
157     * the specified path name is invalid.
158 iliev 1163 * @returns The number of directories in the specified directory.
159 iliev 1161 */
160 iliev 1187 int GetDirectoryCount(String Dir, bool Recursive);
161 iliev 1161
162     /**
163     * Gets the list of directories in the specified directory.
164     * @param Dir The absolute path name of the directory.
165 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
166 iliev 1187 * @param Recursive If true, all directories
167     * in the specified subtree will be returned.
168 iliev 1161 * @throws Exception - if database error occurs, or
169     * the specified path name is invalid.
170 iliev 1345 * @returns The list of directories, where the directories are
171     * represented in abstract path - all slashes in the directory
172     * names are replaced with '\0'.
173 iliev 1161 */
174 iliev 1187 StringListPtr GetDirectories(String Dir, bool Recursive);
175 iliev 1161
176     /**
177     * Adds the specified directory to the database.
178     * @param Dir The absolute path name of the directory to add.
179 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
180 iliev 1161 * @throws Exception - if database error occurs, or the
181     * specified path is invalid.
182     */
183     void AddDirectory(String Dir);
184    
185     /**
186     * Removes the specified directory from the database.
187     * @param Dir The absolute path name of the directory to remove.
188 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
189 iliev 1161 * @throws Exception - If the specified path is invalid, or
190     * Force is false and the specified directory is
191     * not empty, or if database error occurs.
192     */
193     void RemoveDirectory(String Dir, bool Force = false);
194    
195     /**
196     * Determines whether the specified directory exists in the database.
197 iliev 1345 * @param Dir The absolute path name of the directory.
198     * All slashes in the directory names should be replaced with '\0'.
199 iliev 1161 * @throws Exception - If database error occurs.
200     */
201     bool DirectoryExist(String Dir);
202    
203     /**
204     * Gets information about the specified directory.
205     * @param Dir The absolute path name of the directory.
206 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
207 iliev 1161 * @throws Exception - if database error occurs, or if
208     * the specified directory is not found.
209     */
210     DbDirectory GetDirectoryInfo(String Dir);
211    
212     /**
213     * Renames the specified directory.
214     * @param Dir The absolute path name of the directory to rename.
215 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
216 iliev 1161 * @param Name The new name for the directory.
217     * @throws Exception - In case the given directory does not exists,
218     * or the specified name is not a valid name,
219     * or if a directory with name equal to the new name already
220     * exists, or if database error occurs.
221     */
222     void RenameDirectory(String Dir, String Name);
223    
224     /**
225     * Moves the specified directory into the specified location.
226     * @param Dir The absolute path name of the directory to move.
227 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
228 iliev 1161 * @param Dst The location where the directory will be moved to.
229 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
230 iliev 1161 * @throws Exception - In case a given directory does not exists,
231     * or if a directory with name equal to the directory name already
232     * exists in the specified destination directory, or if database error
233     * occurs. Error is also thrown when trying to move a directory to a
234     * subdirectory of itself.
235     */
236     void MoveDirectory(String Dir, String Dst);
237    
238     /**
239 iliev 1187 * Copies the specified directory into the specified location.
240     * @param Dir The absolute path name of the directory to copy.
241 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
242 iliev 1187 * @param Dst The location where the directory will be copied to.
243 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
244 iliev 1187 * @throws Exception - In case a given directory does not exists,
245     * or if a directory with name equal to the directory name already
246     * exists in the specified destination directory, or if database error
247     * occurs. Error is also thrown when trying to copy a directory to a
248     * subdirectory of itself.
249     */
250     void CopyDirectory(String Dir, String Dst);
251    
252     /**
253 iliev 1161 * Changes the description of the specified directory.
254 iliev 1345 * @param Dir The absolute path name of the directory.
255     * All slashes in the directory names should be replaced with '\0'.
256 iliev 1161 * @throws Exception - if database error occurs, or if
257     * the specified directory is not found.
258     */
259     void SetDirectoryDescription(String Dir, String Desc);
260 iliev 1187
261     /**
262     * Finds all directories that match the search query.
263     * @param Dir The absolute path name of the database
264     * directory to search in.
265 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
266 iliev 1187 * @throws Exception - if database error occurs, or
267     * if the specified path name is invalid.
268     * @returns The absolute path names of all directories
269     * that match the search query.
270     */
271     StringListPtr FindDirectories(String Dir, SearchQuery* pQuery, bool Recursive);
272 iliev 1161
273     /**
274     * Adds the instruments in the specified file or
275     * directory to the specified instruments database directory.
276     * @param DbDir The absolute path name of a directory in the
277     * instruments database in which only the new instruments
278     * (that are not already in the database) will be added.
279 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
280 iliev 1161 * @param FilePath The absolute path name of a file or
281     * directory in the file system. In case a directory is
282     * supplied, all supported instruments in the specified directory
283     * will be added to the instruments database, including the
284     * instruments in the subdirectories. The respective subdirectory
285     * structure will be recreated in the supplied database directory.
286     * @param Index The index of the instrument (in the given
287     * instrument file) to add. If -1 is specified, all instruments in
288     * the supplied instrument file will be added. Error is thrown if
289     * a directory is supplied and Index is not equal to -1.
290 iliev 1200 * @param bBackground Determines whether
291     * the task should be done in the background.
292     * @returns If bBackground is true, the ID of the scan job;
293     * -1 otherwise.
294 iliev 1161 * @throws Exception if the operation failed.
295     */
296 iliev 1200 int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground);
297 iliev 1161
298     /**
299 iliev 1200 * Adds the instruments in the specified file
300     * to the specified instruments database directory.
301 iliev 1161 * @param DbDir The absolute path name of a directory in the
302     * instruments database in which only the new instruments
303     * (that are not already in the database) will be added.
304 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
305 iliev 1200 * @param FilePath The absolute path name of the instrument file.
306     * @param Index The index of the instrument (in the given
307     * instrument file) to add. If -1 is specified, all instruments in
308     * the supplied instrument file will be added.
309     * @param pProgress The progress used to monitor the scan process.
310 iliev 1161 * @throws Exception if the operation failed.
311     */
312 iliev 1781 void AddInstruments(String DbDir, bool insDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL);
313 iliev 1161
314     /**
315     * Adds all supported instruments in the specified file system
316 iliev 1200 * direcotry to the specified instruments database directory.
317     * @param Mode Determines the scanning mode. If RECURSIVE is
318     * specified, all supported instruments in the specified file system
319     * direcotry will be added to the specified instruments database
320     * directory, including the instruments in subdirectories
321     * of the supplied directory. If NON_RECURSIVE is specified,
322     * the instruments in the subdirectories will not be processed.
323     * If FLAT is specified, all supported instruments in the specified
324     * file system direcotry will be added, including the instruments in
325     * subdirectories of the supplied directory, but the respective
326     * subdirectory structure will not be recreated in the instruments
327     * database and all instruments will be added directly in the
328     * specified database directory.
329 iliev 1161 * @param DbDir The absolute path name of a directory in the
330     * instruments database in which only the new instruments
331     * (that are not already in the database) will be added.
332 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
333 iliev 1161 * @param FsDir The absolute path name of an existing
334     * directory in the file system.
335 iliev 1200 * @param bBackground Determines whether
336     * the task should be done in the background.
337     * @returns If bBackground is true, the ID of the scan job;
338 iliev 1781 * @param insDir if true a directory is added for each instrument file
339 iliev 1200 * -1 otherwise.
340 iliev 1161 * @throws Exception if the operation failed.
341     */
342 iliev 1781 int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground, bool insDir = false);
343 iliev 1161
344     /**
345     * Gets the number of instruments in the specified directory.
346     * @param Dir The absolute path name of the directory.
347 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
348 iliev 1187 * @param Recursive If true, the number of all instruments
349     * in the specified subtree will be returned.
350 iliev 1161 * @throws Exception - if database error occurs, or
351     * the specified path name is invalid.
352 iliev 1163 * @returns The number of instruments in the specified directory.
353 iliev 1161 */
354 iliev 1187 int GetInstrumentCount(String Dir, bool Recursive);
355 iliev 1161
356     /**
357     * Gets the list of instruments in the specified directory.
358     * @param Dir The absolute path name of the directory.
359 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
360 iliev 1187 * @param Recursive If true, all instruments
361     * in the specified subtree will be returned.
362 iliev 1161 * @throws Exception - if database error occurs, or
363     * the specified path name is invalid.
364     */
365 iliev 1187 StringListPtr GetInstruments(String Dir, bool Recursive);
366 iliev 1161
367     /**
368     * Removes the specified instrument from the database.
369     * @param Instr The absolute path name of the instrument to remove.
370 iliev 1350 * All slashes in the directory/instrument names should be replaced with '\0'.
371 iliev 1161 * @throws Exception - If the specified instrument does not exist,
372     * or database error occurs.
373     */
374     void RemoveInstrument(String Instr);
375    
376     /**
377     * Gets information about the specified instrument.
378     * @param Instr The absolute path name of the instrument.
379 iliev 1350 * All slashes in the directory/instrument names should be replaced with '\0'.
380 iliev 1161 * @throws Exception - if database error occurs, or if
381     * the specified instrument is not found.
382     */
383     DbInstrument GetInstrumentInfo(String Instr);
384    
385     /**
386     * Renames the specified instrument.
387     * @param Instr The absolute path name of the instrument to rename.
388 iliev 1350 * All slashes in the directory/instrument names should be replaced with '\0'.
389 iliev 1161 * @param Name The new name for the instrument.
390     * @throws Exception - In case the given instrument does not exists,
391     * or the specified name is not a valid name, or if an instrument
392     * with name equal to the new name already exists, or
393     * if database error occurs.
394     */
395     void RenameInstrument(String Instr, String Name);
396    
397     /**
398     * Moves the specified instrument into the specified directory.
399     * @param Instr The absolute path name of the instrument to move.
400 iliev 1350 * All slashes in the directory/instrument names should be replaced with '\0'.
401 iliev 1161 * @param Dst The directory where the instrument will be moved to.
402     * @throws Exception - In case the given directory or instrument
403     * does not exist, or if an instrument with name equal to the name
404     * of the specified instrument already exists in the specified
405     * destination directory, or if database error occurs.
406     */
407     void MoveInstrument(String Instr, String Dst);
408    
409     /**
410 iliev 1187 * Copies the specified instrument into the specified directory.
411     * @param Instr The absolute path name of the instrument to copy.
412 iliev 1345 * All slashes in the directory/instrument names should be replaced with '\0'.
413     * @param Dst The absolute path name of the directory where the
414     * instrument will be copied to. All slashes in the directory names
415     * should be replaced with '\0'.
416 iliev 1187 * @throws Exception - In case the given directory or instrument
417     * does not exist, or if an instrument with name equal to the name
418     * of the specified instrument already exists in the specified
419     * destination directory, or if database error occurs.
420     */
421     void CopyInstrument(String Instr, String Dst);
422    
423     /**
424 iliev 1161 * Changes the description of the specified instrument.
425     * @throws Exception - if database error occurs, or if
426     * the specified instrument is not found.
427     */
428     void SetInstrumentDescription(String Instr, String Desc);
429    
430     /**
431 iliev 1187 * Finds all instruments that match the search query.
432     * @param Dir The absolute path name of the database
433     * directory to search in.
434 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
435 iliev 1187 * @throws Exception - if database error occurs, or
436     * if the specified path name is invalid.
437     * @returns The absolute path names of all instruments
438     * that match the search query.
439     */
440     StringListPtr FindInstruments(String Dir, SearchQuery* pQuery, bool Recursive);
441 iliev 1727
442     /**
443     * Checks all instrument files in the database and returns a list
444     * of all files that dosn't exist in the filesystem.
445     * @throws Exception - if database error occurs.
446     * @returns The absolute path names of all lost instrument files.
447     */
448     StringListPtr FindLostInstrumentFiles();
449 iliev 1345
450     /**
451 iliev 1727 * Substitutes all occurrences of the instrument file
452     * OldPath in the database, with NewPath.
453     * @throws Exception - If error occurs.
454     */
455     void SetInstrumentFilePath(String OldPath, String NewPath);
456    
457     /**
458     * Gets a list of all instruments in the instruments database
459     * that are located in the specified instrument file.
460     * @param File The absolute path name of the instrument file.
461     * @throws Exception If database error occurs.
462     */
463     StringListPtr GetInstrumentsByFile(String File);
464    
465     /**
466 iliev 1353 * Removes the old instruments datbase and re-creates
467     * the instruments database from scratch.
468     */
469     void Format();
470    
471     /**
472 iliev 1350 * All '\0' chars in the string are replaced with "\x2f";
473 iliev 1345 * ', ", \ are escaped with backslash and
474     * <CR> and <LF> are replaced with \r and \n.
475     */
476     static String toEscapedPath(String AbstractPath);
477    
478     /**
479     * The characters ', ", \ are escaped with backslash and
480     * <CR> and <LF> are replaced with \r and \n.
481     */
482     static String toEscapedText(String text);
483 iliev 1727
484     static String toNonEscapedText(String text);
485 iliev 1187
486 iliev 1200 JobList Jobs;
487 iliev 1187
488     private:
489 iliev 1161 sqlite3* db;
490     String DbFile;
491 persson 1644 static InstrumentsDb instance;
492 iliev 1161 Mutex DbInstrumentsMutex;
493     ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
494 iliev 1187 bool InTransaction;
495 iliev 1200 WorkerThread InstrumentsDbThread;
496 iliev 1161
497     InstrumentsDb();
498     ~InstrumentsDb();
499    
500     /**
501     * Gets the instruments database. If the database is not
502     * opened, a connection to the database is established first.
503     * @returns The instruments database.
504     * @throws Exception if fail to open the database.
505     */
506     sqlite3* GetDb();
507    
508     /**
509     * Gets the number of directories in the directory
510     * with ID DirId.
511     * @returns The number of directories in the specified directory
512     * or -1 if the directory doesn't exist.
513     */
514     int GetDirectoryCount(int DirId);
515    
516     /**
517     * Gets a list containing the IDs of all directories in
518     * the specified instrument directory.
519     * @returns The IDs of all directories in the specified directory.
520     * @throws Exception - if database error occurs.
521     */
522     IntListPtr GetDirectoryIDs(int DirId);
523    
524     /**
525 iliev 1187 * Gets the list of directories in the specified directory.
526     * @param DirId The ID of the directory.
527 iliev 1345 * @returns The list of directories, where the directories are
528     * represented in abstract path - all slashes in the directory
529     * names are replaced with '\0'.
530 iliev 1187 * @throws Exception - if database error occurs, or
531     * the specified ID is invalid.
532     */
533     StringListPtr GetDirectories(int DirId);
534    
535     /**
536 iliev 1161 * Gets the directory ID.
537     * @param Dir The absolute path name of the directory.
538 iliev 1345 * All slashes in the directory names should be replaced with '\0'.
539 iliev 1161 * @returns The directory ID or -1 if the directory is not found.
540     * @throws Exception - if database error occurs.
541     */
542     int GetDirectoryId(String Dir);
543    
544     /**
545     * Gets the directory ID.
546     * @param ParentDirId The ID of the parent directory.
547     * @param DirName The directory name.
548 iliev 1345 * All slashes in the directory name should be replaced with '\0'.
549 iliev 1161 * @throws Exception - if database error occurs.
550     * @returns The ID of the specified directory
551     * or -1 if the directory doesn't exist.
552     */
553     int GetDirectoryId(int ParentDirId, String DirName);
554    
555     /**
556 iliev 1727 * Gets the ID of the directory, in which the specified instrument is located.
557     * @param InstrId The ID of the instrument.
558     * @returns The directory ID or -1 if the directory is not found.
559     * @throws Exception - if database error occurs.
560     */
561     int GetDirectoryId(int InstrId);
562    
563     /**
564 iliev 1187 * Gets the name of the specified directory.
565     * @throws Exception - if the directory is not found
566     * or if database error occurs.
567     */
568     String GetDirectoryName(int DirId);
569    
570     /**
571     * Gets the ID of the parent directory.
572     * @throws Exception - if the root directory is specified, or if the
573     * specified directory is not found, or if database error occurs.
574     */
575     int GetParentDirectoryId(int DirId);
576    
577     /**
578     * Gets the absolute path name of the specified directory.
579     * @param DirId The ID of the directory, which absolute
580     * path name should be returned.
581     * @throws Exception If the specified directory is not
582     * found or if database error occurs.
583     */
584     String GetDirectoryPath(int DirId);
585    
586     /**
587 iliev 1161 * Removes the specified directory from the database.
588     * @param DirId The ID of the directory to remove.
589     * @throws Exception - If the specified directory is not empty.
590     */
591     void RemoveDirectory(int DirId);
592    
593     /**
594     * Removes all directories in the specified directory.
595     * Do NOT call this method before ensuring that all
596     * directories in the specified directory are empty.
597     * @param DirId The ID of the directory.
598     * @throws Exception - if at least one of the directories in the
599     * specified directory is not empty or if database error occurs.
600     * @see IsDirectoryEmpty
601     */
602     void RemoveAllDirectories(int DirId);
603    
604     /**
605     * Determines whether the specified directory is empty.
606     * If the directory doesn't exist the return value is false.
607     * @throws Exception - if database error occurs.
608     */
609     bool IsDirectoryEmpty(int DirId);
610    
611     /**
612     * Removes the content of the specified directory from the database.
613     * @param DirId The ID of the directory.
614     * @param Level Used to prevent stack overflow, which may occur
615     * due to large or infinite recursive loop.
616     * @throws Exception - If database error occurs.
617     */
618     void RemoveDirectoryContent(int DirId, int Level = 0);
619    
620     /**
621     * Gets the ID of the specified database instrument.
622     * @param Instr The absolute path name of the instrument.
623 iliev 1345 * All slashes in the directory/instrument names should be replaced with '\0'.
624 iliev 1161 * @returns The instrument ID or -1 if the instrument is not found.
625     * @throws Exception - if database error occurs.
626     */
627     int GetInstrumentId(String Instr);
628    
629     /**
630     * Gets the ID of the specified database instrument.
631     * @param DirId The ID of the directory containing the instrument.
632     * @param InstrName The name of the instrument.
633 iliev 1345 * All slashes in the instrument name should be replaced with '\0'.
634 iliev 1161 * @returns The instrument ID or -1 if the instrument is not found.
635     * @throws Exception - if database error occurs.
636     */
637     int GetInstrumentId(int DirId, String InstrName);
638    
639     /**
640 iliev 1187 * Gets the name of the instrument with the specified ID.
641     * @param InstrId The ID of the instrument, which name should be obtained.
642 iliev 1345 * @returns The name of the specified instrument, where all slashes
643     * in the name are replaced with '\0'.
644 iliev 1187 * @throws Exception - if database error occurs.
645     */
646     String GetInstrumentName(int InstrId);
647    
648     /**
649 iliev 1161 * Removes the specified instrument from the database.
650     * @param InstrId The ID of the instrument to remove.
651     * @throws Exception - If the specified instrument does not exist.
652     */
653     void RemoveInstrument(int InstrId);
654    
655     /**
656     * Removes all instruments in the specified directory.
657     * @param DirId The ID of the directory.
658     * @throws Exception - if database error occurs.
659     */
660     void RemoveAllInstruments(int DirId);
661    
662     /**
663     * Gets the number of instruments in the directory
664     * with ID DirId.
665     * @returns The number of instruments in the specified directory
666     * or -1 if the directory doesn't exist.
667     */
668     int GetInstrumentCount(int DirId);
669    
670     /**
671     * Gets a list containing the IDs of all instruments in
672     * the specified instrument directory.
673     * @returns The IDs of all instruments in the specified directory.
674     * @throws Exception - if database error occurs.
675     */
676     IntListPtr GetInstrumentIDs(int DirId);
677    
678     /**
679 iliev 1187 * Gets information about the specified instrument.
680     * @param InstrId The ID of the instrument.
681     * @throws Exception - if database error occurs.
682     */
683     DbInstrument GetInstrumentInfo(int InstrId);
684    
685     /**
686     * Copies the specified instrument into the specified directory.
687     * @param InstrId The ID of the instrument to copy.
688 iliev 1345 * @param InstrName The name of the instrument to copy.
689 iliev 1350 * All slashes in the instrument name should be replaced with '\0'.
690 iliev 1187 * @param DstDirId The ID of the directory where the
691     * instrument will be copied to.
692 iliev 1345 * @param DstDir The name of the directory where the
693 iliev 1187 * instrument will be copied to.
694     * @throws Exception - If database error occurs.
695     */
696     void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);
697    
698     /**
699 iliev 1200 * Adds all supported instruments in the specified directory
700     * to the specified instruments database directory. The
701     * instruments in the subdirectories will not be processed.
702     * @param DbDir The absolute path name of a directory in the
703     * instruments database in which only the new instruments
704     * (that are not already in the database) will be added.
705 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
706 iliev 1200 * @param FsDir The absolute path name of a directory in the file
707     * system.
708 iliev 1781 * @param insDir If true a directory will be create for each gig file
709 iliev 1200 * @param pProgress The progress used to monitor the scan process.
710     * @throws Exception if the operation failed.
711     */
712 iliev 1781 void AddInstrumentsNonrecursive(String DbDir, String FsDir, bool insDir = false, ScanProgress* pProgress = NULL);
713 iliev 1200
714     /**
715     * Adds all supported instruments in the specified file system
716     * direcotry to the specified instruments database directory,
717     * including the instruments in the subdirectories of the
718     * supplied directory.
719     * @param DbDir The absolute path name of a directory in the
720     * instruments database in which only the new instruments
721     * (that are not already in the database) will be added.
722 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
723 iliev 1200 * @param FsDir The absolute path name of an existing
724     * directory in the file system.
725     * @param Flat If true, the respective subdirectory structure will
726     * not be recreated in the instruments database and all instruments
727     * will be added directly in the specified database directory.
728     * @param pProgress The progress used to monitor the scan process.
729     * @throws Exception if the operation failed.
730     */
731 iliev 1781 void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, bool insDir = false, ScanProgress* pProgress = NULL);
732 iliev 1200
733     /**
734 iliev 1161 * Adds the instruments in the specified file
735     * to the specified instruments database directory.
736     * @param DbDir The absolute path name of a directory in the
737     * instruments database in which only the new instruments
738     * (that are not already in the database) will be added.
739 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
740 iliev 1161 * @param File The absolute path name of a file in the file system.
741     * @param Index The index of the instrument (in the given
742     * instrument file) to add. If -1 is specified, all instruments in
743     * the supplied instrument file will be added.
744 iliev 1200 * @param pProgress The progress used to monitor the scan process.
745     * Specify NULL if you don't want to monitor the scanning process.
746 iliev 1161 * @throws Exception if the operation failed.
747     */
748 iliev 1200 void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
749 iliev 1161
750     /**
751     * Adds the specified GIG instrument(s) to the specified location
752     * in the instruments database.
753     * @param DbDir The instruments database directory
754     * in which the instrument will be added.
755 iliev 1350 * All slashes in the directory names should be replaced with '\0'.
756 iliev 1717 * @param FilePath The absolute path name of the instrument file.
757 iliev 1161 * @param Index The index of the instrument (in the given
758     * instrument file) to add. If -1 is specified, all instruments in
759     * the supplied instrument file will be added.
760 iliev 1200 * @param pProgress The progress used to monitor the scan process.
761     * Specify NULL if you don't want to monitor the scanning process.
762 iliev 1161 * @throws Exception if the operation failed.
763     */
764 schoenebeck 3092 void AddInstrumentsFromFilePriv(String DbDir, const int dirId, String FilePath, File file, int Index = -1, ScanProgress* pProgress = NULL);
765 iliev 1161
766 iliev 1345 void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler);
767 iliev 1161
768 iliev 1345 void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level);
769 iliev 1187
770     /** Locks the DbInstrumentsMutex and starts a transaction. */
771     void BeginTransaction();
772    
773     /** Commits the transaction and unocks the DbInstrumentsMutex. */
774     void EndTransaction();
775    
776 iliev 1161 /**
777     * Used to execute SQL commands which return empty result set.
778     */
779     void ExecSql(String Sql);
780    
781     /**
782     * Used to execute SQL commands which return empty result set.
783     */
784     void ExecSql(String Sql, String Param);
785    
786     /**
787 iliev 1727 * Used to execute SQL commands which return empty result set.
788     */
789     void ExecSql(String Sql, std::vector<String>& Params);
790    
791     /**
792 iliev 1161 * Used to execute SQL commands which returns integer.
793     */
794     int ExecSqlInt(String Sql);
795    
796     /**
797     * Used to execute SQL commands which returns integer.
798     */
799     int ExecSqlInt(String Sql, String Param);
800    
801     /**
802 iliev 1727 * Used to execute SQL commands which returns string.
803 iliev 1161 */
804     String ExecSqlString(String Sql);
805    
806     /**
807     * Used to execute SQL commands which returns integer list.
808     */
809     IntListPtr ExecSqlIntList(String Sql);
810    
811     /**
812 iliev 1727 * Used to execute SQL commands which returns integer list.
813     */
814     IntListPtr ExecSqlIntList(String Sql, String Param);
815    
816     /**
817     * Used to execute SQL commands which returns integer list.
818     */
819     IntListPtr ExecSqlIntList(String Sql, std::vector<String>& Params);
820    
821     /**
822 iliev 1161 * Used to execute SQL commands which returns string list.
823     */
824     StringListPtr ExecSqlStringList(String Sql);
825    
826     /**
827     * Binds the specified text parameter.
828     */
829     void BindTextParam(sqlite3_stmt* pStmt, int Index, String Text);
830    
831     /**
832     * Binds the specified integer parameter.
833     */
834     void BindIntParam(sqlite3_stmt* pStmt, int Index, int Param);
835    
836     /**
837 iliev 1782 * Checks whether an instrument or directory with the specified name
838     * already exists in the specified directory and if so a new unique name
839 iliev 1161 * is returnded. The new name is generated by adding the suffix
840 iliev 1782 * [<nr>] to the end of the name, where <nr> is a number between
841 iliev 1161 * 2 and 1000.
842     * throws Exception if cannot find an unique name. This is done
843     * because it is highly unlikely that this can happen, so it is
844     * supposed that this is due to a bug or an infinite loop.
845     */
846 iliev 1782 String GetUniqueName(int DirId, String Name);
847 iliev 1161
848 iliev 1345 /**
849 iliev 1782 * Creates a new directory in the specified existing
850     * instruments database directory. The directory name is
851     * the base name of the specified file system path, if there is
852     * no instrument in DbDir directory with that name. Otherwise,
853     * a directory with unique name is created.
854     * @returns The absolute path name of the newly created
855     * instruments database directory.
856     */
857     String PrepareSubdirectory(String DbDir, String FsPath);
858    
859 schoenebeck 3091 void EnsureDBFileExists();
860    
861 iliev 1782 /**
862     * Adds the specified node to the specified database directory path.
863     * @returns The newly created instruments database path.
864     */
865     static String AppendNode(String DbDir, String Node);
866    
867     /**
868 iliev 1345 * All '\0' chars in the string are replaced with '/'.
869     */
870     static String toDbName(String AbstractName);
871    
872     /**
873     * All slashes are replaced with '\0'.
874     */
875     static String toAbstractName(String DbName);
876    
877 iliev 1350 static String toEscapedFsPath(String FsPath);
878 iliev 1727
879     static String toNonEscapedFsPath(String FsPath);
880 iliev 1350
881 iliev 1161 void FireDirectoryCountChanged(String Dir);
882     void FireDirectoryInfoChanged(String Dir);
883     void FireDirectoryNameChanged(String Dir, String NewName);
884     void FireInstrumentCountChanged(String Dir);
885     void FireInstrumentInfoChanged(String Instr);
886     void FireInstrumentNameChanged(String Instr, String NewName);
887 iliev 1200 void FireJobStatusChanged(int JobId);
888 iliev 1161
889     /**
890     * Strips the non-directory suffix from the file name. If the string
891     * ends with `/' only the last character is removed. If the string
892     * doesn't starts with `/' charater, an empty string is returned.
893     */
894     static String GetDirectoryPath(String File);
895    
896     /**
897     * Returns the file name extracted from the specified absolute path
898     * name. If the string doesn't starts with `/' or ends with `/',
899     * an empty string is returned.
900     */
901     static String GetFileName(String Path);
902    
903     /**
904     * Strips the last directory from the specified path name. If the
905     * string doesn't starts with `/' an empty string is returned.
906     */
907     static String GetParentDirectory(String Dir);
908    
909     /**
910     * Checks whether the specified path is valid.
911     * @throws Exception - if the specified path is invalid.
912     */
913     static void CheckPathName(String Path);
914    
915     /**
916     * Checks whether the specified file name is valid.
917     * @throws Exception - if the specified file name is invalid.
918     */
919     static void CheckFileName(String File);
920 persson 1908
921 schoenebeck 3091 static String GetDefaultDBLocation();
922    
923 persson 1908 #ifndef WIN32
924 iliev 1187 /** SQLite user function for handling regular expressions */
925     static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);
926 persson 1908 #endif
927 iliev 1161 };
928    
929     } // namespace LinuxSampler
930    
931     #endif // __LS_INSTRUMENTSDB_H__

  ViewVC Help
Powered by ViewVC