/[svn]/linuxsampler/trunk/src/db/InstrumentsDb.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/db/InstrumentsDb.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1727 - (show annotations) (download) (as text)
Tue Apr 29 15:44:09 2008 UTC (16 years ago) by iliev
File MIME type: text/x-c++hdr
File size: 43707 byte(s)
* added support for handling lost files in the instruments database
* added new LSCP commands: FIND LOST DB_INSTRUMENT_FILES and
  SET DB_INSTRUMENT FILE_PATH

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

  ViewVC Help
Powered by ViewVC