/[svn]/linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp

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

revision 1770 by schoenebeck, Sun Feb 3 16:21:38 2008 UTC revision 1771 by iliev, Wed Sep 10 15:02:24 2008 UTC
# Line 146  namespace LinuxSampler { namespace gig { Line 146  namespace LinuxSampler { namespace gig {
146      }      }
147    
148      InstrumentResourceManager::instrument_info_t InstrumentResourceManager::GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) {      InstrumentResourceManager::instrument_info_t InstrumentResourceManager::GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) {
149          std::vector<instrument_id_t> result;          Lock();
150            ::gig::Instrument* pInstrument = Resource(ID, false);
151            bool loaded = (pInstrument != NULL);
152            if (!loaded) Unlock();
153    
154          ::RIFF::File* riff = NULL;          ::RIFF::File* riff = NULL;
155          ::gig::File*  gig  = NULL;          ::gig::File*  gig  = NULL;
156          try {          try {
157              riff = new ::RIFF::File(ID.FileName);              if(!loaded) {
158              gig  = new ::gig::File(riff);                  riff = new ::RIFF::File(ID.FileName);
159              gig->SetAutoLoad(false); // avoid time consuming samples scanning                  gig  = new ::gig::File(riff);
160              ::gig::Instrument* pInstrument = gig->GetInstrument(ID.Index);                  gig->SetAutoLoad(false); // avoid time consuming samples scanning
161                    pInstrument = gig->GetInstrument(ID.Index);
162                }
163                
164              if (!pInstrument) throw InstrumentManagerException("There is no instrument " + ToString(ID.Index) + " in " + ID.FileName);              if (!pInstrument) throw InstrumentManagerException("There is no instrument " + ToString(ID.Index) + " in " + ID.FileName);
165    
166              instrument_info_t info;              instrument_info_t info;
167              if (gig->pVersion) {              for (int i = 0; i < 128; i++) { info.KeyBindings[i] = info.KeySwitchBindings[i] = 0; }
168                  info.FormatVersion = ToString(gig->pVersion->major);  
169                  info.Product = gig->pInfo->Product;              ::gig::File* pFile = (::gig::File*) pInstrument->GetParent();
170                  info.Artists = gig->pInfo->Artists;  
171                if (pFile->pVersion) {
172                    info.FormatVersion = ToString(pFile->pVersion->major);
173                    info.Product = pFile->pInfo->Product;
174                    info.Artists = pFile->pInfo->Artists;
175              }              }
176    
177              info.InstrumentName = pInstrument->pInfo->Name;              info.InstrumentName = pInstrument->pInfo->Name;
178    
179                ::gig::Region* pRegion = pInstrument->GetFirstRegion();
180                while (pRegion) {
181                    int low = pRegion->KeyRange.low;
182                    int high = pRegion->KeyRange.high;
183                    if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
184                        std::cerr << "Invalid key range: " << low << " - " << high << std::endl;
185                    } else {
186                        for (int i = low; i <= high; i++) info.KeyBindings[i] = 1;
187                    }
188                    pRegion = pInstrument->GetNextRegion();
189                }
190                
191                int low = pInstrument->DimensionKeyRange.low;
192                int high = pInstrument->DimensionKeyRange.high;
193                if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
194                    std::cerr << "Invalid keyswitch range: " << low << " - " << high << std::endl;
195                } else {
196                    for (int i = low; i <= high; i++) info.KeySwitchBindings[i] = 1;
197                }
198    
199                if (loaded) Unlock();
200    
201              if (gig)  delete gig;              if (gig)  delete gig;
202              if (riff) delete riff;              if (riff) delete riff;
203              return info;              return info;
204          } catch (::RIFF::Exception e) {          } catch (::RIFF::Exception e) {
205                if (loaded) Unlock();
206              if (gig)  delete gig;              if (gig)  delete gig;
207              if (riff) delete riff;              if (riff) delete riff;
208              throw InstrumentManagerException(e.Message);              throw InstrumentManagerException(e.Message);
209          } catch (...) {          } catch (...) {
210                if (loaded) Unlock();
211              if (gig)  delete gig;              if (gig)  delete gig;
212              if (riff) delete riff;              if (riff) delete riff;
213              throw InstrumentManagerException("Unknown exception while trying to parse '" + ID.FileName + "'");              throw InstrumentManagerException("Unknown exception while trying to parse '" + ID.FileName + "'");

Legend:
Removed from v.1770  
changed lines
  Added in v.1771

  ViewVC Help
Powered by ViewVC