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 |
#include <gig.h> |
28 |
#include "../common/Mutex.h" |
29 |
#include "../common/WorkerThread.h" |
30 |
#include "../EventListeners.h" |
31 |
#include "InstrumentsDbUtilities.h" |
32 |
|
33 |
namespace LinuxSampler { |
34 |
/** |
35 |
* @brief Provides access to the instruments database. |
36 |
*/ |
37 |
class InstrumentsDb { |
38 |
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 |
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 |
* @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 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
69 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
76 |
* @param NewName The new name of the directory. |
77 |
* All slashes in the name are replaced with '\0'. |
78 |
*/ |
79 |
virtual void DirectoryNameChanged(String Dir, String NewName) = 0; |
80 |
|
81 |
/** |
82 |
* Invoked when the number of instruments |
83 |
* in a specific directory has changed. |
84 |
* @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 |
*/ |
88 |
virtual void InstrumentCountChanged(String Dir) = 0; |
89 |
|
90 |
/** |
91 |
* Invoked when the settings of an instrument are changed. |
92 |
* @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 |
*/ |
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 |
* All slashes in the directory/instrument names are replaced with '\0'. |
102 |
* @param NewName The new name of the directory. |
103 |
* All slashes in the name are replaced with '\0'. |
104 |
*/ |
105 |
virtual void InstrumentNameChanged(String Instr, String NewName) = 0; |
106 |
|
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 |
}; |
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 |
* Creates an instruments database file. |
127 |
* @param FilePath the pathname of the file to create. |
128 |
* @throws Exception If the creation of the database file failed. |
129 |
*/ |
130 |
static void CreateInstrumentsDb(String FilePath); |
131 |
|
132 |
/** |
133 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
150 |
* @param Recursive If true, the number of all directories |
151 |
* in the specified subtree will be returned. |
152 |
* @throws Exception - if database error occurs, or |
153 |
* the specified path name is invalid. |
154 |
* @returns The number of directories in the specified directory. |
155 |
*/ |
156 |
int GetDirectoryCount(String Dir, bool Recursive); |
157 |
|
158 |
/** |
159 |
* Gets the list of directories in the specified directory. |
160 |
* @param Dir The absolute path name of the directory. |
161 |
* All slashes in the directory names should be replaced with '\0'. |
162 |
* @param Recursive If true, all directories |
163 |
* in the specified subtree will be returned. |
164 |
* @throws Exception - if database error occurs, or |
165 |
* the specified path name is invalid. |
166 |
* @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 |
*/ |
170 |
StringListPtr GetDirectories(String Dir, bool Recursive); |
171 |
|
172 |
/** |
173 |
* Adds the specified directory to the database. |
174 |
* @param Dir The absolute path name of the directory to add. |
175 |
* All slashes in the directory names should be replaced with '\0'. |
176 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
185 |
* @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 |
* @param Dir The absolute path name of the directory. |
194 |
* All slashes in the directory names should be replaced with '\0'. |
195 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
203 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
212 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
224 |
* @param Dst The location where the directory will be moved to. |
225 |
* All slashes in the directory names should be replaced with '\0'. |
226 |
* @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 |
* Copies the specified directory into the specified location. |
236 |
* @param Dir The absolute path name of the directory to copy. |
237 |
* All slashes in the directory names should be replaced with '\0'. |
238 |
* @param Dst The location where the directory will be copied to. |
239 |
* All slashes in the directory names should be replaced with '\0'. |
240 |
* @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 |
* Changes the description of the specified directory. |
250 |
* @param Dir The absolute path name of the directory. |
251 |
* All slashes in the directory names should be replaced with '\0'. |
252 |
* @throws Exception - if database error occurs, or if |
253 |
* the specified directory is not found. |
254 |
*/ |
255 |
void SetDirectoryDescription(String Dir, String Desc); |
256 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
262 |
* @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 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
276 |
* @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 |
* @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 |
* @throws Exception if the operation failed. |
291 |
*/ |
292 |
int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground); |
293 |
|
294 |
/** |
295 |
* Adds the instruments in the specified file |
296 |
* to the specified instruments database directory. |
297 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
301 |
* @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 |
* @throws Exception if the operation failed. |
307 |
*/ |
308 |
void AddInstruments(String DbDir, bool insDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL); |
309 |
|
310 |
/** |
311 |
* Adds all supported instruments in the specified file system |
312 |
* 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 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
329 |
* @param FsDir The absolute path name of an existing |
330 |
* directory in the file system. |
331 |
* @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 |
* @param insDir if true a directory is added for each instrument file |
335 |
* -1 otherwise. |
336 |
* @throws Exception if the operation failed. |
337 |
*/ |
338 |
int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground, bool insDir = false); |
339 |
|
340 |
/** |
341 |
* Gets the number of instruments in the specified directory. |
342 |
* @param Dir The absolute path name of the directory. |
343 |
* All slashes in the directory names should be replaced with '\0'. |
344 |
* @param Recursive If true, the number of all instruments |
345 |
* in the specified subtree will be returned. |
346 |
* @throws Exception - if database error occurs, or |
347 |
* the specified path name is invalid. |
348 |
* @returns The number of instruments in the specified directory. |
349 |
*/ |
350 |
int GetInstrumentCount(String Dir, bool Recursive); |
351 |
|
352 |
/** |
353 |
* Gets the list of instruments in the specified directory. |
354 |
* @param Dir The absolute path name of the directory. |
355 |
* All slashes in the directory names should be replaced with '\0'. |
356 |
* @param Recursive If true, all instruments |
357 |
* in the specified subtree will be returned. |
358 |
* @throws Exception - if database error occurs, or |
359 |
* the specified path name is invalid. |
360 |
*/ |
361 |
StringListPtr GetInstruments(String Dir, bool Recursive); |
362 |
|
363 |
/** |
364 |
* Removes the specified instrument from the database. |
365 |
* @param Instr The absolute path name of the instrument to remove. |
366 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
367 |
* @throws Exception - If the specified instrument does not exist, |
368 |
* or database error occurs. |
369 |
*/ |
370 |
void RemoveInstrument(String Instr); |
371 |
|
372 |
/** |
373 |
* Gets information about the specified instrument. |
374 |
* @param Instr The absolute path name of the instrument. |
375 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
376 |
* @throws Exception - if database error occurs, or if |
377 |
* the specified instrument is not found. |
378 |
*/ |
379 |
DbInstrument GetInstrumentInfo(String Instr); |
380 |
|
381 |
/** |
382 |
* Renames the specified instrument. |
383 |
* @param Instr The absolute path name of the instrument to rename. |
384 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
385 |
* @param Name The new name for the instrument. |
386 |
* @throws Exception - In case the given instrument does not exists, |
387 |
* or the specified name is not a valid name, or if an instrument |
388 |
* with name equal to the new name already exists, or |
389 |
* if database error occurs. |
390 |
*/ |
391 |
void RenameInstrument(String Instr, String Name); |
392 |
|
393 |
/** |
394 |
* Moves the specified instrument into the specified directory. |
395 |
* @param Instr The absolute path name of the instrument to move. |
396 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
397 |
* @param Dst The directory where the instrument will be moved to. |
398 |
* @throws Exception - In case the given directory or instrument |
399 |
* does not exist, or if an instrument with name equal to the name |
400 |
* of the specified instrument already exists in the specified |
401 |
* destination directory, or if database error occurs. |
402 |
*/ |
403 |
void MoveInstrument(String Instr, String Dst); |
404 |
|
405 |
/** |
406 |
* Copies the specified instrument into the specified directory. |
407 |
* @param Instr The absolute path name of the instrument to copy. |
408 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
409 |
* @param Dst The absolute path name of the directory where the |
410 |
* instrument will be copied to. All slashes in the directory names |
411 |
* should be replaced with '\0'. |
412 |
* @throws Exception - In case the given directory or instrument |
413 |
* does not exist, or if an instrument with name equal to the name |
414 |
* of the specified instrument already exists in the specified |
415 |
* destination directory, or if database error occurs. |
416 |
*/ |
417 |
void CopyInstrument(String Instr, String Dst); |
418 |
|
419 |
/** |
420 |
* Changes the description of the specified instrument. |
421 |
* @throws Exception - if database error occurs, or if |
422 |
* the specified instrument is not found. |
423 |
*/ |
424 |
void SetInstrumentDescription(String Instr, String Desc); |
425 |
|
426 |
/** |
427 |
* Finds all instruments that match the search query. |
428 |
* @param Dir The absolute path name of the database |
429 |
* directory to search in. |
430 |
* All slashes in the directory names should be replaced with '\0'. |
431 |
* @throws Exception - if database error occurs, or |
432 |
* if the specified path name is invalid. |
433 |
* @returns The absolute path names of all instruments |
434 |
* that match the search query. |
435 |
*/ |
436 |
StringListPtr FindInstruments(String Dir, SearchQuery* pQuery, bool Recursive); |
437 |
|
438 |
/** |
439 |
* Checks all instrument files in the database and returns a list |
440 |
* of all files that dosn't exist in the filesystem. |
441 |
* @throws Exception - if database error occurs. |
442 |
* @returns The absolute path names of all lost instrument files. |
443 |
*/ |
444 |
StringListPtr FindLostInstrumentFiles(); |
445 |
|
446 |
/** |
447 |
* Substitutes all occurrences of the instrument file |
448 |
* OldPath in the database, with NewPath. |
449 |
* @throws Exception - If error occurs. |
450 |
*/ |
451 |
void SetInstrumentFilePath(String OldPath, String NewPath); |
452 |
|
453 |
/** |
454 |
* Gets a list of all instruments in the instruments database |
455 |
* that are located in the specified instrument file. |
456 |
* @param File The absolute path name of the instrument file. |
457 |
* @throws Exception If database error occurs. |
458 |
*/ |
459 |
StringListPtr GetInstrumentsByFile(String File); |
460 |
|
461 |
/** |
462 |
* Removes the old instruments datbase and re-creates |
463 |
* the instruments database from scratch. |
464 |
*/ |
465 |
void Format(); |
466 |
|
467 |
/** |
468 |
* All '\0' chars in the string are replaced with "\x2f"; |
469 |
* ', ", \ are escaped with backslash and |
470 |
* <CR> and <LF> are replaced with \r and \n. |
471 |
*/ |
472 |
static String toEscapedPath(String AbstractPath); |
473 |
|
474 |
/** |
475 |
* The characters ', ", \ are escaped with backslash and |
476 |
* <CR> and <LF> are replaced with \r and \n. |
477 |
*/ |
478 |
static String toEscapedText(String text); |
479 |
|
480 |
static String toNonEscapedText(String text); |
481 |
|
482 |
JobList Jobs; |
483 |
|
484 |
private: |
485 |
sqlite3* db; |
486 |
String DbFile; |
487 |
static InstrumentsDb instance; |
488 |
Mutex DbInstrumentsMutex; |
489 |
ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners; |
490 |
bool InTransaction; |
491 |
WorkerThread InstrumentsDbThread; |
492 |
|
493 |
InstrumentsDb(); |
494 |
~InstrumentsDb(); |
495 |
|
496 |
/** |
497 |
* Gets the instruments database. If the database is not |
498 |
* opened, a connection to the database is established first. |
499 |
* @returns The instruments database. |
500 |
* @throws Exception if fail to open the database. |
501 |
*/ |
502 |
sqlite3* GetDb(); |
503 |
|
504 |
/** |
505 |
* Gets the number of directories in the directory |
506 |
* with ID DirId. |
507 |
* @returns The number of directories in the specified directory |
508 |
* or -1 if the directory doesn't exist. |
509 |
*/ |
510 |
int GetDirectoryCount(int DirId); |
511 |
|
512 |
/** |
513 |
* Gets a list containing the IDs of all directories in |
514 |
* the specified instrument directory. |
515 |
* @returns The IDs of all directories in the specified directory. |
516 |
* @throws Exception - if database error occurs. |
517 |
*/ |
518 |
IntListPtr GetDirectoryIDs(int DirId); |
519 |
|
520 |
/** |
521 |
* Gets the list of directories in the specified directory. |
522 |
* @param DirId The ID of the directory. |
523 |
* @returns The list of directories, where the directories are |
524 |
* represented in abstract path - all slashes in the directory |
525 |
* names are replaced with '\0'. |
526 |
* @throws Exception - if database error occurs, or |
527 |
* the specified ID is invalid. |
528 |
*/ |
529 |
StringListPtr GetDirectories(int DirId); |
530 |
|
531 |
/** |
532 |
* Gets the directory ID. |
533 |
* @param Dir The absolute path name of the directory. |
534 |
* All slashes in the directory names should be replaced with '\0'. |
535 |
* @returns The directory ID or -1 if the directory is not found. |
536 |
* @throws Exception - if database error occurs. |
537 |
*/ |
538 |
int GetDirectoryId(String Dir); |
539 |
|
540 |
/** |
541 |
* Gets the directory ID. |
542 |
* @param ParentDirId The ID of the parent directory. |
543 |
* @param DirName The directory name. |
544 |
* All slashes in the directory name should be replaced with '\0'. |
545 |
* @throws Exception - if database error occurs. |
546 |
* @returns The ID of the specified directory |
547 |
* or -1 if the directory doesn't exist. |
548 |
*/ |
549 |
int GetDirectoryId(int ParentDirId, String DirName); |
550 |
|
551 |
/** |
552 |
* Gets the ID of the directory, in which the specified instrument is located. |
553 |
* @param InstrId The ID of the instrument. |
554 |
* @returns The directory ID or -1 if the directory is not found. |
555 |
* @throws Exception - if database error occurs. |
556 |
*/ |
557 |
int GetDirectoryId(int InstrId); |
558 |
|
559 |
/** |
560 |
* Gets the name of the specified directory. |
561 |
* @throws Exception - if the directory is not found |
562 |
* or if database error occurs. |
563 |
*/ |
564 |
String GetDirectoryName(int DirId); |
565 |
|
566 |
/** |
567 |
* Gets the ID of the parent directory. |
568 |
* @throws Exception - if the root directory is specified, or if the |
569 |
* specified directory is not found, or if database error occurs. |
570 |
*/ |
571 |
int GetParentDirectoryId(int DirId); |
572 |
|
573 |
/** |
574 |
* Gets the absolute path name of the specified directory. |
575 |
* @param DirId The ID of the directory, which absolute |
576 |
* path name should be returned. |
577 |
* @throws Exception If the specified directory is not |
578 |
* found or if database error occurs. |
579 |
*/ |
580 |
String GetDirectoryPath(int DirId); |
581 |
|
582 |
/** |
583 |
* Removes the specified directory from the database. |
584 |
* @param DirId The ID of the directory to remove. |
585 |
* @throws Exception - If the specified directory is not empty. |
586 |
*/ |
587 |
void RemoveDirectory(int DirId); |
588 |
|
589 |
/** |
590 |
* Removes all directories in the specified directory. |
591 |
* Do NOT call this method before ensuring that all |
592 |
* directories in the specified directory are empty. |
593 |
* @param DirId The ID of the directory. |
594 |
* @throws Exception - if at least one of the directories in the |
595 |
* specified directory is not empty or if database error occurs. |
596 |
* @see IsDirectoryEmpty |
597 |
*/ |
598 |
void RemoveAllDirectories(int DirId); |
599 |
|
600 |
/** |
601 |
* Determines whether the specified directory is empty. |
602 |
* If the directory doesn't exist the return value is false. |
603 |
* @throws Exception - if database error occurs. |
604 |
*/ |
605 |
bool IsDirectoryEmpty(int DirId); |
606 |
|
607 |
/** |
608 |
* Removes the content of the specified directory from the database. |
609 |
* @param DirId The ID of the directory. |
610 |
* @param Level Used to prevent stack overflow, which may occur |
611 |
* due to large or infinite recursive loop. |
612 |
* @throws Exception - If database error occurs. |
613 |
*/ |
614 |
void RemoveDirectoryContent(int DirId, int Level = 0); |
615 |
|
616 |
/** |
617 |
* Gets the ID of the specified database instrument. |
618 |
* @param Instr The absolute path name of the instrument. |
619 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
620 |
* @returns The instrument ID or -1 if the instrument is not found. |
621 |
* @throws Exception - if database error occurs. |
622 |
*/ |
623 |
int GetInstrumentId(String Instr); |
624 |
|
625 |
/** |
626 |
* Gets the ID of the specified database instrument. |
627 |
* @param DirId The ID of the directory containing the instrument. |
628 |
* @param InstrName The name of the instrument. |
629 |
* All slashes in the instrument name should be replaced with '\0'. |
630 |
* @returns The instrument ID or -1 if the instrument is not found. |
631 |
* @throws Exception - if database error occurs. |
632 |
*/ |
633 |
int GetInstrumentId(int DirId, String InstrName); |
634 |
|
635 |
/** |
636 |
* Gets the name of the instrument with the specified ID. |
637 |
* @param InstrId The ID of the instrument, which name should be obtained. |
638 |
* @returns The name of the specified instrument, where all slashes |
639 |
* in the name are replaced with '\0'. |
640 |
* @throws Exception - if database error occurs. |
641 |
*/ |
642 |
String GetInstrumentName(int InstrId); |
643 |
|
644 |
/** |
645 |
* Removes the specified instrument from the database. |
646 |
* @param InstrId The ID of the instrument to remove. |
647 |
* @throws Exception - If the specified instrument does not exist. |
648 |
*/ |
649 |
void RemoveInstrument(int InstrId); |
650 |
|
651 |
/** |
652 |
* Removes all instruments in the specified directory. |
653 |
* @param DirId The ID of the directory. |
654 |
* @throws Exception - if database error occurs. |
655 |
*/ |
656 |
void RemoveAllInstruments(int DirId); |
657 |
|
658 |
/** |
659 |
* Gets the number of instruments in the directory |
660 |
* with ID DirId. |
661 |
* @returns The number of instruments in the specified directory |
662 |
* or -1 if the directory doesn't exist. |
663 |
*/ |
664 |
int GetInstrumentCount(int DirId); |
665 |
|
666 |
/** |
667 |
* Gets a list containing the IDs of all instruments in |
668 |
* the specified instrument directory. |
669 |
* @returns The IDs of all instruments in the specified directory. |
670 |
* @throws Exception - if database error occurs. |
671 |
*/ |
672 |
IntListPtr GetInstrumentIDs(int DirId); |
673 |
|
674 |
/** |
675 |
* Gets information about the specified instrument. |
676 |
* @param InstrId The ID of the instrument. |
677 |
* @throws Exception - if database error occurs. |
678 |
*/ |
679 |
DbInstrument GetInstrumentInfo(int InstrId); |
680 |
|
681 |
/** |
682 |
* Copies the specified instrument into the specified directory. |
683 |
* @param InstrId The ID of the instrument to copy. |
684 |
* @param InstrName The name of the instrument to copy. |
685 |
* All slashes in the instrument name should be replaced with '\0'. |
686 |
* @param DstDirId The ID of the directory where the |
687 |
* instrument will be copied to. |
688 |
* @param DstDir The name of the directory where the |
689 |
* instrument will be copied to. |
690 |
* @throws Exception - If database error occurs. |
691 |
*/ |
692 |
void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir); |
693 |
|
694 |
/** |
695 |
* Adds all supported instruments in the specified directory |
696 |
* to the specified instruments database directory. The |
697 |
* instruments in the subdirectories will not be processed. |
698 |
* @param DbDir The absolute path name of a directory in the |
699 |
* instruments database in which only the new instruments |
700 |
* (that are not already in the database) will be added. |
701 |
* All slashes in the directory names should be replaced with '\0'. |
702 |
* @param FsDir The absolute path name of a directory in the file |
703 |
* system. |
704 |
* @param insDir If true a directory will be create for each gig file |
705 |
* @param pProgress The progress used to monitor the scan process. |
706 |
* @throws Exception if the operation failed. |
707 |
*/ |
708 |
void AddInstrumentsNonrecursive(String DbDir, String FsDir, bool insDir = false, ScanProgress* pProgress = NULL); |
709 |
|
710 |
/** |
711 |
* Adds all supported instruments in the specified file system |
712 |
* direcotry to the specified instruments database directory, |
713 |
* including the instruments in the subdirectories of the |
714 |
* supplied directory. |
715 |
* @param DbDir The absolute path name of a directory in the |
716 |
* instruments database in which only the new instruments |
717 |
* (that are not already in the database) will be added. |
718 |
* All slashes in the directory names should be replaced with '\0'. |
719 |
* @param FsDir The absolute path name of an existing |
720 |
* directory in the file system. |
721 |
* @param Flat If true, the respective subdirectory structure will |
722 |
* not be recreated in the instruments database and all instruments |
723 |
* will be added directly in the specified database directory. |
724 |
* @param pProgress The progress used to monitor the scan process. |
725 |
* @throws Exception if the operation failed. |
726 |
*/ |
727 |
void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, bool insDir = false, ScanProgress* pProgress = NULL); |
728 |
|
729 |
/** |
730 |
* Adds the instruments in the specified file |
731 |
* to the specified instruments database directory. |
732 |
* @param DbDir The absolute path name of a directory in the |
733 |
* instruments database in which only the new instruments |
734 |
* (that are not already in the database) will be added. |
735 |
* All slashes in the directory names should be replaced with '\0'. |
736 |
* @param File The absolute path name of a file in the file system. |
737 |
* @param Index The index of the instrument (in the given |
738 |
* instrument file) to add. If -1 is specified, all instruments in |
739 |
* the supplied instrument file will be added. |
740 |
* @param pProgress The progress used to monitor the scan process. |
741 |
* Specify NULL if you don't want to monitor the scanning process. |
742 |
* @throws Exception if the operation failed. |
743 |
*/ |
744 |
void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL); |
745 |
|
746 |
/** |
747 |
* Adds the specified GIG instrument(s) to the specified location |
748 |
* in the instruments database. |
749 |
* @param DbDir The instruments database directory |
750 |
* in which the instrument will be added. |
751 |
* All slashes in the directory names should be replaced with '\0'. |
752 |
* @param FilePath The absolute path name of the instrument file. |
753 |
* @param Index The index of the instrument (in the given |
754 |
* instrument file) to add. If -1 is specified, all instruments in |
755 |
* the supplied instrument file will be added. |
756 |
* @param pProgress The progress used to monitor the scan process. |
757 |
* Specify NULL if you don't want to monitor the scanning process. |
758 |
* @throws Exception if the operation failed. |
759 |
*/ |
760 |
void AddGigInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL); |
761 |
|
762 |
/** |
763 |
* Adds the specified GIG instrument. |
764 |
* @param DbDir The instruments database directory |
765 |
* in which the instrument will be added. |
766 |
* All slashes in the directory names should be replaced with '\0'. |
767 |
* @throws Exception if the operation failed. |
768 |
*/ |
769 |
void AddGigInstrument(sqlite3_stmt* pStmt, String DbDir, int DirId, String File, ::gig::Instrument* pInstrument, int Index); |
770 |
|
771 |
void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler); |
772 |
|
773 |
void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level); |
774 |
|
775 |
/** Locks the DbInstrumentsMutex and starts a transaction. */ |
776 |
void BeginTransaction(); |
777 |
|
778 |
/** Commits the transaction and unocks the DbInstrumentsMutex. */ |
779 |
void EndTransaction(); |
780 |
|
781 |
/** |
782 |
* Used to execute SQL commands which return empty result set. |
783 |
*/ |
784 |
void ExecSql(String Sql); |
785 |
|
786 |
/** |
787 |
* Used to execute SQL commands which return empty result set. |
788 |
*/ |
789 |
void ExecSql(String Sql, String Param); |
790 |
|
791 |
/** |
792 |
* Used to execute SQL commands which return empty result set. |
793 |
*/ |
794 |
void ExecSql(String Sql, std::vector<String>& Params); |
795 |
|
796 |
/** |
797 |
* Used to execute SQL commands which returns integer. |
798 |
*/ |
799 |
int ExecSqlInt(String Sql); |
800 |
|
801 |
/** |
802 |
* Used to execute SQL commands which returns integer. |
803 |
*/ |
804 |
int ExecSqlInt(String Sql, String Param); |
805 |
|
806 |
/** |
807 |
* Used to execute SQL commands which returns string. |
808 |
*/ |
809 |
String ExecSqlString(String Sql); |
810 |
|
811 |
/** |
812 |
* Used to execute SQL commands which returns integer list. |
813 |
*/ |
814 |
IntListPtr ExecSqlIntList(String Sql); |
815 |
|
816 |
/** |
817 |
* Used to execute SQL commands which returns integer list. |
818 |
*/ |
819 |
IntListPtr ExecSqlIntList(String Sql, String Param); |
820 |
|
821 |
/** |
822 |
* Used to execute SQL commands which returns integer list. |
823 |
*/ |
824 |
IntListPtr ExecSqlIntList(String Sql, std::vector<String>& Params); |
825 |
|
826 |
/** |
827 |
* Used to execute SQL commands which returns string list. |
828 |
*/ |
829 |
StringListPtr ExecSqlStringList(String Sql); |
830 |
|
831 |
/** |
832 |
* Binds the specified text parameter. |
833 |
*/ |
834 |
void BindTextParam(sqlite3_stmt* pStmt, int Index, String Text); |
835 |
|
836 |
/** |
837 |
* Binds the specified integer parameter. |
838 |
*/ |
839 |
void BindIntParam(sqlite3_stmt* pStmt, int Index, int Param); |
840 |
|
841 |
/** |
842 |
* Checks whether an instrument or directory with the specified name |
843 |
* already exists in the specified directory and if so a new unique name |
844 |
* is returnded. The new name is generated by adding the suffix |
845 |
* [<nr>] to the end of the name, where <nr> is a number between |
846 |
* 2 and 1000. |
847 |
* throws Exception if cannot find an unique name. This is done |
848 |
* because it is highly unlikely that this can happen, so it is |
849 |
* supposed that this is due to a bug or an infinite loop. |
850 |
*/ |
851 |
String GetUniqueName(int DirId, String Name); |
852 |
|
853 |
/** |
854 |
* Creates a new directory in the specified existing |
855 |
* instruments database directory. The directory name is |
856 |
* the base name of the specified file system path, if there is |
857 |
* no instrument in DbDir directory with that name. Otherwise, |
858 |
* a directory with unique name is created. |
859 |
* @returns The absolute path name of the newly created |
860 |
* instruments database directory. |
861 |
*/ |
862 |
String PrepareSubdirectory(String DbDir, String FsPath); |
863 |
|
864 |
/** |
865 |
* Adds the specified node to the specified database directory path. |
866 |
* @returns The newly created instruments database path. |
867 |
*/ |
868 |
static String AppendNode(String DbDir, String Node); |
869 |
|
870 |
/** |
871 |
* All '\0' chars in the string are replaced with '/'. |
872 |
*/ |
873 |
static String toDbName(String AbstractName); |
874 |
|
875 |
/** |
876 |
* All slashes are replaced with '\0'. |
877 |
*/ |
878 |
static String toAbstractName(String DbName); |
879 |
|
880 |
static String toEscapedFsPath(String FsPath); |
881 |
|
882 |
static String toNonEscapedFsPath(String FsPath); |
883 |
|
884 |
void FireDirectoryCountChanged(String Dir); |
885 |
void FireDirectoryInfoChanged(String Dir); |
886 |
void FireDirectoryNameChanged(String Dir, String NewName); |
887 |
void FireInstrumentCountChanged(String Dir); |
888 |
void FireInstrumentInfoChanged(String Instr); |
889 |
void FireInstrumentNameChanged(String Instr, String NewName); |
890 |
void FireJobStatusChanged(int JobId); |
891 |
|
892 |
/** |
893 |
* Strips the non-directory suffix from the file name. If the string |
894 |
* ends with `/' only the last character is removed. If the string |
895 |
* doesn't starts with `/' charater, an empty string is returned. |
896 |
*/ |
897 |
static String GetDirectoryPath(String File); |
898 |
|
899 |
/** |
900 |
* Returns the file name extracted from the specified absolute path |
901 |
* name. If the string doesn't starts with `/' or ends with `/', |
902 |
* an empty string is returned. |
903 |
*/ |
904 |
static String GetFileName(String Path); |
905 |
|
906 |
/** |
907 |
* Strips the last directory from the specified path name. If the |
908 |
* string doesn't starts with `/' an empty string is returned. |
909 |
*/ |
910 |
static String GetParentDirectory(String Dir); |
911 |
|
912 |
/** |
913 |
* Checks whether the specified path is valid. |
914 |
* @throws Exception - if the specified path is invalid. |
915 |
*/ |
916 |
static void CheckPathName(String Path); |
917 |
|
918 |
/** |
919 |
* Checks whether the specified file name is valid. |
920 |
* @throws Exception - if the specified file name is invalid. |
921 |
*/ |
922 |
static void CheckFileName(String File); |
923 |
|
924 |
#ifndef WIN32 |
925 |
/** SQLite user function for handling regular expressions */ |
926 |
static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue); |
927 |
#endif |
928 |
}; |
929 |
|
930 |
} // namespace LinuxSampler |
931 |
|
932 |
#endif // __LS_INSTRUMENTSDB_H__ |