Skip to content

Commit 7e69363

Browse files
committed
Fix issues
1 parent 71207b0 commit 7e69363

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

modules/yup_audio_basics/midi/yup_MidiFile.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,22 @@ void MidiFile::setTicksPerQuarterNote (int ticks) noexcept
340340

341341
void MidiFile::setSmpteTimeFormat (int framesPerSecond, int subframeResolution) noexcept
342342
{
343-
timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
343+
switch (framesPerSecond)
344+
{
345+
case 24:
346+
case 25:
347+
case 29:
348+
case 30:
349+
break;
350+
351+
default:
352+
framesPerSecond = 25;
353+
break;
354+
}
355+
356+
const int8 smpteByte = static_cast<int8> (-framesPerSecond);
357+
358+
timeFormat = static_cast<int16> ((static_cast<uint8> (smpteByte) << 8) | static_cast<uint8> (subframeResolution));
344359
}
345360

346361
//==============================================================================

modules/yup_audio_devices/native/yup_CoreAudio_mac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ struct CoreAudioClasses
11581158
{
11591159
auto& intern = *static_cast<CoreAudioInternal*> (inClientData);
11601160

1161-
const auto xruns = std::count_if (pa, pa + numAddresses, [] (const AudioObjectPropertyAddress& x)
1161+
const auto xruns = (int) std::count_if (pa, pa + numAddresses, [] (const AudioObjectPropertyAddress& x)
11621162
{
11631163
return x.mSelector == kAudioDeviceProcessorOverload;
11641164
});

modules/yup_events/timers/yup_Timer.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Timer::TimerThread final : private Thread
134134
break;
135135

136136
auto* timer = first.timer;
137-
first.countdownMs = timer->timerPeriodMs;
137+
first.countdownMs = timer->getTimerInterval();
138138
shuffleTimerBackInQueue (0);
139139
notify();
140140

@@ -175,7 +175,7 @@ class Timer::TimerThread final : private Thread
175175

176176
auto pos = timers.size();
177177

178-
timers.push_back ({ t, t->timerPeriodMs });
178+
timers.push_back ({ t, t->getTimerInterval() });
179179
t->positionInQueue = pos;
180180
shuffleTimerForwardInQueue (pos);
181181
notify();
@@ -210,7 +210,7 @@ class Timer::TimerThread final : private Thread
210210
jassert (timers[pos].timer == t);
211211

212212
auto lastCountdown = timers[pos].countdownMs;
213-
auto newCountdown = t->timerPeriodMs;
213+
auto newCountdown = t->getTimerInterval();
214214

215215
if (newCountdown != lastCountdown)
216216
{
@@ -350,10 +350,7 @@ void Timer::startTimer (int interval) noexcept
350350

351351
if (auto* instance = TimerThread::getInstance())
352352
{
353-
bool wasStopped = (timerPeriodMs == 0);
354-
timerPeriodMs = jmax (1, interval);
355-
356-
if (wasStopped)
353+
if (timerPeriodMs.exchange (jmax (1, interval)) == 0)
357354
instance->addTimer (this);
358355
else
359356
instance->resetTimerCounter (this);

modules/yup_events/timers/yup_Timer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ class YUP_API Timer
125125

126126
//==============================================================================
127127
/** Returns true if the timer is currently running. */
128-
bool isTimerRunning() const noexcept { return timerPeriodMs > 0; }
128+
bool isTimerRunning() const noexcept { return getTimerInterval() > 0; }
129129

130130
/** Returns the timer's interval.
131+
131132
@returns the timer's interval in milliseconds if it's running, or 0 if it's not.
132133
*/
133-
int getTimerInterval() const noexcept { return timerPeriodMs; }
134+
int getTimerInterval() const noexcept { return timerPeriodMs.load (std::memory_order_relaxed); }
134135

135136
//==============================================================================
136137
/** Invokes a lambda after a given number of milliseconds. */
@@ -143,7 +144,7 @@ class YUP_API Timer
143144
private:
144145
class TimerThread;
145146
size_t positionInQueue = (size_t) -1;
146-
int timerPeriodMs = 0;
147+
std::atomic<int> timerPeriodMs = 0;
147148

148149
Timer& operator= (const Timer&) = delete;
149150
};

tests/yup_audio_basics/yup_MidiFile.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,14 @@ TEST_F (MidiFileTest, TimeFormatGetSet)
214214
EXPECT_EQ (file.getTimeFormat(), 96);
215215

216216
// Test SMPTE format
217-
file.setSmpteTimeFormat (24, 8);
218-
//EXPECT_EQ(file.getTimeFormat(), (short)(((-24) << 8) | 8));
217+
file.setSmpteTimeFormat (24, 4);
218+
EXPECT_EQ (file.getTimeFormat(), -6140);
219+
220+
file.setSmpteTimeFormat (25, 40);
221+
EXPECT_EQ (file.getTimeFormat(), -6360);
219222

220-
file.setSmpteTimeFormat (30, 10);
221-
//EXPECT_EQ(file.getTimeFormat(), (short)(((-30) << 8) | 10));
223+
file.setSmpteTimeFormat (26, 40);
224+
EXPECT_EQ (file.getTimeFormat(), -6360);
222225
}
223226

224227
TEST_F (MidiFileTest, ReadFromValidStream)

0 commit comments

Comments
 (0)