/[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 1353 - (hide annotations) (download) (as text)
Mon Sep 17 23:15:25 2007 UTC (16 years, 7 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 41858 byte(s)
* added new LSCP command: FORMAT INSTRUMENTS_DB

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

  ViewVC Help
Powered by ViewVC