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

Diff of /linuxsampler/trunk/src/engines/FxSend.cpp

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

revision 1001 by schoenebeck, Wed Dec 27 16:17:08 2006 UTC revision 1108 by iliev, Thu Mar 22 20:39:04 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 24 
24  #include "FxSend.h"  #include "FxSend.h"
25    
26  #include "../drivers/audio/AudioOutputDevice.h"  #include "../drivers/audio/AudioOutputDevice.h"
27    #include "../common/RTMath.h"
28    
29  #include <map>  #include <map>
30    
31  namespace LinuxSampler {  #define DEFAULT_FX_SEND_LEVEL   0.0f
32    
33      /*  namespace LinuxSampler {
        FIXME: we create fx send indeces globally for now, although we might  
        want them to be an individual sequence per sampler channel, beside that  
        we don't handle the cases yet where __indexer overflows back to 0  
     */  
     static uint __indexer = 0;  
34    
35      FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) {      FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception) {
36          this->pEngineChannel = pEngineChannel;          this->pEngineChannel = pEngineChannel;
37          AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();          AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
38          const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;          const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
# Line 44  namespace LinuxSampler { Line 40  namespace LinuxSampler {
40              const int iDestination = iChanOffset + i;              const int iDestination = iChanOffset + i;
41              Routing.push_back(iDestination);              Routing.push_back(iDestination);
42          }          }
43          MidiFxSendController = MidiCtrl;          SetMidiController(MidiCtrl);
44          sName = Name;          sName = Name;
45          iId = __indexer;  
46          __indexer++;          // create an EngineChannel unique ID for this FxSend instance
47          fLevel = 0.3f; // default FX send level          if (!pEngineChannel->GetFxSendCount()) iId = 0;
48            else {
49                // get the highest existing map ID
50                uint highestIndex = 0;
51                for (uint i = 0; i < pEngineChannel->GetFxSendCount(); i++)
52                    highestIndex = RTMath::Max(highestIndex, pEngineChannel->GetFxSend(i)->Id());
53                // check if we reached the index limit
54                if (highestIndex + 1 < highestIndex) {
55                    // search for an unoccupied map ID starting from 0
56                    for (uint i = 0; i < highestIndex; i++) {
57                        bool bOccupied = false;
58                        for (uint j = 0; j < pEngineChannel->GetFxSendCount(); j++) {
59                            if (pEngineChannel->GetFxSend(j)->Id() == i) {
60                                bOccupied = true;
61                                break;
62                            }
63                        }
64                        if (!bOccupied) {
65                            iId = i;
66                            goto __done;
67                        }
68                    }
69                    throw Exception("Internal error: could not find unoccupied FxSend ID.");
70                }
71                iId = highestIndex + 1;
72            }
73            __done:
74    
75            fLevel = DEFAULT_FX_SEND_LEVEL;
76      }      }
77    
78      int FxSend::DestinationChannel(int SrcChan) {      int FxSend::DestinationChannel(int SrcChan) {
# Line 94  namespace LinuxSampler { Line 118  namespace LinuxSampler {
118      }      }
119    
120      void FxSend::SetLevel(float f) {      void FxSend::SetLevel(float f) {
121            if(fLevel == f) return;
122          fLevel = f;          fLevel = f;
123            SetInfoChanged(true);
124      }      }
125    
126      void FxSend::SetLevel(uint8_t iMidiValue) {      void FxSend::SetLevel(uint8_t iMidiValue) {
127          fLevel = float(iMidiValue & 0x7f) / 127.0f;          fLevel = float(iMidiValue & 0x7f) / 127.0f;
128            SetInfoChanged(true);
129        }
130    
131        void FxSend::Reset() {
132            SetLevel(DEFAULT_FX_SEND_LEVEL);
133      }      }
134    
135      uint8_t FxSend::MidiController() {      uint8_t FxSend::MidiController() {
# Line 106  namespace LinuxSampler { Line 137  namespace LinuxSampler {
137      }      }
138    
139      void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {      void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
140          if (MidiCtrl & 0x7f)          if (MidiCtrl >> 7)
141              throw Exception("Invalid MIDI controller");              throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl));
142          MidiFxSendController = MidiCtrl;          MidiFxSendController = MidiCtrl;
143      }      }
144    
# Line 119  namespace LinuxSampler { Line 150  namespace LinuxSampler {
150          return iId;          return iId;
151      }      }
152    
153        void FxSend::SetInfoChanged(bool b) {
154            bInfoChanged = b;
155        }
156    
157        bool FxSend::IsInfoChanged() {
158            return bInfoChanged;
159        }
160    
161  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1001  
changed lines
  Added in v.1108

  ViewVC Help
Powered by ViewVC