1 |
/*************************************************************************** |
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 |
#include "../common/WorkerThread.h" |
32 |
#include "../EventListeners.h" |
33 |
#include "InstrumentsDbUtilities.h" |
34 |
|
35 |
namespace LinuxSampler { |
36 |
/** |
37 |
* @brief Provides access to the instruments database. |
38 |
*/ |
39 |
class InstrumentsDb { |
40 |
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 |
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 |
* @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 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
71 |
*/ |
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 |
* All slashes in the directory names are replaced with '\0'. |
78 |
* @param NewName The new name of the directory. |
79 |
* All slashes in the name are replaced with '\0'. |
80 |
*/ |
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 |
* @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 |
*/ |
90 |
virtual void InstrumentCountChanged(String Dir) = 0; |
91 |
|
92 |
/** |
93 |
* Invoked when the settings of an instrument are changed. |
94 |
* @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 |
*/ |
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 |
* All slashes in the directory/instrument names are replaced with '\0'. |
104 |
* @param NewName The new name of the directory. |
105 |
* All slashes in the name are replaced with '\0'. |
106 |
*/ |
107 |
virtual void InstrumentNameChanged(String Instr, String NewName) = 0; |
108 |
|
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 |
}; |
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 |
* 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 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
152 |
* @param Recursive If true, the number of all directories |
153 |
* in the specified subtree will be returned. |
154 |
* @throws Exception - if database error occurs, or |
155 |
* the specified path name is invalid. |
156 |
* @returns The number of directories in the specified directory. |
157 |
*/ |
158 |
int GetDirectoryCount(String Dir, bool Recursive); |
159 |
|
160 |
/** |
161 |
* Gets the list of directories in the specified directory. |
162 |
* @param Dir The absolute path name of the directory. |
163 |
* All slashes in the directory names should be replaced with '\0'. |
164 |
* @param Recursive If true, all directories |
165 |
* in the specified subtree will be returned. |
166 |
* @throws Exception - if database error occurs, or |
167 |
* the specified path name is invalid. |
168 |
* @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 |
*/ |
172 |
StringListPtr GetDirectories(String Dir, bool Recursive); |
173 |
|
174 |
/** |
175 |
* Adds the specified directory to the database. |
176 |
* @param Dir The absolute path name of the directory to add. |
177 |
* All slashes in the directory names should be replaced with '\0'. |
178 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
187 |
* @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 |
* @param Dir The absolute path name of the directory. |
196 |
* All slashes in the directory names should be replaced with '\0'. |
197 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
205 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
214 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
226 |
* @param Dst The location where the directory will be moved to. |
227 |
* All slashes in the directory names should be replaced with '\0'. |
228 |
* @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 |
* Copies the specified directory into the specified location. |
238 |
* @param Dir The absolute path name of the directory to copy. |
239 |
* All slashes in the directory names should be replaced with '\0'. |
240 |
* @param Dst The location where the directory will be copied to. |
241 |
* All slashes in the directory names should be replaced with '\0'. |
242 |
* @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 |
* Changes the description of the specified directory. |
252 |
* @param Dir The absolute path name of the directory. |
253 |
* All slashes in the directory names should be replaced with '\0'. |
254 |
* @throws Exception - if database error occurs, or if |
255 |
* the specified directory is not found. |
256 |
*/ |
257 |
void SetDirectoryDescription(String Dir, String Desc); |
258 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
264 |
* @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 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
278 |
* @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 |
* @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 |
* @throws Exception if the operation failed. |
293 |
*/ |
294 |
int AddInstruments(String DbDir, String FilePath, int Index, bool bBackground); |
295 |
|
296 |
/** |
297 |
* Adds the instruments in the specified file |
298 |
* to the specified instruments database directory. |
299 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
303 |
* @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 |
* @throws Exception if the operation failed. |
309 |
*/ |
310 |
void AddInstruments(String DbDir, String FilePath, int Index = -1, ScanProgress* pProgress = NULL); |
311 |
|
312 |
/** |
313 |
* Adds all supported instruments in the specified file system |
314 |
* 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 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
331 |
* @param FsDir The absolute path name of an existing |
332 |
* directory in the file system. |
333 |
* @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 |
* @throws Exception if the operation failed. |
338 |
*/ |
339 |
int AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground); |
340 |
|
341 |
/** |
342 |
* Gets the number of instruments in the specified directory. |
343 |
* @param Dir The absolute path name of the directory. |
344 |
* All slashes in the directory names should be replaced with '\0'. |
345 |
* @param Recursive If true, the number of all instruments |
346 |
* in the specified subtree will be returned. |
347 |
* @throws Exception - if database error occurs, or |
348 |
* the specified path name is invalid. |
349 |
* @returns The number of instruments in the specified directory. |
350 |
*/ |
351 |
int GetInstrumentCount(String Dir, bool Recursive); |
352 |
|
353 |
/** |
354 |
* Gets the list of instruments in the specified directory. |
355 |
* @param Dir The absolute path name of the directory. |
356 |
* All slashes in the directory names should be replaced with '\0'. |
357 |
* @param Recursive If true, all instruments |
358 |
* in the specified subtree will be returned. |
359 |
* @throws Exception - if database error occurs, or |
360 |
* the specified path name is invalid. |
361 |
*/ |
362 |
StringListPtr GetInstruments(String Dir, bool Recursive); |
363 |
|
364 |
/** |
365 |
* Removes the specified instrument from the database. |
366 |
* @param Instr The absolute path name of the instrument to remove. |
367 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
368 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
377 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
386 |
* @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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
398 |
* @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 |
* Copies the specified instrument into the specified directory. |
408 |
* @param Instr The absolute path name of the instrument to copy. |
409 |
* 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 |
* @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 |
* 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 |
* Finds all instruments that match the search query. |
429 |
* @param Dir The absolute path name of the database |
430 |
* directory to search in. |
431 |
* All slashes in the directory names should be replaced with '\0'. |
432 |
* @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 |
|
439 |
/** |
440 |
* Removes the old instruments datbase and re-creates |
441 |
* the instruments database from scratch. |
442 |
*/ |
443 |
void Format(); |
444 |
|
445 |
/** |
446 |
* All '\0' chars in the string are replaced with "\x2f"; |
447 |
* ', ", \ 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 |
|
458 |
/** |
459 |
* Closes the database connection if opened and deletes |
460 |
* the InstrumentsDb instance. |
461 |
*/ |
462 |
static void Destroy(); |
463 |
|
464 |
JobList Jobs; |
465 |
|
466 |
private: |
467 |
sqlite3* db; |
468 |
String DbFile; |
469 |
static InstrumentsDb* pInstrumentsDb; |
470 |
Mutex DbInstrumentsMutex; |
471 |
ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners; |
472 |
bool InTransaction; |
473 |
WorkerThread InstrumentsDbThread; |
474 |
|
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 |
* Gets the list of directories in the specified directory. |
504 |
* @param DirId The ID of the directory. |
505 |
* @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 |
* @throws Exception - if database error occurs, or |
509 |
* the specified ID is invalid. |
510 |
*/ |
511 |
StringListPtr GetDirectories(int DirId); |
512 |
|
513 |
/** |
514 |
* Gets the directory ID. |
515 |
* @param Dir The absolute path name of the directory. |
516 |
* All slashes in the directory names should be replaced with '\0'. |
517 |
* @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 |
* All slashes in the directory name should be replaced with '\0'. |
527 |
* @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 |
* 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 |
* 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 |
* All slashes in the directory/instrument names should be replaced with '\0'. |
594 |
* @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 |
* All slashes in the instrument name should be replaced with '\0'. |
604 |
* @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 |
* Gets the name of the instrument with the specified ID. |
611 |
* @param InstrId The ID of the instrument, which name should be obtained. |
612 |
* @returns The name of the specified instrument, where all slashes |
613 |
* in the name are replaced with '\0'. |
614 |
* @throws Exception - if database error occurs. |
615 |
*/ |
616 |
String GetInstrumentName(int InstrId); |
617 |
|
618 |
/** |
619 |
* 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 |
* 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 |
* @param InstrName The name of the instrument to copy. |
659 |
* All slashes in the instrument name should be replaced with '\0'. |
660 |
* @param DstDirId The ID of the directory where the |
661 |
* instrument will be copied to. |
662 |
* @param DstDir The name of the directory where the |
663 |
* 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 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
676 |
* @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 |
* All slashes in the directory names should be replaced with '\0'. |
692 |
* @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 |
* 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 |
* All slashes in the directory names should be replaced with '\0'. |
709 |
* @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 |
* @param pProgress The progress used to monitor the scan process. |
714 |
* Specify NULL if you don't want to monitor the scanning process. |
715 |
* @throws Exception if the operation failed. |
716 |
*/ |
717 |
void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL); |
718 |
|
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 |
* All slashes in the directory names should be replaced with '\0'. |
725 |
* @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 |
* @param pProgress The progress used to monitor the scan process. |
730 |
* Specify NULL if you don't want to monitor the scanning process. |
731 |
* @throws Exception if the operation failed. |
732 |
*/ |
733 |
void AddGigInstruments(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL); |
734 |
|
735 |
/** |
736 |
* Adds the specified GIG instrument. |
737 |
* @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 |
* @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 |
|
744 |
void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler); |
745 |
|
746 |
void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level); |
747 |
|
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 |
/** |
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 |
/** |
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 |
static String toEscapedFsPath(String FsPath); |
822 |
|
823 |
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 |
void FireJobStatusChanged(int JobId); |
830 |
|
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 |
|
863 |
/** SQLite user function for handling regular expressions */ |
864 |
static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue); |
865 |
}; |
866 |
|
867 |
} // namespace LinuxSampler |
868 |
|
869 |
#endif // __LS_INSTRUMENTSDB_H__ |
870 |
|
871 |
#endif // HAVE_SQLITE3 |