| 366 | } |
| 367 | |
| 368 | int Transport::GetQuantized(double time, const TransportListenerInfo* listenerInfo, double* remainderMs /*=nullptr*/) |
| 369 | { |
| 370 | double offsetMs; |
| 371 | if (listenerInfo->mOffsetInfo.mOffsetIsInMs) |
| 372 | offsetMs = listenerInfo->mOffsetInfo.mOffset; |
| 373 | else |
| 374 | offsetMs = listenerInfo->mOffsetInfo.mOffset * MsPerBar(); |
| 375 | time += offsetMs; |
| 376 | |
| 377 | int measure = GetMeasure(time); |
| 378 | double measurePos = GetMeasurePos(time); |
| 379 | double pos = Swing(measurePos); |
| 380 | |
| 381 | //TODO(Ryan) it seems like most of these cases below could be collapsed into a single case |
| 382 | //(but there will probably be fallout that needs to be fixed up in various places) |
| 383 | //changing GetQuantized() to return an unclamped range across the board seems like the right way to go |
| 384 | NoteInterval interval = listenerInfo->mInterval; |
| 385 | switch (interval) |
| 386 | { |
| 387 | case kInterval_1n: |
| 388 | case kInterval_2: |
| 389 | case kInterval_3: |
| 390 | case kInterval_4: |
| 391 | case kInterval_8: |
| 392 | case kInterval_16: |
| 393 | case kInterval_32: |
| 394 | case kInterval_64: |
| 395 | { |
| 396 | pos *= double(mTimeSigTop) / mTimeSigBottom; |
| 397 | int ret = measure / (int)GetMeasureFraction(interval); |
| 398 | if (remainderMs != nullptr) |
| 399 | *remainderMs = (pos + measure % (int)GetMeasureFraction(interval)) * MsPerBar(); |
| 400 | return ret; //unclamped |
| 401 | } |
| 402 | case kInterval_None: |
| 403 | interval = kInterval_16n; //just pick some default value |
| 404 | [[fallthrough]]; |
| 405 | case kInterval_2n: |
| 406 | case kInterval_2nt: |
| 407 | case kInterval_4n: |
| 408 | case kInterval_4nt: |
| 409 | case kInterval_8n: |
| 410 | case kInterval_8nt: |
| 411 | case kInterval_16n: |
| 412 | case kInterval_16nt: |
| 413 | case kInterval_32n: |
| 414 | case kInterval_32nt: |
| 415 | case kInterval_64n: |
| 416 | { |
| 417 | pos *= double(mTimeSigTop) / mTimeSigBottom; |
| 418 | double ret = pos * CountInStandardMeasure(interval); |
| 419 | if (remainderMs != nullptr) |
| 420 | { |
| 421 | double remainder = ret - (int)ret; |
| 422 | if (mSwing == .5f) |
| 423 | *remainderMs = remainder * GetDuration(interval); |
| 424 | else |
| 425 | *remainderMs = 0; //TODO(Ryan) this is incorrect, figure out how to properly calculate remainderMs when swing is applied |