/[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 1017 - (hide annotations) (download)
Tue Jan 9 23:51:32 2007 UTC (17 years, 3 months ago) by schoenebeck
File size: 6159 byte(s)
* create IDs for FX Send entities in a logical sequence on a per sampler
  channel basis

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     namespace LinuxSampler {
32    
33 schoenebeck 1017 FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception) {
34 schoenebeck 1001 this->pEngineChannel = pEngineChannel;
35     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
36     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
37     for (int i = 0; i < pEngineChannel->Channels(); i++) {
38     const int iDestination = iChanOffset + i;
39     Routing.push_back(iDestination);
40     }
41     MidiFxSendController = MidiCtrl;
42     sName = Name;
43 schoenebeck 1017
44     // create an EngineChannel unique ID for this FxSend instance
45     if (!pEngineChannel->GetFxSendCount()) iId = 0;
46     else {
47     // get the highest existing map ID
48     uint highestIndex = 0;
49     for (uint i = 0; i < pEngineChannel->GetFxSendCount(); i++)
50     highestIndex = RTMath::Max(highestIndex, pEngineChannel->GetFxSend(i)->Id());
51     // check if we reached the index limit
52     if (highestIndex + 1 < highestIndex) {
53     // search for an unoccupied map ID starting from 0
54     for (uint i = 0; i < highestIndex; i++) {
55     bool bOccupied = false;
56     for (uint j = 0; j < pEngineChannel->GetFxSendCount(); j++) {
57     if (pEngineChannel->GetFxSend(j)->Id() == i) {
58     bOccupied = true;
59     break;
60     }
61     }
62     if (!bOccupied) {
63     iId = i;
64     goto __done;
65     }
66     }
67     throw Exception("Internal error: could not find unoccupied FxSend ID.");
68     }
69     iId = highestIndex + 1;
70     }
71     __done:
72    
73 schoenebeck 1001 fLevel = 0.3f; // default FX send level
74     }
75    
76     int FxSend::DestinationChannel(int SrcChan) {
77     if (SrcChan >= pEngineChannel->Channels()) return -1;
78     return Routing[SrcChan];
79     }
80    
81     void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) {
82     if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels())
83     throw Exception("Cannot alter FxSend routing, source channel out of bounds");
84     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
85     if (pDevice) {
86     if (DstChan < 0 || DstChan >= pDevice->ChannelCount())
87     throw Exception("Cannot alter FxSend routing, destination channel out of bounds");
88     } else { // no audio device assigned yet
89     if (DstChan < 0 || DstChan >= pEngineChannel->Channels())
90     throw Exception(
91     "there is no audio device yet, so you cannot set a "
92     "FxSend destination channel higher than the engine "
93     "channel's amount of channels"
94     );
95     }
96     Routing[SrcChan] = DstChan;
97     }
98    
99     void FxSend::UpdateChannels() {
100     if (Routing.size() > pEngineChannel->Channels()) {
101     // add routings with default destinations
102     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
103     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
104     for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) {
105     const int iDestination = iChanOffset + i;
106     Routing.push_back(iDestination);
107     }
108     } else if (Routing.size() < pEngineChannel->Channels()) {
109     // shrink routing vector
110     Routing.resize(pEngineChannel->Channels());
111     }
112     }
113    
114     float FxSend::Level() {
115     return fLevel;
116     }
117    
118     void FxSend::SetLevel(float f) {
119     fLevel = f;
120     }
121    
122     void FxSend::SetLevel(uint8_t iMidiValue) {
123     fLevel = float(iMidiValue & 0x7f) / 127.0f;
124     }
125    
126     uint8_t FxSend::MidiController() {
127     return MidiFxSendController;
128     }
129    
130     void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
131     if (MidiCtrl & 0x7f)
132     throw Exception("Invalid MIDI controller");
133     MidiFxSendController = MidiCtrl;
134     }
135    
136     String FxSend::Name() {
137     return sName;
138     }
139    
140     uint FxSend::Id() {
141     return iId;
142     }
143    
144     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC