|
24 | 24 |
|
25 | 25 | #include "soundbase.h" |
26 | 26 |
|
27 | | -// This is used as a lookup table for parsing option letters, mapping |
28 | | -// a single character to an EMidiCtlType |
29 | | -char const sMidiCtlChar[] = { |
30 | | - // Has to follow order of EMidiCtlType |
31 | | - /* [EMidiCtlType::Fader] = */ 'f', |
32 | | - /* [EMidiCtlType::Pan] = */ 'p', |
33 | | - /* [EMidiCtlType::Solo] = */ 's', |
34 | | - /* [EMidiCtlType::Mute] = */ 'm', |
35 | | - /* [EMidiCtlType::MuteMyself] = */ 'o', |
36 | | - /* [EMidiCtlType::OurFader] = */ 'z', // Proposed addition: a new enum value for "our fader" |
37 | | - /* [EMidiCtlType::None] = */ '\0' }; |
38 | | - |
39 | 27 | /* Implementation *************************************************************/ |
40 | 28 | CSoundBase::CSoundBase ( const QString& strNewSystemDriverTechniqueName, |
41 | 29 | void ( *fpNewProcessCallback ) ( CVector<int16_t>& psData, void* pParg ), |
@@ -233,98 +221,156 @@ QVector<QString> CSoundBase::LoadAndInitializeFirstValidDriver ( const bool bOpe |
233 | 221 | } |
234 | 222 |
|
235 | 223 | /******************************************************************************\ |
236 | | -* MIDI handling * |
| 224 | +* Command Line Handling * |
237 | 225 | \******************************************************************************/ |
238 | 226 | void CSoundBase::ParseCommandLineArgument ( const QString& strMIDISetup ) |
239 | 227 | { |
240 | | - int iMIDIOffsetFader = 70; // Behringer X-TOUCH: offset of 0x46 |
241 | | - |
242 | | - // parse the server info string according to definition: there is |
243 | | - // the legacy definition with just one or two numbers that only |
244 | | - // provides a definition for the controller offset of the level |
245 | | - // controllers (default 70 for the sake of Behringer X-Touch) |
246 | | - // [MIDI channel];[offset for level] |
247 | | - // |
248 | | - // The more verbose new form is a sequence of offsets for various |
249 | | - // controllers: at the current point, 'f', 'p', 's', and 'm' are |
250 | | - // parsed for fader, pan, solo, mute controllers respectively. |
251 | | - // However, at the current point of time only 'f' and 'p' |
252 | | - // controllers are actually implemented. The syntax for a Korg |
253 | | - // nanoKONTROL2 with 8 fader controllers starting at offset 0 and |
254 | | - // 8 pan controllers starting at offset 16 would be |
255 | | - // |
256 | | - // [MIDI channel];f0*8;p16*8 |
257 | | - // |
258 | | - // Namely a sequence of letters indicating the kind of controller, |
259 | | - // followed by the offset of the first such controller, followed |
260 | | - // by * and a count for number of controllers (if more than 1) |
261 | | - if ( !strMIDISetup.isEmpty() ) |
| 228 | + if ( strMIDISetup.isEmpty() ) |
262 | 229 | { |
263 | | - // split the different parameter strings |
264 | | - const QStringList slMIDIParams = strMIDISetup.split ( ";" ); |
| 230 | + // should be caught in main.cpp |
| 231 | + return; |
| 232 | + } |
| 233 | + |
| 234 | + // Parse the --ctrlmidich string. There are two formats. |
| 235 | + // Default to the legacy kind of specifying the fader controller offset |
| 236 | + // without an indication of the count of controllers. |
| 237 | + bool bSimple = true; |
265 | 238 |
|
266 | | - // [MIDI channel] |
267 | | - if ( slMIDIParams.count() >= 1 ) |
| 239 | + // split the different parameter strings |
| 240 | + const QStringList slMIDIParams = strMIDISetup.split ( ";" ); |
| 241 | + int iNumParams = slMIDIParams.count(); |
| 242 | + |
| 243 | + if ( iNumParams >= 1 ) |
| 244 | + { |
| 245 | + bool bChOK = false; |
| 246 | + int i = slMIDIParams[0].toUInt ( &bChOK ); |
| 247 | + if ( bChOK ) |
268 | 248 | { |
269 | | - iCtrlMIDIChannel = slMIDIParams[0].toUInt(); |
| 249 | + // [MIDI channel] supplied (else use default) |
| 250 | + iCtrlMIDIChannel = i; |
270 | 251 | } |
| 252 | + else |
| 253 | + { |
| 254 | + // iCtrlMIDIChannel == INVALID_MIDI_CH, so no point continuing |
| 255 | + return; |
| 256 | + } |
| 257 | + } |
271 | 258 |
|
272 | | - bool bSimple = true; // Indicates the legacy kind of specifying |
273 | | - // the fader controller offset without an |
274 | | - // indication of the count of controllers |
| 259 | + // Use Behringer X-TOUCH as default offset of 0x46 |
| 260 | + int iMIDIOffsetFader = 70; |
| 261 | + if ( iNumParams >= 2 ) |
| 262 | + { |
| 263 | + // if there is a second parameter that can be parsed as a number, |
| 264 | + // we have the legacy specification of controllers. |
| 265 | + int i = slMIDIParams[1].toUInt ( &bSimple ); |
| 266 | + if ( bSimple ) |
| 267 | + { |
| 268 | + // [offset for fader] supplied (else use default) |
| 269 | + iMIDIOffsetFader = i; |
| 270 | + } |
| 271 | + } |
275 | 272 |
|
276 | | - // [offset for level] |
277 | | - if ( slMIDIParams.count() >= 2 ) |
| 273 | + if ( bSimple ) |
| 274 | + { |
| 275 | + // For the legacy specification, we consider every controller |
| 276 | + // up to the maximum number of channels (or the maximum |
| 277 | + // controller number) a fader. |
| 278 | + for ( int i = 0; i + iMIDIOffsetFader <= 127 && i < MAX_NUM_CHANNELS; i++ ) |
278 | 279 | { |
279 | | - int i = slMIDIParams[1].toUInt ( &bSimple ); |
280 | | - // if the second parameter can be parsed as a number, we |
281 | | - // have the legacy specification of controllers. |
282 | | - if ( bSimple ) |
283 | | - iMIDIOffsetFader = i; |
| 280 | + // add a list entry for the CMidiCtlEntry |
| 281 | + aMidiCtls[i + iMIDIOffsetFader] = { EMidiCtlType::Fader, i }; |
284 | 282 | } |
| 283 | + return; |
| 284 | + } |
285 | 285 |
|
286 | | - if ( bSimple ) |
| 286 | + // We have named controllers |
| 287 | + // Validate and see whether "MyChannel" option is present |
| 288 | + |
| 289 | + bool bMyChannel = false; |
| 290 | + QStringList slValid; // keep track of valid entries to make later processing simple |
| 291 | + |
| 292 | + for ( int i = 0; i < iNumParams; i++ ) |
| 293 | + { |
| 294 | + QString sParm = slMIDIParams[i].trimmed(); |
| 295 | + |
| 296 | + if ( sParm.isEmpty() ) |
| 297 | + { |
| 298 | + // skip empty entries silently |
| 299 | + continue; |
| 300 | + } |
| 301 | + |
| 302 | + int iCtrl = sMidiCtl.indexOf ( sParm[0] ); |
| 303 | + if ( iCtrl < 0 ) |
| 304 | + { |
| 305 | + // skip unknown entries silently |
| 306 | + continue; |
| 307 | + } |
| 308 | + |
| 309 | + if ( static_cast<EMidiCtlType> ( iCtrl ) == EMidiCtlType::MyChannel ) |
287 | 310 | { |
288 | | - // For the legacy specification, we consider every controller |
289 | | - // up to the maximum number of channels (or the maximum |
290 | | - // controller number) a fader. |
291 | | - for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) |
| 311 | + // once seen, just remember this |
| 312 | + bMyChannel = true; |
| 313 | + continue; |
| 314 | + } |
| 315 | + |
| 316 | + const QStringList slP = sParm.mid ( 1 ).split ( '*' ); |
| 317 | + |
| 318 | + if ( slP.count() > 2 ) |
| 319 | + { |
| 320 | + // skip invalid entries silently |
| 321 | + continue; |
| 322 | + } |
| 323 | + |
| 324 | + bool bIsUInt = false; |
| 325 | + |
| 326 | + unsigned int u = slP[0].toUInt ( &bIsUInt ); |
| 327 | + if ( !bIsUInt ) |
| 328 | + { |
| 329 | + // skip invalid entries silently |
| 330 | + continue; |
| 331 | + } |
| 332 | + int iFirst = u; |
| 333 | + |
| 334 | + // silently default incoherent count to 1 |
| 335 | + int iNum = 1; |
| 336 | + if ( static_cast<EMidiCtlType> ( iCtrl ) != EMidiCtlType::MuteMyself && slP.count() == 2 ) |
| 337 | + { |
| 338 | + bIsUInt = false; |
| 339 | + unsigned int u = slP[1].toUInt ( &bIsUInt ); |
| 340 | + if ( bIsUInt ) |
292 | 341 | { |
293 | | - if ( i + iMIDIOffsetFader > 127 ) |
294 | | - break; |
295 | | - aMidiCtls[i + iMIDIOffsetFader] = { EMidiCtlType::Fader, i }; |
| 342 | + iNum = u; |
296 | 343 | } |
297 | | - return; |
298 | 344 | } |
299 | 345 |
|
300 | | - // We have named controllers |
| 346 | + // store the valid entry in a more splittable format |
| 347 | + slValid.append ( QString ( "%1*%2*%3" ).arg ( iCtrl ).arg ( iFirst ).arg ( iNum ) ); |
| 348 | + } |
301 | 349 |
|
302 | | - for ( int i = 1; i < slMIDIParams.count(); i++ ) |
| 350 | + foreach ( QString sParm, slValid ) |
| 351 | + { |
| 352 | + const QStringList slP = sParm.split ( '*' ); |
| 353 | + const EMidiCtlType eTyp = static_cast<EMidiCtlType> ( slP[0].toInt() ); |
| 354 | + const int iFirst = slP[1].toUInt(); |
| 355 | + const int iNum = slP[2].toUInt(); |
| 356 | + for ( int iOff = 0; iOff < iNum && iOff + iFirst <= 127 && iOff < MAX_NUM_CHANNELS; iOff++ ) |
303 | 357 | { |
304 | | - QString sParm = slMIDIParams[i].trimmed(); |
305 | | - if ( sParm.isEmpty() ) |
306 | | - continue; |
307 | | - |
308 | | - int iCtrl = QString ( sMidiCtlChar ).indexOf ( sParm[0] ); |
309 | | - if ( iCtrl < 0 ) |
310 | | - continue; |
311 | | - EMidiCtlType eTyp = static_cast<EMidiCtlType> ( iCtrl ); |
312 | | - |
313 | | - const QStringList slP = sParm.mid ( 1 ).split ( '*' ); |
314 | | - int iFirst = slP[0].toUInt(); |
315 | | - int iNum = ( slP.count() > 1 ) ? slP[1].toUInt() : 1; |
316 | | - for ( int iOff = 0; iOff < iNum; iOff++ ) |
| 358 | + // For MyChannel option, first offset is "MyChannel", then the rest are 0 to iNum-1 channels |
| 359 | + if ( bMyChannel ) |
| 360 | + { |
| 361 | + aMidiCtls[iFirst + iOff] = { eTyp, iOff == 0 ? I_MY_CHANNEL : iOff - 1 }; |
| 362 | + } |
| 363 | + else |
317 | 364 | { |
318 | | - if ( iOff >= MAX_NUM_CHANNELS ) |
319 | | - break; |
320 | | - if ( iFirst + iOff >= 128 ) |
321 | | - break; |
322 | 365 | aMidiCtls[iFirst + iOff] = { eTyp, iOff }; |
323 | 366 | } |
324 | 367 | } |
325 | 368 | } |
326 | 369 | } |
327 | 370 |
|
| 371 | +/******************************************************************************\ |
| 372 | +* MIDI handling * |
| 373 | +\******************************************************************************/ |
328 | 374 | void CSoundBase::ParseMIDIMessage ( const CVector<uint8_t>& vMIDIPaketBytes ) |
329 | 375 | { |
330 | 376 | if ( vMIDIPaketBytes.Size() > 0 ) |
@@ -357,22 +403,22 @@ void CSoundBase::ParseMIDIMessage ( const CVector<uint8_t>& vMIDIPaketBytes ) |
357 | 403 | // make sure packet is long enough |
358 | 404 | if ( vMIDIPaketBytes.Size() > 2 && vMIDIPaketBytes[1] <= uint8_t ( 127 ) && vMIDIPaketBytes[2] <= uint8_t ( 127 ) ) |
359 | 405 | { |
| 406 | + // Where "MyChannel" is in effect, cCtrl.iChannel will be I_MY_CHANNEL |
| 407 | + // for the first CC number in the range for a cCtrl.eType and then zero upwards. |
360 | 408 | const CMidiCtlEntry& cCtrl = aMidiCtls[vMIDIPaketBytes[1]]; |
361 | 409 | const int iValue = vMIDIPaketBytes[2]; |
362 | | - ; |
| 410 | + |
363 | 411 | switch ( cCtrl.eType ) |
364 | 412 | { |
365 | 413 | case Fader: |
366 | | - case OurFader: |
367 | 414 | { |
368 | 415 | // we are assuming that the controller number is the same |
369 | 416 | // as the audio fader index and the range is 0-127 |
370 | 417 | const int iFaderLevel = static_cast<int> ( static_cast<double> ( iValue ) / 127 * AUD_MIX_FADER_MAX ); |
371 | | - const int iTheChannel = cCtrl.eType == OurFader ? I_MY_CHANNEL : cCtrl.iChannel; |
372 | 418 |
|
373 | 419 | // consider offset for the faders |
374 | 420 |
|
375 | | - emit ControllerInFaderLevel ( iTheChannel, iFaderLevel ); |
| 421 | + emit ControllerInFaderLevel ( cCtrl.iChannel, iFaderLevel ); |
376 | 422 | } |
377 | 423 | break; |
378 | 424 | case Pan: |
|
0 commit comments