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

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

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

revision 1748 by persson, Sun Jun 22 14:46:46 2008 UTC revision 1789 by iliev, Sat Nov 1 19:01:27 2008 UTC
# Line 291  namespace LinuxSampler { namespace gig { Line 291  namespace LinuxSampler { namespace gig {
291          // make sure that the engine does not get any sysex messages          // make sure that the engine does not get any sysex messages
292          // while it's reseting          // while it's reseting
293          bool sysexDisabled = MidiInputPort::RemoveSysexListener(this);          bool sysexDisabled = MidiInputPort::RemoveSysexListener(this);
294          ActiveVoiceCount    = 0;          SetVoiceCount(0);
295          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
296    
297          // reset voice stealing parameters          // reset voice stealing parameters
# Line 573  namespace LinuxSampler { namespace gig { Line 573  namespace LinuxSampler { namespace gig {
573          // return if engine disabled          // return if engine disabled
574          if (EngineDisabled.Pop()) {          if (EngineDisabled.Pop()) {
575              dmsg(5,("gig::Engine: engine disabled (val=%d)\n",EngineDisabled.GetUnsafe()));              dmsg(5,("gig::Engine: engine disabled (val=%d)\n",EngineDisabled.GetUnsafe()));
576                EngineDisabled.RttDone();
577              return 0;              return 0;
578          }          }
579    
# Line 685  namespace LinuxSampler { namespace gig { Line 686  namespace LinuxSampler { namespace gig {
686          pVoiceStealingQueue->clear();          pVoiceStealingQueue->clear();
687    
688          // just some statistics about this engine instance          // just some statistics about this engine instance
689          ActiveVoiceCount = ActiveVoiceCountTemp;          SetVoiceCount(ActiveVoiceCountTemp);
690          if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount;          if (VoiceCount() > ActiveVoiceCountMax) ActiveVoiceCountMax = VoiceCount();
691    
692          // in case regions were previously suspended and we killed voices          // in case regions were previously suspended and we killed voices
693          // with disk streams due to that, check if those streams have finally          // with disk streams due to that, check if those streams have finally
# Line 698  namespace LinuxSampler { namespace gig { Line 699  namespace LinuxSampler { namespace gig {
699          }          }
700          FrameTime += Samples;          FrameTime += Samples;
701    
702            EngineDisabled.RttDone();
703          return 0;          return 0;
704      }      }
705    
# Line 784  namespace LinuxSampler { namespace gig { Line 786  namespace LinuxSampler { namespace gig {
786                      voiceCount++;                      voiceCount++;
787    
788                      if (itVoice->PlaybackState == Voice::playback_state_disk) {                      if (itVoice->PlaybackState == Voice::playback_state_disk) {
789                          if ((itVoice->DiskStreamRef).State == Stream::state_active) streamCount++;                          if ((itVoice->DiskStreamRef).State != Stream::state_unused) streamCount++;
790                      }                      }
791                  }  else { // voice reached end, is now inactive                  }  else { // voice reached end, is now inactive
792                      FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices                      FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices
# Line 825  namespace LinuxSampler { namespace gig { Line 827  namespace LinuxSampler { namespace gig {
827                      pEngineChannel->SetVoiceCount(pEngineChannel->GetVoiceCount() + 1);                      pEngineChannel->SetVoiceCount(pEngineChannel->GetVoiceCount() + 1);
828    
829                      if (itNewVoice->PlaybackState == Voice::playback_state_disk) {                      if (itNewVoice->PlaybackState == Voice::playback_state_disk) {
830                          if (itNewVoice->DiskStreamRef.State == Stream::state_active) {                          if (itNewVoice->DiskStreamRef.State != Stream::state_unused) {
831                              pEngineChannel->SetDiskStreamCount(pEngineChannel->GetDiskStreamCount() + 1);                              pEngineChannel->SetDiskStreamCount(pEngineChannel->GetDiskStreamCount() + 1);
832                          }                          }
833                      }                      }
# Line 953  namespace LinuxSampler { namespace gig { Line 955  namespace LinuxSampler { namespace gig {
955       *       *
956       *  @param pData - pointer to sysex data       *  @param pData - pointer to sysex data
957       *  @param Size  - lenght of sysex data (in bytes)       *  @param Size  - lenght of sysex data (in bytes)
958         *  @param pSender - the MIDI input port on which the SysEx message was
959         *                   received
960       */       */
961      void Engine::SendSysex(void* pData, uint Size) {      void Engine::SendSysex(void* pData, uint Size, MidiInputPort* pSender) {
962          Event event             = pEventGenerator->CreateEvent();          Event event             = pEventGenerator->CreateEvent();
963          event.Type              = Event::type_sysex;          event.Type              = Event::type_sysex;
964          event.Param.Sysex.Size  = Size;          event.Param.Sysex.Size  = Size;
965          event.pEngineChannel    = NULL; // as Engine global event          event.pEngineChannel    = NULL; // as Engine global event
966            event.pMidiInputPort    = pSender;
967          if (pEventQueue->write_space() > 0) {          if (pEventQueue->write_space() > 0) {
968              if (pSysexBuffer->write_space() >= Size) {              if (pSysexBuffer->write_space() >= Size) {
969                  // copy sysex data to input buffer                  // copy sysex data to input buffer
# Line 1901  namespace LinuxSampler { namespace gig { Line 1906  namespace LinuxSampler { namespace gig {
1906                  switch (sub_id1) {                  switch (sub_id1) {
1907                      case 0x04: // Device Control                      case 0x04: // Device Control
1908                          switch (sub_id2) {                          switch (sub_id2) {
1909                              case 0x01: // Master Volume                              case 0x01: { // Master Volume
1910                                  GLOBAL_VOLUME =                                  const double volume =
1911                                      double((uint(val_msb)<<7) | uint(val_lsb)) / 16383.0;                                      double((uint(val_msb)<<7) | uint(val_lsb)) / 16383.0;
1912                                    #if CONFIG_MASTER_VOLUME_SYSEX_BY_PORT
1913                                    // apply volume to all sampler channels that
1914                                    // are connected to the same MIDI input port
1915                                    // this sysex message arrived on
1916                                    for (int i = 0; i < engineChannels.size(); ++i) {
1917                                        EngineChannel* pEngineChannel = engineChannels[i];
1918                                        if (pEngineChannel->GetMidiInputPort() ==
1919                                            itSysexEvent->pMidiInputPort)
1920                                        {
1921                                            pEngineChannel->Volume(volume);
1922                                        }
1923                                    }
1924                                    #else
1925                                    // apply volume globally to the whole sampler
1926                                    GLOBAL_VOLUME = volume;
1927                                    #endif // CONFIG_MASTER_VOLUME_SYSEX_BY_PORT
1928                                  break;                                  break;
1929                                }
1930                          }                          }
1931                          break;                          break;
1932                  }                  }
# Line 1946  namespace LinuxSampler { namespace gig { Line 1968  namespace LinuxSampler { namespace gig {
1968                              dmsg(3,("\t\t\tNew scale applied.\n"));                              dmsg(3,("\t\t\tNew scale applied.\n"));
1969                              break;                              break;
1970                          }                          }
1971                            case 0x15: { // chromatic / drumkit mode
1972                                dmsg(3,("\t\tMIDI Instrument Map Switch\n"));
1973                                uint8_t part = addr[1] & 0x0f;
1974                                uint8_t map;
1975                                if (!reader.pop(&map)) goto free_sysex_data;
1976                                for (int i = 0; i < engineChannels.size(); ++i) {
1977                                    EngineChannel* pEngineChannel = engineChannels[i];
1978                                    if (
1979                                        (pEngineChannel->midiChannel == part ||
1980                                         pEngineChannel->midiChannel == midi_chan_all) &&
1981                                         pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort
1982                                    ) {
1983                                        try {
1984                                            pEngineChannel->SetMidiInstrumentMap(map);
1985                                        } catch (Exception e) {
1986                                            dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str()));
1987                                            goto free_sysex_data;
1988                                        } catch (...) {
1989                                            dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part));
1990                                            goto free_sysex_data;
1991                                        }
1992                                    }
1993                                }
1994                                dmsg(3,("\t\t\tApplied MIDI instrument map %d to part %d.\n", map, part));
1995                                break;
1996                            }
1997                      }                      }
1998                  }                  }
1999                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x20) { // Part Parameters (2)                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x20) { // Part Parameters (2)
# Line 2052  namespace LinuxSampler { namespace gig { Line 2100  namespace LinuxSampler { namespace gig {
2100      }      }
2101    
2102      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
2103          return ActiveVoiceCount;          return atomic_read(&ActiveVoiceCount);
2104        }
2105    
2106        void Engine::SetVoiceCount(uint Count) {
2107            atomic_set(&ActiveVoiceCount, Count);
2108      }      }
2109    
2110      uint Engine::VoiceCountMax() {      uint Engine::VoiceCountMax() {
# Line 2064  namespace LinuxSampler { namespace gig { Line 2116  namespace LinuxSampler { namespace gig {
2116      }      }
2117    
2118      uint Engine::DiskStreamCount() {      uint Engine::DiskStreamCount() {
2119          return (pDiskThread) ? pDiskThread->ActiveStreamCount : 0;          return (pDiskThread) ? pDiskThread->GetActiveStreamCount() : 0;
2120      }      }
2121    
2122      uint Engine::DiskStreamCountMax() {      uint Engine::DiskStreamCountMax() {
# Line 2088  namespace LinuxSampler { namespace gig { Line 2140  namespace LinuxSampler { namespace gig {
2140      }      }
2141    
2142      String Engine::Version() {      String Engine::Version() {
2143          String s = "$Revision: 1.93 $";          String s = "$Revision: 1.98 $";
2144          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
2145      }      }
2146    

Legend:
Removed from v.1748  
changed lines
  Added in v.1789

  ViewVC Help
Powered by ViewVC