/[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 1424 - (show annotations) (download) (as text)
Sun Oct 14 22:00:17 2007 UTC (16 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 41816 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

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 #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 File the pathname of the file to create.
128 * @throws Exception If the creation of the database file failed.
129 */
130 static void CreateInstrumentsDb(String File);
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 * Removes the old instruments datbase and re-creates
439 * the instruments database from scratch.
440 */
441 void Format();
442
443 /**
444 * All '\0' chars in the string are replaced with "\x2f";
445 * ', ", \ are escaped with backslash and
446 * <CR> and <LF> are replaced with \r and \n.
447 */
448 static String toEscapedPath(String AbstractPath);
449
450 /**
451 * The characters ', ", \ are escaped with backslash and
452 * <CR> and <LF> are replaced with \r and \n.
453 */
454 static String toEscapedText(String text);
455
456 /**
457 * Closes the database connection if opened and deletes
458 * the InstrumentsDb instance.
459 */
460 static void Destroy();
461
462 JobList Jobs;
463
464 private:
465 sqlite3* db;
466 String DbFile;
467 static InstrumentsDb* pInstrumentsDb;
468 Mutex DbInstrumentsMutex;
469 ListenerList<InstrumentsDb::Listener*> llInstrumentsDbListeners;
470 bool InTransaction;
471 WorkerThread InstrumentsDbThread;
472
473 InstrumentsDb();
474 ~InstrumentsDb();
475
476 /**
477 * Gets the instruments database. If the database is not
478 * opened, a connection to the database is established first.
479 * @returns The instruments database.
480 * @throws Exception if fail to open the database.
481 */
482 sqlite3* GetDb();
483
484 /**
485 * Gets the number of directories in the directory
486 * with ID DirId.
487 * @returns The number of directories in the specified directory
488 * or -1 if the directory doesn't exist.
489 */
490 int GetDirectoryCount(int DirId);
491
492 /**
493 * Gets a list containing the IDs of all directories in
494 * the specified instrument directory.
495 * @returns The IDs of all directories in the specified directory.
496 * @throws Exception - if database error occurs.
497 */
498 IntListPtr GetDirectoryIDs(int DirId);
499
500 /**
501 * Gets the list of directories in the specified directory.
502 * @param DirId The ID of the directory.
503 * @returns The list of directories, where the directories are
504 * represented in abstract path - all slashes in the directory
505 * names are replaced with '\0'.
506 * @throws Exception - if database error occurs, or
507 * the specified ID is invalid.
508 */
509 StringListPtr GetDirectories(int DirId);
510
511 /**
512 * Gets the directory ID.
513 * @param Dir The absolute path name of the directory.
514 * All slashes in the directory names should be replaced with '\0'.
515 * @returns The directory ID or -1 if the directory is not found.
516 * @throws Exception - if database error occurs.
517 */
518 int GetDirectoryId(String Dir);
519
520 /**
521 * Gets the directory ID.
522 * @param ParentDirId The ID of the parent directory.
523 * @param DirName The directory name.
524 * All slashes in the directory name should be replaced with '\0'.
525 * @throws Exception - if database error occurs.
526 * @returns The ID of the specified directory
527 * or -1 if the directory doesn't exist.
528 */
529 int GetDirectoryId(int ParentDirId, String DirName);
530
531 /**
532 * Gets the name of the specified directory.
533 * @throws Exception - if the directory is not found
534 * or if database error occurs.
535 */
536 String GetDirectoryName(int DirId);
537
538 /**
539 * Gets the ID of the parent directory.
540 * @throws Exception - if the root directory is specified, or if the
541 * specified directory is not found, or if database error occurs.
542 */
543 int GetParentDirectoryId(int DirId);
544
545 /**
546 * Gets the absolute path name of the specified directory.
547 * @param DirId The ID of the directory, which absolute
548 * path name should be returned.
549 * @throws Exception If the specified directory is not
550 * found or if database error occurs.
551 */
552 String GetDirectoryPath(int DirId);
553
554 /**
555 * Removes the specified directory from the database.
556 * @param DirId The ID of the directory to remove.
557 * @throws Exception - If the specified directory is not empty.
558 */
559 void RemoveDirectory(int DirId);
560
561 /**
562 * Removes all directories in the specified directory.
563 * Do NOT call this method before ensuring that all
564 * directories in the specified directory are empty.
565 * @param DirId The ID of the directory.
566 * @throws Exception - if at least one of the directories in the
567 * specified directory is not empty or if database error occurs.
568 * @see IsDirectoryEmpty
569 */
570 void RemoveAllDirectories(int DirId);
571
572 /**
573 * Determines whether the specified directory is empty.
574 * If the directory doesn't exist the return value is false.
575 * @throws Exception - if database error occurs.
576 */
577 bool IsDirectoryEmpty(int DirId);
578
579 /**
580 * Removes the content of the specified directory from the database.
581 * @param DirId The ID of the directory.
582 * @param Level Used to prevent stack overflow, which may occur
583 * due to large or infinite recursive loop.
584 * @throws Exception - If database error occurs.
585 */
586 void RemoveDirectoryContent(int DirId, int Level = 0);
587
588 /**
589 * Gets the ID of the specified database instrument.
590 * @param Instr The absolute path name of the instrument.
591 * All slashes in the directory/instrument names should be replaced with '\0'.
592 * @returns The instrument ID or -1 if the instrument is not found.
593 * @throws Exception - if database error occurs.
594 */
595 int GetInstrumentId(String Instr);
596
597 /**
598 * Gets the ID of the specified database instrument.
599 * @param DirId The ID of the directory containing the instrument.
600 * @param InstrName The name of the instrument.
601 * All slashes in the instrument name should be replaced with '\0'.
602 * @returns The instrument ID or -1 if the instrument is not found.
603 * @throws Exception - if database error occurs.
604 */
605 int GetInstrumentId(int DirId, String InstrName);
606
607 /**
608 * Gets the name of the instrument with the specified ID.
609 * @param InstrId The ID of the instrument, which name should be obtained.
610 * @returns The name of the specified instrument, where all slashes
611 * in the name are replaced with '\0'.
612 * @throws Exception - if database error occurs.
613 */
614 String GetInstrumentName(int InstrId);
615
616 /**
617 * Removes the specified instrument from the database.
618 * @param InstrId The ID of the instrument to remove.
619 * @throws Exception - If the specified instrument does not exist.
620 */
621 void RemoveInstrument(int InstrId);
622
623 /**
624 * Removes all instruments in the specified directory.
625 * @param DirId The ID of the directory.
626 * @throws Exception - if database error occurs.
627 */
628 void RemoveAllInstruments(int DirId);
629
630 /**
631 * Gets the number of instruments in the directory
632 * with ID DirId.
633 * @returns The number of instruments in the specified directory
634 * or -1 if the directory doesn't exist.
635 */
636 int GetInstrumentCount(int DirId);
637
638 /**
639 * Gets a list containing the IDs of all instruments in
640 * the specified instrument directory.
641 * @returns The IDs of all instruments in the specified directory.
642 * @throws Exception - if database error occurs.
643 */
644 IntListPtr GetInstrumentIDs(int DirId);
645
646 /**
647 * Gets information about the specified instrument.
648 * @param InstrId The ID of the instrument.
649 * @throws Exception - if database error occurs.
650 */
651 DbInstrument GetInstrumentInfo(int InstrId);
652
653 /**
654 * Copies the specified instrument into the specified directory.
655 * @param InstrId The ID of the instrument to copy.
656 * @param InstrName The name of the instrument to copy.
657 * All slashes in the instrument name should be replaced with '\0'.
658 * @param DstDirId The ID of the directory where the
659 * instrument will be copied to.
660 * @param DstDir The name of the directory where the
661 * instrument will be copied to.
662 * @throws Exception - If database error occurs.
663 */
664 void CopyInstrument(int InstrId, String InstrName, int DstDirId, String DstDir);
665
666 /**
667 * Adds all supported instruments in the specified directory
668 * to the specified instruments database directory. The
669 * instruments in the subdirectories will not be processed.
670 * @param DbDir The absolute path name of a directory in the
671 * instruments database in which only the new instruments
672 * (that are not already in the database) will be added.
673 * All slashes in the directory names should be replaced with '\0'.
674 * @param FsDir The absolute path name of a directory in the file
675 * system.
676 * @param pProgress The progress used to monitor the scan process.
677 * @throws Exception if the operation failed.
678 */
679 void AddInstrumentsNonrecursive(String DbDir, String FsDir, ScanProgress* pProgress = NULL);
680
681 /**
682 * Adds all supported instruments in the specified file system
683 * direcotry to the specified instruments database directory,
684 * including the instruments in the subdirectories of the
685 * supplied directory.
686 * @param DbDir The absolute path name of a directory in the
687 * instruments database in which only the new instruments
688 * (that are not already in the database) will be added.
689 * All slashes in the directory names should be replaced with '\0'.
690 * @param FsDir The absolute path name of an existing
691 * directory in the file system.
692 * @param Flat If true, the respective subdirectory structure will
693 * not be recreated in the instruments database and all instruments
694 * will be added directly in the specified database directory.
695 * @param pProgress The progress used to monitor the scan process.
696 * @throws Exception if the operation failed.
697 */
698 void AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat = false, ScanProgress* pProgress = NULL);
699
700 /**
701 * Adds the instruments in the specified file
702 * to the specified instruments database directory.
703 * @param DbDir The absolute path name of a directory in the
704 * instruments database in which only the new instruments
705 * (that are not already in the database) will be added.
706 * All slashes in the directory names should be replaced with '\0'.
707 * @param File The absolute path name of a file in the file system.
708 * @param Index The index of the instrument (in the given
709 * instrument file) to add. If -1 is specified, all instruments in
710 * the supplied instrument file will be added.
711 * @param pProgress The progress used to monitor the scan process.
712 * Specify NULL if you don't want to monitor the scanning process.
713 * @throws Exception if the operation failed.
714 */
715 void AddInstrumentsFromFile(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
716
717 /**
718 * Adds the specified GIG instrument(s) to the specified location
719 * in the instruments database.
720 * @param DbDir The instruments database directory
721 * in which the instrument will be added.
722 * All slashes in the directory names should be replaced with '\0'.
723 * @param File The absolute path name of the instrument file.
724 * @param Index The index of the instrument (in the given
725 * instrument file) to add. If -1 is specified, all instruments in
726 * the supplied instrument file will be added.
727 * @param pProgress The progress used to monitor the scan process.
728 * Specify NULL if you don't want to monitor the scanning process.
729 * @throws Exception if the operation failed.
730 */
731 void AddGigInstruments(String DbDir, String File, int Index = -1, ScanProgress* pProgress = NULL);
732
733 /**
734 * Adds the specified GIG instrument.
735 * @param DbDir The instruments database directory
736 * in which the instrument will be added.
737 * All slashes in the directory names should be replaced with '\0'.
738 * @throws Exception if the operation failed.
739 */
740 void AddGigInstrument(sqlite3_stmt* pStmt, String DbDir, int DirId, String File, ::gig::Instrument* pInstrument, int Index);
741
742 void DirectoryTreeWalk(String AbstractPath, DirectoryHandler* pHandler);
743
744 void DirectoryTreeWalk(DirectoryHandler* pHandler, String AbstractPath, int DirId, int Level);
745
746 /** Locks the DbInstrumentsMutex and starts a transaction. */
747 void BeginTransaction();
748
749 /** Commits the transaction and unocks the DbInstrumentsMutex. */
750 void EndTransaction();
751
752 /**
753 * Used to execute SQL commands which return empty result set.
754 */
755 void ExecSql(String Sql);
756
757 /**
758 * Used to execute SQL commands which return empty result set.
759 */
760 void ExecSql(String Sql, String Param);
761
762 /**
763 * Used to execute SQL commands which returns integer.
764 */
765 int ExecSqlInt(String Sql);
766
767 /**
768 * Used to execute SQL commands which returns integer.
769 */
770 int ExecSqlInt(String Sql, String Param);
771
772 /**
773 * Used to execute SQL commands which returns integer.
774 */
775 String ExecSqlString(String Sql);
776
777 /**
778 * Used to execute SQL commands which returns integer list.
779 */
780 IntListPtr ExecSqlIntList(String Sql);
781
782 /**
783 * Used to execute SQL commands which returns string list.
784 */
785 StringListPtr ExecSqlStringList(String Sql);
786
787 /**
788 * Binds the specified text parameter.
789 */
790 void BindTextParam(sqlite3_stmt* pStmt, int Index, String Text);
791
792 /**
793 * Binds the specified integer parameter.
794 */
795 void BindIntParam(sqlite3_stmt* pStmt, int Index, int Param);
796
797 /**
798 * Checks whether an instrument with the specified name already
799 * exists in the specified directory and if so a new unique name
800 * is returnded. The new name is generated by adding the suffix
801 * [<nr>] to the end of the name , where <nr> is a number between
802 * 2 and 1000.
803 * throws Exception if cannot find an unique name. This is done
804 * because it is highly unlikely that this can happen, so it is
805 * supposed that this is due to a bug or an infinite loop.
806 */
807 String GetUniqueInstrumentName(int DirId, String Name);
808
809 /**
810 * All '\0' chars in the string are replaced with '/'.
811 */
812 static String toDbName(String AbstractName);
813
814 /**
815 * All slashes are replaced with '\0'.
816 */
817 static String toAbstractName(String DbName);
818
819 static String toEscapedFsPath(String FsPath);
820
821 void FireDirectoryCountChanged(String Dir);
822 void FireDirectoryInfoChanged(String Dir);
823 void FireDirectoryNameChanged(String Dir, String NewName);
824 void FireInstrumentCountChanged(String Dir);
825 void FireInstrumentInfoChanged(String Instr);
826 void FireInstrumentNameChanged(String Instr, String NewName);
827 void FireJobStatusChanged(int JobId);
828
829 /**
830 * Strips the non-directory suffix from the file name. If the string
831 * ends with `/' only the last character is removed. If the string
832 * doesn't starts with `/' charater, an empty string is returned.
833 */
834 static String GetDirectoryPath(String File);
835
836 /**
837 * Returns the file name extracted from the specified absolute path
838 * name. If the string doesn't starts with `/' or ends with `/',
839 * an empty string is returned.
840 */
841 static String GetFileName(String Path);
842
843 /**
844 * Strips the last directory from the specified path name. If the
845 * string doesn't starts with `/' an empty string is returned.
846 */
847 static String GetParentDirectory(String Dir);
848
849 /**
850 * Checks whether the specified path is valid.
851 * @throws Exception - if the specified path is invalid.
852 */
853 static void CheckPathName(String Path);
854
855 /**
856 * Checks whether the specified file name is valid.
857 * @throws Exception - if the specified file name is invalid.
858 */
859 static void CheckFileName(String File);
860
861 /** SQLite user function for handling regular expressions */
862 static void Regexp(sqlite3_context* pContext, int argc, sqlite3_value** ppValue);
863 };
864
865 } // namespace LinuxSampler
866
867 #endif // __LS_INSTRUMENTSDB_H__

  ViewVC Help
Powered by ViewVC