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