/[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 1717 - (hide annotations) (download) (as text)
Sun Mar 16 17:43:20 2008 UTC (16 years, 1 month ago) by iliev
File MIME type: text/x-c++hdr
File size: 41646 byte(s)
* moved all OS dependent file operation to File class

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

  ViewVC Help
Powered by ViewVC