/[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 1135 - (hide annotations) (download)
Thu Mar 29 09:40:45 2007 UTC (17 years ago) by iliev
File size: 6590 byte(s)
* Added new LSCP command - SET FX_SEND NAME
* The default map is now the first available map

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     #include "../drivers/audio/AudioOutputDevice.h"
27 schoenebeck 1017 #include "../common/RTMath.h"
28 schoenebeck 1001
29     #include <map>
30    
31 schoenebeck 1040 #define DEFAULT_FX_SEND_LEVEL 0.0f
32    
33 schoenebeck 1001 namespace LinuxSampler {
34    
35 schoenebeck 1017 FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception) {
36 schoenebeck 1001 this->pEngineChannel = pEngineChannel;
37     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
38     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
39     for (int i = 0; i < pEngineChannel->Channels(); i++) {
40     const int iDestination = iChanOffset + i;
41     Routing.push_back(iDestination);
42     }
43 schoenebeck 1026 SetMidiController(MidiCtrl);
44 schoenebeck 1001 sName = Name;
45 schoenebeck 1017
46     // create an EngineChannel unique ID for this FxSend instance
47     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 schoenebeck 1040 fLevel = DEFAULT_FX_SEND_LEVEL;
76 schoenebeck 1001 }
77    
78     int FxSend::DestinationChannel(int SrcChan) {
79     if (SrcChan >= pEngineChannel->Channels()) return -1;
80     return Routing[SrcChan];
81     }
82    
83     void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) {
84     if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels())
85     throw Exception("Cannot alter FxSend routing, source channel out of bounds");
86     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
87     if (pDevice) {
88     if (DstChan < 0 || DstChan >= pDevice->ChannelCount())
89     throw Exception("Cannot alter FxSend routing, destination channel out of bounds");
90     } else { // no audio device assigned yet
91     if (DstChan < 0 || DstChan >= pEngineChannel->Channels())
92     throw Exception(
93     "there is no audio device yet, so you cannot set a "
94     "FxSend destination channel higher than the engine "
95     "channel's amount of channels"
96     );
97     }
98     Routing[SrcChan] = DstChan;
99     }
100    
101     void FxSend::UpdateChannels() {
102     if (Routing.size() > pEngineChannel->Channels()) {
103     // add routings with default destinations
104     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
105     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
106     for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) {
107     const int iDestination = iChanOffset + i;
108     Routing.push_back(iDestination);
109     }
110     } else if (Routing.size() < pEngineChannel->Channels()) {
111     // shrink routing vector
112     Routing.resize(pEngineChannel->Channels());
113     }
114     }
115    
116     float FxSend::Level() {
117     return fLevel;
118     }
119    
120     void FxSend::SetLevel(float f) {
121 iliev 1108 if(fLevel == f) return;
122 schoenebeck 1001 fLevel = f;
123 iliev 1108 SetInfoChanged(true);
124 schoenebeck 1001 }
125    
126     void FxSend::SetLevel(uint8_t iMidiValue) {
127     fLevel = float(iMidiValue & 0x7f) / 127.0f;
128 iliev 1108 SetInfoChanged(true);
129 schoenebeck 1001 }
130    
131 schoenebeck 1040 void FxSend::Reset() {
132 iliev 1108 SetLevel(DEFAULT_FX_SEND_LEVEL);
133 schoenebeck 1040 }
134    
135 schoenebeck 1001 uint8_t FxSend::MidiController() {
136     return MidiFxSendController;
137     }
138    
139     void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
140 schoenebeck 1026 if (MidiCtrl >> 7)
141     throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl));
142 schoenebeck 1001 MidiFxSendController = MidiCtrl;
143     }
144    
145     String FxSend::Name() {
146     return sName;
147     }
148    
149 iliev 1135 void FxSend::SetName(String Name) {
150     sName = Name;
151     }
152    
153 schoenebeck 1001 uint FxSend::Id() {
154     return iId;
155     }
156    
157 iliev 1108 void FxSend::SetInfoChanged(bool b) {
158     bInfoChanged = b;
159     }
160    
161     bool FxSend::IsInfoChanged() {
162     return bInfoChanged;
163     }
164    
165 schoenebeck 1001 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC