1 |
schoenebeck |
1001 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
|
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
|
|
* * |
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 |
|
|
|
28 |
|
|
#include <map> |
29 |
|
|
|
30 |
|
|
namespace LinuxSampler { |
31 |
|
|
|
32 |
|
|
/* |
33 |
|
|
FIXME: we create fx send indeces globally for now, although we might |
34 |
|
|
want them to be an individual sequence per sampler channel, beside that |
35 |
|
|
we don't handle the cases yet where __indexer overflows back to 0 |
36 |
|
|
*/ |
37 |
|
|
static uint __indexer = 0; |
38 |
|
|
|
39 |
|
|
FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) { |
40 |
|
|
this->pEngineChannel = pEngineChannel; |
41 |
|
|
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
42 |
|
|
const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0; |
43 |
|
|
for (int i = 0; i < pEngineChannel->Channels(); i++) { |
44 |
|
|
const int iDestination = iChanOffset + i; |
45 |
|
|
Routing.push_back(iDestination); |
46 |
|
|
} |
47 |
|
|
MidiFxSendController = MidiCtrl; |
48 |
|
|
sName = Name; |
49 |
|
|
iId = __indexer; |
50 |
|
|
__indexer++; |
51 |
|
|
fLevel = 0.3f; // default FX send level |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
int FxSend::DestinationChannel(int SrcChan) { |
55 |
|
|
if (SrcChan >= pEngineChannel->Channels()) return -1; |
56 |
|
|
return Routing[SrcChan]; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) { |
60 |
|
|
if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels()) |
61 |
|
|
throw Exception("Cannot alter FxSend routing, source channel out of bounds"); |
62 |
|
|
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
63 |
|
|
if (pDevice) { |
64 |
|
|
if (DstChan < 0 || DstChan >= pDevice->ChannelCount()) |
65 |
|
|
throw Exception("Cannot alter FxSend routing, destination channel out of bounds"); |
66 |
|
|
} else { // no audio device assigned yet |
67 |
|
|
if (DstChan < 0 || DstChan >= pEngineChannel->Channels()) |
68 |
|
|
throw Exception( |
69 |
|
|
"there is no audio device yet, so you cannot set a " |
70 |
|
|
"FxSend destination channel higher than the engine " |
71 |
|
|
"channel's amount of channels" |
72 |
|
|
); |
73 |
|
|
} |
74 |
|
|
Routing[SrcChan] = DstChan; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
void FxSend::UpdateChannels() { |
78 |
|
|
if (Routing.size() > pEngineChannel->Channels()) { |
79 |
|
|
// add routings with default destinations |
80 |
|
|
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
81 |
|
|
const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0; |
82 |
|
|
for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) { |
83 |
|
|
const int iDestination = iChanOffset + i; |
84 |
|
|
Routing.push_back(iDestination); |
85 |
|
|
} |
86 |
|
|
} else if (Routing.size() < pEngineChannel->Channels()) { |
87 |
|
|
// shrink routing vector |
88 |
|
|
Routing.resize(pEngineChannel->Channels()); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
float FxSend::Level() { |
93 |
|
|
return fLevel; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
void FxSend::SetLevel(float f) { |
97 |
|
|
fLevel = f; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
void FxSend::SetLevel(uint8_t iMidiValue) { |
101 |
|
|
fLevel = float(iMidiValue & 0x7f) / 127.0f; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
uint8_t FxSend::MidiController() { |
105 |
|
|
return MidiFxSendController; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) { |
109 |
|
|
if (MidiCtrl & 0x7f) |
110 |
|
|
throw Exception("Invalid MIDI controller"); |
111 |
|
|
MidiFxSendController = MidiCtrl; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
String FxSend::Name() { |
115 |
|
|
return sName; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
uint FxSend::Id() { |
119 |
|
|
return iId; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
} // namespace LinuxSampler |