mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 11:14:00 +00:00
Hook up new Fwd/Rev system
This commit is contained in:
parent
61fffbe00c
commit
f083ae9857
File diff suppressed because it is too large
Load Diff
|
@ -598,35 +598,12 @@
|
||||||
|
|
||||||
- (IBAction) playMusic:(id)sender
|
- (IBAction) playMusic:(id)sender
|
||||||
{
|
{
|
||||||
const float kUpScale = 1.41f;
|
|
||||||
const float kDownScale = 1.0f/kUpScale;
|
|
||||||
bool nowPlaying = VLSoundOut::Instance()->Playing();
|
|
||||||
const float tempoRate = [songTempo floatValue] / baseTempo;
|
|
||||||
switch (int tag = [sender tag]) {
|
switch (int tag = [sender tag]) {
|
||||||
case 0: // Play
|
|
||||||
VLSoundOut::Instance()->SetPlayRate(playRate = 1.0f);
|
|
||||||
if (!hasMusicSequence || !nowPlaying)
|
|
||||||
[self play:sender];
|
|
||||||
else if (VLSoundOut::Instance()->AtEnd())
|
|
||||||
VLSoundOut::Instance()->SetTime(0);
|
|
||||||
break;
|
|
||||||
case 1: // Fwd
|
case 1: // Fwd
|
||||||
|
VLSoundOut::Instance()->Fwd();
|
||||||
|
break;
|
||||||
case -1: // Rew
|
case -1: // Rew
|
||||||
if (tag * playRate < 0)
|
VLSoundOut::Instance()->Bck();
|
||||||
playRate = tag;
|
|
||||||
else if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
|
|
||||||
playRate *= kDownScale;
|
|
||||||
else
|
|
||||||
playRate *= kUpScale;
|
|
||||||
VLSoundOut::Instance()->SetPlayRate(playRate*tempoRate);
|
|
||||||
break;
|
|
||||||
case -2: // To Start
|
|
||||||
if (playRate < 0)
|
|
||||||
VLSoundOut::Instance()->SetPlayRate(playRate = -playRate);
|
|
||||||
VLSoundOut::Instance()->SetTime(0);
|
|
||||||
break;
|
|
||||||
case 2: // To End
|
|
||||||
VLSoundOut::Instance()->SetTime(0x7FFFFFFF);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <dispatch/dispatch.h>
|
||||||
|
|
||||||
#define R(x) if (OSStatus r = (x)) fprintf(stderr, "%s -> %ld\n", #x, r);
|
#define R(x) if (OSStatus r = (x)) fprintf(stderr, "%s -> %d\n", #x, r);
|
||||||
|
|
||||||
class VLAUSoundOut : public VLSoundOut {
|
class VLAUSoundOut : public VLSoundOut {
|
||||||
public:
|
public:
|
||||||
|
@ -31,7 +32,8 @@ public:
|
||||||
virtual bool Playing();
|
virtual bool Playing();
|
||||||
virtual bool AtEnd();
|
virtual bool AtEnd();
|
||||||
virtual void SetPlayRate(float rate);
|
virtual void SetPlayRate(float rate);
|
||||||
virtual void SetTime(MusicTimeStamp time);
|
virtual void Fwd();
|
||||||
|
virtual void Bck();
|
||||||
|
|
||||||
virtual ~VLAUSoundOut();
|
virtual ~VLAUSoundOut();
|
||||||
protected:
|
protected:
|
||||||
|
@ -40,6 +42,7 @@ protected:
|
||||||
void InitSoundOutput(bool fileOutput);
|
void InitSoundOutput(bool fileOutput);
|
||||||
virtual void SetupOutput(AUNode outputNode);
|
virtual void SetupOutput(AUNode outputNode);
|
||||||
MusicTimeStamp SequenceLength(MusicSequence music);
|
MusicTimeStamp SequenceLength(MusicSequence music);
|
||||||
|
void SkipTimeInterval();
|
||||||
|
|
||||||
AUGraph fGraph;
|
AUGraph fGraph;
|
||||||
MusicPlayer fPlayer;
|
MusicPlayer fPlayer;
|
||||||
|
@ -217,9 +220,41 @@ void VLAUSoundOut::SetPlayRate(float rate)
|
||||||
MusicPlayerSetPlayRateScalar(fPlayer, fabsf(rate));
|
MusicPlayerSetPlayRateScalar(fPlayer, fabsf(rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VLAUSoundOut::SetTime(MusicTimeStamp time)
|
static MusicTimeStamp sLastSkip = 0.0;
|
||||||
|
static dispatch_source_t sResetTimer;
|
||||||
|
|
||||||
|
void VLAUSoundOut::SkipTimeInterval()
|
||||||
{
|
{
|
||||||
MusicPlayerSetTime(fPlayer, time);
|
MusicTimeStamp time;
|
||||||
|
MusicPlayerGetTime(fPlayer, &time);
|
||||||
|
time += sLastSkip;
|
||||||
|
sLastSkip *= 1.1;
|
||||||
|
if (!sResetTimer) {
|
||||||
|
sResetTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
|
||||||
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
|
||||||
|
dispatch_source_set_event_handler(sResetTimer, ^{
|
||||||
|
sLastSkip = 0.0;
|
||||||
|
});
|
||||||
|
dispatch_source_set_timer(sResetTimer, DISPATCH_TIME_FOREVER, INT64_MAX, 1000*NSEC_PER_USEC);
|
||||||
|
dispatch_resume(sResetTimer);
|
||||||
|
}
|
||||||
|
dispatch_source_set_timer(sResetTimer, dispatch_time(DISPATCH_TIME_NOW, 500*NSEC_PER_MSEC),
|
||||||
|
INT64_MAX, 10*NSEC_PER_MSEC);
|
||||||
|
MusicPlayerSetTime(fPlayer, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VLAUSoundOut::Fwd()
|
||||||
|
{
|
||||||
|
if (sLastSkip <= 0.0)
|
||||||
|
sLastSkip = 0.1;
|
||||||
|
SkipTimeInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VLAUSoundOut::Bck()
|
||||||
|
{
|
||||||
|
if (sLastSkip >= 0.0)
|
||||||
|
sLastSkip = -0.1;
|
||||||
|
SkipTimeInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VLAUSoundOut::Stop(bool pause)
|
void VLAUSoundOut::Stop(bool pause)
|
||||||
|
|
|
@ -43,7 +43,8 @@ public:
|
||||||
virtual bool Playing() = 0;
|
virtual bool Playing() = 0;
|
||||||
virtual bool AtEnd() = 0;
|
virtual bool AtEnd() = 0;
|
||||||
virtual void SetPlayRate(float rate) = 0;
|
virtual void SetPlayRate(float rate) = 0;
|
||||||
virtual void SetTime(MusicTimeStamp time) = 0;
|
virtual void Fwd() = 0;
|
||||||
|
virtual void Bck() = 0;
|
||||||
|
|
||||||
virtual ~VLSoundOut();
|
virtual ~VLSoundOut();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user