/[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 1350 - (show annotations) (download) (as text)
Sun Sep 16 23:06:10 2007 UTC (16 years, 7 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 41678 byte(s)
* instruments db: slashes-in-names are now escaped with \x2f

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

  ViewVC Help
Powered by ViewVC