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