/[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 1187 - (show annotations) (download) (as text)
Wed May 16 14:22:26 2007 UTC (16 years, 11 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 37741 byte(s)
* updated instruments db support
* added transactions for improving the db performance
* added commands for copying and finding instruments and directories

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

  ViewVC Help
Powered by ViewVC