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

Diff of /linuxsampler/trunk/src/db/InstrumentsDb.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1727 by iliev, Tue Apr 29 15:44:09 2008 UTC revision 1781 by iliev, Mon Sep 29 18:21:21 2008 UTC
# Line 641  namespace LinuxSampler { Line 641  namespace LinuxSampler {
641          FireDirectoryInfoChanged(Dir);          FireDirectoryInfoChanged(Dir);
642      }      }
643    
644      int InstrumentsDb::AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground) {      int InstrumentsDb::AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground, bool insDir) {
645          dmsg(2,("InstrumentsDb: AddInstruments(Mode=%d,DbDir=%s,FsDir=%s,bBackground=%d)\n", Mode, DbDir.c_str(), FsDir.c_str(), bBackground));          dmsg(2,("InstrumentsDb: AddInstruments(Mode=%d,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", Mode, DbDir.c_str(), FsDir.c_str(), bBackground, insDir));
646          if(!bBackground) {          if(!bBackground) {
647              switch (Mode) {              switch (Mode) {
648                  case NON_RECURSIVE:                  case NON_RECURSIVE:
649                      AddInstrumentsNonrecursive(DbDir, FsDir);                      AddInstrumentsNonrecursive(DbDir, FsDir, insDir);
650                      break;                      break;
651                  case RECURSIVE:                  case RECURSIVE:
652                      AddInstrumentsRecursive(DbDir, FsDir);                      AddInstrumentsRecursive(DbDir, FsDir, false, insDir);
653                      break;                      break;
654                  case FLAT:                  case FLAT:
655                      AddInstrumentsRecursive(DbDir, FsDir, true);                      AddInstrumentsRecursive(DbDir, FsDir, true, insDir);
656                      break;                      break;
657                  default:                  default:
658                      throw Exception("Unknown scan mode");                      throw Exception("Unknown scan mode");
# Line 663  namespace LinuxSampler { Line 663  namespace LinuxSampler {
663    
664          ScanJob job;          ScanJob job;
665          int jobId = Jobs.AddJob(job);          int jobId = Jobs.AddJob(job);
666          InstrumentsDbThread.Execute(new AddInstrumentsJob(jobId, Mode, DbDir, FsDir));          InstrumentsDbThread.Execute(new AddInstrumentsJob(jobId, Mode, DbDir, FsDir, insDir));
667    
668          return jobId;          return jobId;
669      }      }
# Line 671  namespace LinuxSampler { Line 671  namespace LinuxSampler {
671      int InstrumentsDb::AddInstruments(String DbDir, String FilePath, int Index, bool bBackground) {      int InstrumentsDb::AddInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
672          dmsg(2,("InstrumentsDb: AddInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));          dmsg(2,("InstrumentsDb: AddInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
673          if(!bBackground) {          if(!bBackground) {
674              AddInstruments(DbDir, FilePath, Index);              AddInstruments(DbDir, false, FilePath, Index);
675              return -1;              return -1;
676          }          }
677    
678          ScanJob job;          ScanJob job;
679          int jobId = Jobs.AddJob(job);          int jobId = Jobs.AddJob(job);
680          InstrumentsDbThread.Execute(new AddInstrumentsFromFileJob(jobId, DbDir, FilePath, Index));          InstrumentsDbThread.Execute(new AddInstrumentsFromFileJob(jobId, DbDir, FilePath, Index, false));
681    
682          return jobId;          return jobId;
683      }      }
684    
685      void InstrumentsDb::AddInstruments(String DbDir, String FilePath, int Index, ScanProgress* pProgress) {      void InstrumentsDb::AddInstruments(String DbDir, bool insDir, String FilePath, int Index, ScanProgress* pProgress) {
686          dmsg(2,("InstrumentsDb: AddInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index));          dmsg(2,("InstrumentsDb: AddInstruments(DbDir=%s,insDir=%d,FilePath=%s,Index=%d)\n", DbDir.c_str(), insDir, FilePath.c_str(), Index));
687          if (DbDir.empty() || FilePath.empty()) return;          if (DbDir.empty() || FilePath.empty()) return;
688                    
689          DbInstrumentsMutex.Lock();          DbInstrumentsMutex.Lock();
# Line 704  namespace LinuxSampler { Line 704  namespace LinuxSampler {
704                  throw Exception(ss.str());                  throw Exception(ss.str());
705              }              }
706    
707              AddInstrumentsFromFile(DbDir, FilePath, Index, pProgress);                          if(insDir) {
708                                    std::string tmp = f.basename(FilePath, ".");
709                                    String gigDir;
710                                    if(DbDir.length() == 1 && DbDir.at(0) == '/') //DbDir is /
711                                            gigDir = DbDir + (String)tmp + "/";
712                                    else
713                                            gigDir = DbDir +"/"+ (String)tmp + "/";
714                                    dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(Dir from file mode=%d, Created SubDir=%s)\n",insDir, gigDir.c_str()));
715                    DbInstrumentsMutex.Unlock();
716                                    AddDirectory(gigDir);//TODO: Add some error checking here to make sure the dir is created
717                    DbInstrumentsMutex.Lock();
718                    AddInstrumentsFromFile(gigDir, FilePath, Index, pProgress);
719                            } else {
720                    AddInstrumentsFromFile(DbDir, FilePath, Index, pProgress);
721                            }
722          } catch (Exception e) {          } catch (Exception e) {
723              DbInstrumentsMutex.Unlock();              DbInstrumentsMutex.Unlock();
724              throw e;              throw e;
# Line 713  namespace LinuxSampler { Line 727  namespace LinuxSampler {
727          DbInstrumentsMutex.Unlock();          DbInstrumentsMutex.Unlock();
728      }      }
729    
730      void InstrumentsDb::AddInstrumentsNonrecursive(String DbDir, String FsDir, ScanProgress* pProgress) {      void InstrumentsDb::AddInstrumentsNonrecursive(String DbDir, String FsDir, bool insDir, ScanProgress* pProgress) {
731          dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(DbDir=%s,FsDir=%s)\n", DbDir.c_str(), FsDir.c_str()));          dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(DbDir=%s,FsDir=%s,insDir=%d)\n", DbDir.c_str(), FsDir.c_str(), insDir));
732          if (DbDir.empty() || FsDir.empty()) return;          if (DbDir.empty() || FsDir.empty()) return;
733                    
734          DbInstrumentsMutex.Lock();          DbInstrumentsMutex.Lock();
# Line 740  namespace LinuxSampler { Line 754  namespace LinuxSampler {
754              try {              try {
755                  FileListPtr fileList = File::GetFiles(FsDir);                  FileListPtr fileList = File::GetFiles(FsDir);
756                  for (int i = 0; i < fileList->size(); i++) {                  for (int i = 0; i < fileList->size(); i++) {
757                      AddInstrumentsFromFile(DbDir, FsDir + fileList->at(i), -1, pProgress);                                          if(insDir)
758                                            {
759                                                    //File gFile = File(fileList->at(i));
760                                                    String gigDir;
761                                                    if(DbDir.length() == 1 && DbDir.at(0) == '/') //DbDir is /
762                                                            gigDir  = DbDir + f.basename(fileList->at(i),".") + "/";
763                                                    else
764                                                            gigDir  = DbDir +"/"+ f.basename(fileList->at(i),".") + "/";
765                                                    dmsg(2,("InstrumentsDb: AddInstrumentsNonrecursive(Dir from file mode=%d, Created SubDir=%s)\n",insDir, gigDir.c_str()));
766                                    DbInstrumentsMutex.Unlock(); // UnLock the db so we can add our extra directory
767                                                    AddDirectory(gigDir);//TODO: Add some error checking here to make sure the dir is created
768                                            DbInstrumentsMutex.Lock(); //Lock and carry on
769                            AddInstrumentsFromFile(gigDir, FsDir + fileList->at(i), -1, pProgress);
770                                            }
771                                            else
772                                            {
773                            AddInstrumentsFromFile(DbDir, FsDir + fileList->at(i), -1, pProgress);
774                                            }
775                  }                  }
776              } catch(Exception e) {              } catch(Exception e) {
777                  e.PrintMessage();                  e.PrintMessage();
# Line 755  namespace LinuxSampler { Line 786  namespace LinuxSampler {
786          DbInstrumentsMutex.Unlock();          DbInstrumentsMutex.Unlock();
787      }      }
788    
789      void InstrumentsDb::AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat, ScanProgress* pProgress) {      void InstrumentsDb::AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat, bool insDir, ScanProgress* pProgress) {
790          dmsg(2,("InstrumentsDb: AddInstrumentsRecursive(DbDir=%s,FsDir=%s,Flat=%d)\n", DbDir.c_str(), FsDir.c_str(), Flat));          dmsg(2,("InstrumentsDb: AddInstrumentsRecursive(DbDir=%s,FsDir=%s,Flat=%d,insDir=%d)\n", DbDir.c_str(), FsDir.c_str(), Flat, insDir));
791          if (pProgress != NULL) {          if (pProgress != NULL) {
792              InstrumentFileCounter c;              InstrumentFileCounter c;
793              pProgress->SetTotalFileCount(c.Count(FsDir));              pProgress->SetTotalFileCount(c.Count(FsDir));
794          }          }
795    
796          DirectoryScanner d;          DirectoryScanner d;
797          d.Scan(DbDir, FsDir, Flat, pProgress);          d.Scan(DbDir, FsDir, Flat, insDir, pProgress);
798      }      }
799    
800      int InstrumentsDb::GetInstrumentCount(int DirId) {      int InstrumentsDb::GetInstrumentCount(int DirId) {

Legend:
Removed from v.1727  
changed lines
  Added in v.1781

  ViewVC Help
Powered by ViewVC