fixing MidiClock (Zwischenstand #2)
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "JK_MidiClock.h"
|
#include "JK_MidiClock.h"
|
||||||
#include "juce_core/maths/juce_MathsFunctions.h"
|
#include "juce_core/maths/juce_MathsFunctions.h"
|
||||||
|
#include <cmath>
|
||||||
#include <synth/synth_defs.h>
|
#include <synth/synth_defs.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +32,6 @@ JK_MidiClock::JK_MidiClock()
|
|||||||
m_clockMessage = new MidiMessage(MidiMessage::midiClock());
|
m_clockMessage = new MidiMessage(MidiMessage::midiClock());
|
||||||
m_songPositionMessage = new MidiMessage(MidiMessage::songPositionPointer(0));
|
m_songPositionMessage = new MidiMessage(MidiMessage::songPositionPointer(0));
|
||||||
m_last_sample_pos_sync = 0;
|
m_last_sample_pos_sync = 0;
|
||||||
m_last_sample_pos_sync = 0;
|
|
||||||
m_syncSamplePos = 0;
|
m_syncSamplePos = 0;
|
||||||
}
|
}
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
@@ -111,7 +111,7 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
const double hostSamplePos_f = hostPpqPosition * quant;
|
const double hostSamplePos_f = hostPpqPosition * quant;
|
||||||
|
|
||||||
double syncSamplePos_f = hostSamplePos_f;
|
double syncSamplePos_f = hostSamplePos_f;
|
||||||
int64 syncSamplePos = roundToInt64(syncSamplePos_f);
|
int64 syncSamplePos = (int64)std::round(syncSamplePos_f);
|
||||||
double sample_offset = syncSamplePos_f - m_syncSamplePos;
|
double sample_offset = syncSamplePos_f - m_syncSamplePos;
|
||||||
|
|
||||||
for (int posInBuffer = 0; posInBuffer < bufferSize; ++posInBuffer)
|
for (int posInBuffer = 0; posInBuffer < bufferSize; ++posInBuffer)
|
||||||
@@ -156,11 +156,11 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
//to Midiclock even if they are in stop mode.
|
//to Midiclock even if they are in stop mode.
|
||||||
double sample_pos = (double)posInBuffer + sample_offset;
|
double sample_pos = (double)posInBuffer + sample_offset;
|
||||||
double distance = fabs(syncSamplePos_f-m_last_sample_pos_sync);
|
double distance = fabs(syncSamplePos_f-m_last_sample_pos_sync);
|
||||||
// SynthDebug("Distance: %f", distance);
|
|
||||||
// SynthDebug("Quant: %f", quant);
|
|
||||||
// if (fabs(distance - clockDistanceInSamples) < quant and sample_pos >= 0)
|
|
||||||
if ((syncSamplePos % clockDistanceInSamples) == 0 and sample_pos >= 0)
|
if ((syncSamplePos % clockDistanceInSamples) == 0 and sample_pos >= 0)
|
||||||
{
|
{
|
||||||
|
SynthDebug("Distance : %f", distance);
|
||||||
|
SynthDebug("syncSamplePos_f: %f", syncSamplePos_f);
|
||||||
|
SynthDebug("sample_offset : %f", sample_offset);
|
||||||
// SynthDebug("MidiClock at Sample Sync: %d | PPQ Host: %f | PPQ Sync: %f", syncSamplePos-m_last_sample_pos_sync, hostPpqPosition-m_last_ppq_pos_host, m_syncPpqPosition-m_last_syncPpqPosition);
|
// SynthDebug("MidiClock at Sample Sync: %d | PPQ Host: %f | PPQ Sync: %f", syncSamplePos-m_last_sample_pos_sync, hostPpqPosition-m_last_ppq_pos_host, m_syncPpqPosition-m_last_syncPpqPosition);
|
||||||
SynthDebug("MidiClock at Sample Sync: %f, diff %f", sample_pos, syncSamplePos_f-m_last_sample_pos_sync);
|
SynthDebug("MidiClock at Sample Sync: %f, diff %f", sample_pos, syncSamplePos_f-m_last_sample_pos_sync);
|
||||||
m_last_sample_pos_sync = syncSamplePos_f;
|
m_last_sample_pos_sync = syncSamplePos_f;
|
||||||
@@ -169,6 +169,7 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
midiBuffer->addEvent(*m_clockMessage, roundToInt(sample_pos));
|
midiBuffer->addEvent(*m_clockMessage, roundToInt(sample_pos));
|
||||||
}
|
}
|
||||||
m_syncSamplePos = ++syncSamplePos;
|
m_syncSamplePos = ++syncSamplePos;
|
||||||
|
syncSamplePos_f += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_wasPlaying = true;
|
m_wasPlaying = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user