| 27 | #include "Transport.h" |
| 28 | |
| 29 | juce::Optional<juce::AudioPlayHead::PositionInfo> VSTPlayhead::getPosition() const |
| 30 | { |
| 31 | PositionInfo pos; |
| 32 | juce::AudioPlayHead::TimeSignature timeSignature; |
| 33 | juce::AudioPlayHead::LoopPoints loopPoint; |
| 34 | timeSignature.numerator = TheTransport->GetTimeSigTop(); |
| 35 | timeSignature.denominator = TheTransport->GetTimeSigBottom(); |
| 36 | |
| 37 | juce::Optional<juce::AudioPlayHead::TimeSignature> posTM = pos.getTimeSignature(); |
| 38 | |
| 39 | loopPoint.ppqStart = 0; |
| 40 | loopPoint.ppqEnd = 480; |
| 41 | |
| 42 | if (posTM) |
| 43 | { |
| 44 | loopPoint.ppqEnd *= posTM->denominator; |
| 45 | } |
| 46 | |
| 47 | pos.setBpm(TheTransport->GetTempo()); |
| 48 | pos.setTimeSignature(timeSignature); |
| 49 | pos.setTimeInSamples(int64_t(gTime * gSampleRateMs)); |
| 50 | pos.setTimeInSeconds(gTime / 1000); |
| 51 | |
| 52 | /* |
| 53 | * getMeasureTime is a float of how many measures we are through with fractional |
| 54 | * measures. We want to know the number of quarter notes from the epoch which is |
| 55 | * just the tsRatio times measure count, and for start of measure we simply floor |
| 56 | * the measure time |
| 57 | */ |
| 58 | |
| 59 | double tsRatio = 4; |
| 60 | if (pos.getTimeSignature()->numerator > 0) |
| 61 | tsRatio = 1.0 * pos.getTimeSignature()->numerator / pos.getTimeSignature()->denominator * 4; |
| 62 | pos.setPpqPosition((TheTransport->GetMeasureTime(gTime)) * tsRatio); |
| 63 | pos.setPpqPositionOfLastBarStart(floor(TheTransport->GetMeasureTime(gTime)) * tsRatio); |
| 64 | |
| 65 | pos.setIsPlaying(true); |
| 66 | pos.setIsRecording(false); |
| 67 | pos.setIsLooping(false); |
| 68 | pos.setLoopPoints(loopPoint); |
| 69 | pos.setFrameRate(juce::AudioPlayHead::fps60); |
| 70 | |
| 71 | return pos; |
| 72 | } |
no test coverage detected