163 |
* @see PrepareLoadInstrument() |
* @see PrepareLoadInstrument() |
164 |
*/ |
*/ |
165 |
void EngineChannel::LoadInstrument() { |
void EngineChannel::LoadInstrument() { |
166 |
|
::gig::Instrument* oldInstrument = pInstrument; |
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
|
|
|
ResetInternal(); |
|
167 |
|
|
168 |
// free old instrument |
// free old instrument |
169 |
if (pInstrument) { |
if (oldInstrument) { |
170 |
// give old instrument back to instrument manager |
if (pEngine) { |
171 |
Engine::instruments.HandBack(pInstrument, this); |
// make sure we don't trigger any new notes with the |
172 |
|
// old instrument |
173 |
|
::gig::DimensionRegion** dimRegionsInUse = pEngine->ChangeInstrument(this, 0); |
174 |
|
|
175 |
|
// give old instrument back to instrument manager, but |
176 |
|
// keep the dimension regions and samples that are in |
177 |
|
// use |
178 |
|
Engine::instruments.HandBackInstrument(oldInstrument, this, dimRegionsInUse); |
179 |
|
} else { |
180 |
|
Engine::instruments.HandBack(oldInstrument, this); |
181 |
|
} |
182 |
} |
} |
183 |
|
|
184 |
// delete all key groups |
// delete all key groups |
185 |
ActiveKeyGroups.clear(); |
ActiveKeyGroups.clear(); |
186 |
|
|
187 |
// request gig instrument from instrument manager |
// request gig instrument from instrument manager |
188 |
|
::gig::Instrument* newInstrument; |
189 |
try { |
try { |
190 |
InstrumentManager::instrument_id_t instrid; |
InstrumentManager::instrument_id_t instrid; |
191 |
instrid.FileName = InstrumentFile; |
instrid.FileName = InstrumentFile; |
192 |
instrid.Index = InstrumentIdx; |
instrid.Index = InstrumentIdx; |
193 |
pInstrument = Engine::instruments.Borrow(instrid, this); |
newInstrument = Engine::instruments.Borrow(instrid, this); |
194 |
if (!pInstrument) { |
if (!newInstrument) { |
195 |
InstrumentStat = -1; |
InstrumentStat = -1; |
196 |
dmsg(1,("no instrument loaded!!!\n")); |
dmsg(1,("no instrument loaded!!!\n")); |
197 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
213 |
} |
} |
214 |
|
|
215 |
// rebuild ActiveKeyGroups map with key groups of current instrument |
// rebuild ActiveKeyGroups map with key groups of current instrument |
216 |
for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion()) |
for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion()) |
217 |
if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL; |
if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL; |
218 |
|
|
219 |
InstrumentIdxName = pInstrument->pInfo->Name; |
InstrumentIdxName = newInstrument->pInfo->Name; |
220 |
InstrumentStat = 100; |
InstrumentStat = 100; |
221 |
|
|
222 |
// inform audio driver for the need of two channels |
if (pEngine) pEngine->ChangeInstrument(this, newInstrument); |
223 |
try { |
else pInstrument = newInstrument; |
|
if (pEngine && pEngine->pAudioOutputDevice) |
|
|
pEngine->pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo |
|
|
} |
|
|
catch (AudioOutputException e) { |
|
|
String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message(); |
|
|
throw Exception(msg); |
|
|
} |
|
|
|
|
|
if (pEngine) pEngine->Enable(); |
|
224 |
} |
} |
225 |
|
|
226 |
/** |
/** |
281 |
pChannelLeft = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle()); |
pChannelLeft = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle()); |
282 |
pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle()); |
pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle()); |
283 |
} |
} |
284 |
|
pEngine->Enable(); |
285 |
MidiInputPort::AddSysexListener(pEngine); |
MidiInputPort::AddSysexListener(pEngine); |
286 |
} |
} |
287 |
|
|
629 |
Pitch = 0; |
Pitch = 0; |
630 |
SustainPedal = false; |
SustainPedal = false; |
631 |
SostenutoPedal = false; |
SostenutoPedal = false; |
632 |
GlobalVolume = CONFIG_GLOBAL_ATTENUATION; |
GlobalVolume = 1.0f; |
633 |
MidiVolume = 1.0; |
MidiVolume = 1.0; |
634 |
GlobalPanLeft = 1.0f; |
GlobalPanLeft = 1.0f; |
635 |
GlobalPanRight = 1.0f; |
GlobalPanRight = 1.0f; |