1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2007 - 2009 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 |
#ifndef __LS_INSTRUMENTSDB_H__ |
24 |
#define __LS_INSTRUMENTSDB_H__ |
25 |
|
26 |
#include <sqlite3.h> |
27 |
#if AC_APPLE_UNIVERSAL_BUILD |
28 |
# include <libgig/gig.h> |
29 |
#else |
30 |
# include <gig.h> |
31 |
#endif |
32 |
#include "../common/Mutex.h" |
33 |
#include "../common/WorkerThread.h" |
34 |
#include "../EventListeners.h" |
35 |
#include "InstrumentsDbUtilities.h" |
36 |
|
37 |
namespace LinuxSampler { |
38 |
/** |
39 |
* @brief Provides access to the instruments database. |
40 |
*/ |
41 |
class InstrumentsDb { |
42 |
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 |
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 |
* @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 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
73 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
80 |
* @param NewName The new name of the directory. |
81 |
* All slashes in the name are replaced with '\0'. |
82 |
*/ |
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 |
* @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 |
*/ |
92 |
virtual void InstrumentCountChanged(String Dir) = 0; |
93 |
|
94 |
/** |
95 |
* Invoked when the settings of an instrument are changed. |
96 |
* @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 |
*/ |
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 |
* All slashes in the directory/instrument names are replaced with '\0'. |
106 |
* @param NewName The new name of the directory. |
107 |
* All slashes in the name are replaced with '\0'. |
108 |
*/ |
109 |
virtual void InstrumentNameChanged(String Instr, String NewName) = 0; |
110 |
|
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 |
}; |
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 |
* Creates an instruments database file. |
131 |
* @param FilePath optional pathname of the file to create. |
132 |
* @throws Exception If the creation of the database file failed. |
133 |
*/ |
134 |
void CreateInstrumentsDb(String FilePath = ""); |
135 |
|
136 |
/** |
137 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
154 |
* @param Recursive If true, the number of all directories |
155 |
* in the specified subtree will be returned. |
156 |
* @throws Exception - if database error occurs, or |
157 |
* the specified path name is invalid. |
158 |
* @returns The number of directories in the specified directory. |
159 |
*/ |
160 |
int GetDirectoryCount(String Dir, bool Recursive); |
161 |
|
162 |
/** |
163 |
* Gets the list of directories in the specified directory. |
164 |
* @param Dir The absolute path name of the directory. |
165 |
* All slashes in the directory names should be replaced with '\0'. |
166 |
* @param Recursive If true, all directories |
167 |
* in the specified subtree will be returned. |
168 |
* @throws Exception - if database error occurs, or |
169 |
* the specified path name is invalid. |
170 |
* @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 |
*/ |
174 |
StringListPtr GetDirectories(String Dir, bool Recursive); |
175 |
|
176 |
/** |
177 |
* Adds the specified directory to the database. |
178 |
* @param Dir The absolute path name of the directory to add. |
179 |
* All slashes in the directory names should be replaced with '\0'. |
180 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
189 |
* @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 |
* @param Dir The absolute path name of the directory. |
198 |
* All slashes in the directory names should be replaced with '\0'. |
199 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
207 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
216 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
228 |
* @param Dst The location where the directory will be moved to. |
229 |
* All slashes in the directory names should be replaced with '\0'. |
230 |
* @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 |
* Copies the specified directory into the specified location. |
240 |
* @param Dir The absolute path name of the directory to copy. |
241 |
* All slashes in the directory names should be replaced with '\0'. |
242 |
* @param Dst The location where the directory will be copied to. |
243 |
* All slashes in the directory names should be replaced with '\0'. |
244 |
* @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 |
* Changes the description of the specified directory. |
254 |
* @param Dir The absolute path name of the directory. |
255 |
* All slashes in the directory names should be replaced with '\0'. |
256 |
* @throws Exception - if database error occurs, or if |
257 |
* the specified directory is not found. |
258 |
*/ |
259 |
void SetDirectoryDescription(String Dir, String Desc); |
260 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
266 |
* @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 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
280 |
* @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 |
* @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 |
* @throws Exception if the operation failed. |
295 |
*/ |
296 |
int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground); |
297 |
|
298 |
/** |
299 |
* Adds the instruments in the specified file |
300 |
* to the specified instruments database directory. |
301 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
305 |
* @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 |
* @throws Exception if the operation failed. |
311 |
*/ |
312 |
void AddInstruments(String DbDir, bool insDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL); |
313 |
|
314 |
/** |
315 |
* Adds all supported instruments in the specified file system |
316 |
* 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 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
333 |
* @param FsDir The absolute path name of an existing |
334 |
* directory in the file system. |
335 |
* @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 |
* @param insDir if true a directory is added for each instrument file |
339 |
* -1 otherwise. |
340 |
* @throws Exception if the operation failed. |
341 |
*/ |
342 |
int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground, bool insDir = false); |
343 |
|
344 |
/** |
345 |
* Gets the number of instruments in the specified directory. |
346 |
* @param Dir The absolute path name of the directory. |
347 |
* All slashes in the directory names should be replaced with '\0'. |
348 |
* @param Recursive If true, the number of all instruments |
349 |
* in the specified subtree will be returned. |
350 |
* @throws Exception - if database error occurs, or |
351 |
* the specified path name is invalid. |
352 |
* @returns The number of instruments in the specified directory. |
353 |
*/ |
354 |
int GetInstrumentCount(String Dir, bool Recursive); |
355 |
|
356 |
/** |
357 |
* Gets the list of instruments in the specified directory. |
358 |
* @param Dir The absolute path name of the directory. |
359 |
* All slashes in the directory names should be replaced with '\0'. |
360 |
* @param Recursive If true, all instruments |
361 |
* in the specified subtree will be returned. |
362 |
* @throws Exception - if database error occurs, or |
363 |
* the specified path name is invalid. |
364 |
*/ |
365 |
StringListPtr GetInstruments(String Dir, bool Recursive); |
366 |
|
367 |
/** |
368 |
* Removes the specified instrument from the database. |
369 |
* @param Instr The absolute path name of the instrument to remove. |
370 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
371 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
380 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
389 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
401 |
* @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 |
* Copies the specified instrument into the specified directory. |
411 |
* @param Instr The absolute path name of the instrument to copy. |
412 |
* 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 |
* @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 |
* 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 |
* Finds all instruments that match the search query. |
432 |
* @param Dir The absolute path name of the database |
433 |
* directory to search in. |
434 |
* All slashes in the directory names should be replaced with '\0'. |
435 |
* @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 |
|
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 |
|
450 |
/** |
451 |
* 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 |
* Removes the old instruments datbase and re-creates |
467 |
* the instruments database from scratch. |
468 |
*/ |
469 |
void Format(); |
470 |
|
471 |
/** |
472 |
* All '\0' chars in the string are replaced with "\x2f"; |
473 |
* ', ", \ 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 |
|
484 |
static String toNonEscapedText(String text); |
485 |
|
486 |
JobList Jobs; |
487 |
|
488 |
private: |
489 |
sqlite3* db; |
490 |
String DbFile; |
491 |
static InstrumentsDb instance; |
492 |
Mutex DbInstrumentsMutex; |
493 |
ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners; |
494 |
bool InTransaction; |
495 |
WorkerThread InstrumentsDbThread; |
496 |
|
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 |
* Gets the list of directories in the specified directory. |
526 |
* @param DirId The ID of the directory. |
527 |
* @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 |
* @throws Exception - if database error occurs, or |
531 |
* the specified ID is invalid. |
532 |
*/ |
533 |
StringListPtr GetDirectories(int DirId); |
534 |
|
535 |
/** |
536 |
* Gets the directory ID. |
537 |
* @param Dir The absolute path name of the directory. |
538 |
* All slashes in the directory names should be replaced with '\0'. |
539 |
* @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 |
* All slashes in the directory name should be replaced with '\0'. |
549 |
* @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 |
* 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 |
* 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 |
* 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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
624 |
* @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 |
* All slashes in the instrument name should be replaced with '\0'. |
634 |
* @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 |
* Gets the name of the instrument with the specified ID. |
641 |
* @param InstrId The ID of the instrument, which name should be obtained. |
642 |
* @returns The name of the specified instrument, where all slashes |
643 |
* in the name are replaced with '\0'. |
644 |
* @throws Exception - if database error occurs. |
645 |
*/ |
646 |
String GetInstrumentName(int InstrId); |
647 |
|
648 |
/** |
649 |
* 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 |
* 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 |
* @param InstrName The name of the instrument to copy. |
689 |
* All slashes in the instrument name should be replaced with '\0'. |
690 |
* @param DstDirId The ID of the directory where the |
691 |
* instrument will be copied to. |
692 |
* @param DstDir The name of the directory where the |
693 |
* 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 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
706 |
* @param FsDir The absolute path name of a directory in the file |
707 |
* system. |
708 |
* @param insDir If true a directory will be create for each gig file |
709 |
* @param pProgress The progress used to monitor the scan process. |
710 |
* @throws Exception if the operation failed. |
711 |
*/ |
712 |
void AddInstrumentsNonrecursive(String DbDir, String FsDir, bool insDir = false, ScanProgress* pProgress = NULL); |
713 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
723 |
* @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 |
void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, bool insDir = false, ScanProgress* pProgress = NULL); |
732 |
|
733 |
/** |
734 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
740 |
* @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 |
* @param pProgress The progress used to monitor the scan process. |
745 |
* Specify NULL if you don't want to monitor the scanning process. |
746 |
* @throws Exception if the operation failed. |
747 |
*/ |
748 |
void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL); |
749 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
756 |
* @param FilePath The absolute path name of the instrument file. |
757 |
* @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 |
* @param pProgress The progress used to monitor the scan process. |
761 |
* Specify NULL if you don't want to monitor the scanning process. |
762 |
* @throws Exception if the operation failed. |
763 |
*/ |
764 |
void AddGigInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL); |
765 |
|
766 |
/** |
767 |
* Adds the specified GIG instrument. |
768 |
* @param DbDir The instruments database directory |
769 |
* in which the instrument will be added. |
770 |
* All slashes in the directory names should be replaced with '\0'. |
771 |
* @throws Exception if the operation failed. |
772 |
*/ |
773 |
void AddGigInstrument(sqlite3_stmt* pStmt, String DbDir, int DirId, String File, ::gig::Instrument* pInstrument, int Index); |
774 |
|
775 |
void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler); |
776 |
|
777 |
void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level); |
778 |
|
779 |
/** Locks the DbInstrumentsMutex and starts a transaction. */ |
780 |
void BeginTransaction(); |
781 |
|
782 |
/** Commits the transaction and unocks the DbInstrumentsMutex. */ |
783 |
void EndTransaction(); |
784 |
|
785 |
/** |
786 |
* Used to execute SQL commands which return empty result set. |
787 |
*/ |
788 |
void ExecSql(String Sql); |
789 |
|
790 |
/** |
791 |
* Used to execute SQL commands which return empty result set. |
792 |
*/ |
793 |
void ExecSql(String Sql, String Param); |
794 |
|
795 |
/** |
796 |
* Used to execute SQL commands which return empty result set. |
797 |
*/ |
798 |
void ExecSql(String Sql, std::vector<String>& Params); |
799 |
|
800 |
/** |
801 |
* Used to execute SQL commands which returns integer. |
802 |
*/ |
803 |
int ExecSqlInt(String Sql); |
804 |
|
805 |
/** |
806 |
* Used to execute SQL commands which returns integer. |
807 |
*/ |
808 |
int ExecSqlInt(String Sql, String Param); |
809 |
|
810 |
/** |
811 |
* Used to execute SQL commands which returns string. |
812 |
*/ |
813 |
String ExecSqlString(String Sql); |
814 |
|
815 |
/** |
816 |
* Used to execute SQL commands which returns integer list. |
817 |
*/ |
818 |
IntListPtr ExecSqlIntList(String Sql); |
819 |
|
820 |
/** |
821 |
* Used to execute SQL commands which returns integer list. |
822 |
*/ |
823 |
IntListPtr ExecSqlIntList(String Sql, String Param); |
824 |
|
825 |
/** |
826 |
* Used to execute SQL commands which returns integer list. |
827 |
*/ |
828 |
IntListPtr ExecSqlIntList(String Sql, std::vector<String>& Params); |
829 |
|
830 |
/** |
831 |
* Used to execute SQL commands which returns string list. |
832 |
*/ |
833 |
StringListPtr ExecSqlStringList(String Sql); |
834 |
|
835 |
/** |
836 |
* Binds the specified text parameter. |
837 |
*/ |
838 |
void BindTextParam(sqlite3_stmt* pStmt, int Index, String Text); |
839 |
|
840 |
/** |
841 |
* Binds the specified integer parameter. |
842 |
*/ |
843 |
void BindIntParam(sqlite3_stmt* pStmt, int Index, int Param); |
844 |
|
845 |
/** |
846 |
* Checks whether an instrument or directory with the specified name |
847 |
* already exists in the specified directory and if so a new unique name |
848 |
* is returnded. The new name is generated by adding the suffix |
849 |
* [<nr>] to the end of the name, where <nr> is a number between |
850 |
* 2 and 1000. |
851 |
* throws Exception if cannot find an unique name. This is done |
852 |
* because it is highly unlikely that this can happen, so it is |
853 |
* supposed that this is due to a bug or an infinite loop. |
854 |
*/ |
855 |
String GetUniqueName(int DirId, String Name); |
856 |
|
857 |
/** |
858 |
* Creates a new directory in the specified existing |
859 |
* instruments database directory. The directory name is |
860 |
* the base name of the specified file system path, if there is |
861 |
* no instrument in DbDir directory with that name. Otherwise, |
862 |
* a directory with unique name is created. |
863 |
* @returns The absolute path name of the newly created |
864 |
* instruments database directory. |
865 |
*/ |
866 |
String PrepareSubdirectory(String DbDir, String FsPath); |
867 |
|
868 |
void EnsureDBFileExists(); |
869 |
|
870 |
/** |
871 |
* Adds the specified node to the specified database directory path. |
872 |
* @returns The newly created instruments database path. |
873 |
*/ |
874 |
static String AppendNode(String DbDir, String Node); |
875 |
|
876 |
/** |
877 |
* All '\0' chars in the string are replaced with '/'. |
878 |
*/ |
879 |
static String toDbName(String AbstractName); |
880 |
|
881 |
/** |
882 |
* All slashes are replaced with '\0'. |
883 |
*/ |
884 |
static String toAbstractName(String DbName); |
885 |
|
886 |
static String toEscapedFsPath(String FsPath); |
887 |
|
888 |
static String toNonEscapedFsPath(String FsPath); |
889 |
|
890 |
void FireDirectoryCountChanged(String Dir); |
891 |
void FireDirectoryInfoChanged(String Dir); |
892 |
void FireDirectoryNameChanged(String Dir, String NewName); |
893 |
void FireInstrumentCountChanged(String Dir); |
894 |
void FireInstrumentInfoChanged(String Instr); |
895 |
void FireInstrumentNameChanged(String Instr, String NewName); |
896 |
void FireJobStatusChanged(int JobId); |
897 |
|
898 |
/** |
899 |
* Strips the non-directory suffix from the file name. If the string |
900 |
* ends with `/' only the last character is removed. If the string |
901 |
* doesn't starts with `/' charater, an empty string is returned. |
902 |
*/ |
903 |
static String GetDirectoryPath(String File); |
904 |
|
905 |
/** |
906 |
* Returns the file name extracted from the specified absolute path |
907 |
* name. If the string doesn't starts with `/' or ends with `/', |
908 |
* an empty string is returned. |
909 |
*/ |
910 |
static String GetFileName(String Path); |
911 |
|
912 |
/** |
913 |
* Strips the last directory from the specified path name. If the |
914 |
* string doesn't starts with `/' an empty string is returned. |
915 |
*/ |
916 |
static String GetParentDirectory(String Dir); |
917 |
|
918 |
/** |
919 |
* Checks whether the specified path is valid. |
920 |
* @throws Exception - if the specified path is invalid. |
921 |
*/ |
922 |
static void CheckPathName(String Path); |
923 |
|
924 |
/** |
925 |
* Checks whether the specified file name is valid. |
926 |
* @throws Exception - if the specified file name is invalid. |
927 |
*/ |
928 |
static void CheckFileName(String File); |
929 |
|
930 |
static String GetDefaultDBLocation(); |
931 |
|
932 |
#ifndef WIN32 |
933 |
/** SQLite user function for handling regular expressions */ |
934 |
static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue); |
935 |
#endif |
936 |
}; |
937 |
|
938 |
} // namespace LinuxSampler |
939 |
|
940 |
#endif // __LS_INSTRUMENTSDB_H__ |