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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (hide annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 6628 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

1 schoenebeck 1001 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1017 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 schoenebeck 1001 * *
8     * 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 *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This library is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this library; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "FxSend.h"
25    
26 schoenebeck 1424 #include "../common/global_private.h"
27 schoenebeck 1001 #include "../drivers/audio/AudioOutputDevice.h"
28 schoenebeck 1017 #include "../common/RTMath.h"
29 schoenebeck 1001
30     #include <map>
31    
32 schoenebeck 1040 #define DEFAULT_FX_SEND_LEVEL 0.0f
33    
34 schoenebeck 1001 namespace LinuxSampler {
35    
36 schoenebeck 1017 FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception) {
37 schoenebeck 1001 this->pEngineChannel = pEngineChannel;
38     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
39     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
40     for (int i = 0; i < pEngineChannel->Channels(); i++) {
41     const int iDestination = iChanOffset + i;
42     Routing.push_back(iDestination);
43     }
44 schoenebeck 1026 SetMidiController(MidiCtrl);
45 schoenebeck 1001 sName = Name;
46 schoenebeck 1017
47     // create an EngineChannel unique ID for this FxSend instance
48     if (!pEngineChannel->GetFxSendCount()) iId = 0;
49     else {
50     // get the highest existing map ID
51     uint highestIndex = 0;
52     for (uint i = 0; i < pEngineChannel->GetFxSendCount(); i++)
53     highestIndex = RTMath::Max(highestIndex, pEngineChannel->GetFxSend(i)->Id());
54     // check if we reached the index limit
55     if (highestIndex + 1 < highestIndex) {
56     // search for an unoccupied map ID starting from 0
57     for (uint i = 0; i < highestIndex; i++) {
58     bool bOccupied = false;
59     for (uint j = 0; j < pEngineChannel->GetFxSendCount(); j++) {
60     if (pEngineChannel->GetFxSend(j)->Id() == i) {
61     bOccupied = true;
62     break;
63     }
64     }
65     if (!bOccupied) {
66     iId = i;
67     goto __done;
68     }
69     }
70     throw Exception("Internal error: could not find unoccupied FxSend ID.");
71     }
72     iId = highestIndex + 1;
73     }
74     __done:
75    
76 schoenebeck 1040 fLevel = DEFAULT_FX_SEND_LEVEL;
77 schoenebeck 1001 }
78    
79     int FxSend::DestinationChannel(int SrcChan) {
80     if (SrcChan >= pEngineChannel->Channels()) return -1;
81     return Routing[SrcChan];
82     }
83    
84     void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) {
85     if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels())
86     throw Exception("Cannot alter FxSend routing, source channel out of bounds");
87     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
88     if (pDevice) {
89     if (DstChan < 0 || DstChan >= pDevice->ChannelCount())
90     throw Exception("Cannot alter FxSend routing, destination channel out of bounds");
91     } else { // no audio device assigned yet
92     if (DstChan < 0 || DstChan >= pEngineChannel->Channels())
93     throw Exception(
94     "there is no audio device yet, so you cannot set a "
95     "FxSend destination channel higher than the engine "
96     "channel's amount of channels"
97     );
98     }
99     Routing[SrcChan] = DstChan;
100     }
101    
102     void FxSend::UpdateChannels() {
103     if (Routing.size() > pEngineChannel->Channels()) {
104     // add routings with default destinations
105     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
106     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
107     for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) {
108     const int iDestination = iChanOffset + i;
109     Routing.push_back(iDestination);
110     }
111     } else if (Routing.size() < pEngineChannel->Channels()) {
112     // shrink routing vector
113     Routing.resize(pEngineChannel->Channels());
114     }
115     }
116    
117     float FxSend::Level() {
118     return fLevel;
119     }
120    
121     void FxSend::SetLevel(float f) {
122 iliev 1108 if(fLevel == f) return;
123 schoenebeck 1001 fLevel = f;
124 iliev 1108 SetInfoChanged(true);
125 schoenebeck 1001 }
126    
127     void FxSend::SetLevel(uint8_t iMidiValue) {
128     fLevel = float(iMidiValue & 0x7f) / 127.0f;
129 iliev 1108 SetInfoChanged(true);
130 schoenebeck 1001 }
131    
132 schoenebeck 1040 void FxSend::Reset() {
133 iliev 1108 SetLevel(DEFAULT_FX_SEND_LEVEL);
134 schoenebeck 1040 }
135    
136 schoenebeck 1001 uint8_t FxSend::MidiController() {
137     return MidiFxSendController;
138     }
139    
140     void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
141 schoenebeck 1026 if (MidiCtrl >> 7)
142     throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl));
143 schoenebeck 1001 MidiFxSendController = MidiCtrl;
144     }
145    
146     String FxSend::Name() {
147     return sName;
148     }
149    
150 iliev 1135 void FxSend::SetName(String Name) {
151     sName = Name;
152     }
153    
154 schoenebeck 1001 uint FxSend::Id() {
155     return iId;
156     }
157    
158 iliev 1108 void FxSend::SetInfoChanged(bool b) {
159     bInfoChanged = b;
160     }
161    
162     bool FxSend::IsInfoChanged() {
163     return bInfoChanged;
164     }
165    
166 schoenebeck 1001 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC