Implement slow button

This commit is contained in:
Matthias Neeracher 2011-09-11 19:20:34 +02:00
parent d9e8d9e0bd
commit 22180008d2
9 changed files with 172 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

BIN
Art/slow.artx/doc.thread Normal file

Binary file not shown.

View File

@ -101,10 +101,12 @@
<string key="NSToolbarItemPaletteLabel">Progress</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSProgressIndicator" key="NSToolbarItemView" id="643802566">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">1292</int>
<object class="NSPSMatrix" key="NSDrawMatrix"/>
<string key="NSFrame">{{19, 14}, {16, 16}}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:3954</string>
<int key="NSpiFlags">28938</int>
<double key="NSMaxValue">100</double>
@ -164,6 +166,55 @@
<bool key="NSToolbarIsUserRemovable">YES</bool>
<int key="NSToolbarItemVisibilityPriority">0</int>
</object>
<object class="NSToolbarItem" key="4FD2C68B-58C8-493C-8935-78D2E689B16F" id="583756323">
<object class="NSMutableString" key="NSToolbarItemIdentifier">
<characters key="NS.bytes">4FD2C68B-58C8-493C-8935-78D2E689B16F</characters>
</object>
<string key="NSToolbarItemLabel">Slow</string>
<string key="NSToolbarItemPaletteLabel">Slow</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSButton" key="NSToolbarItemView" id="562272867">
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {32, 32}}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1491</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="1030377542">
<int key="NSCellFlags">67763712</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<object class="NSFont" key="NSSupport" id="488220547">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double>
<int key="NSfFlags">1044</int>
</object>
<string key="NSCellIdentifier">_NS:1491</string>
<reference key="NSControlView" ref="562272867"/>
<int key="NSButtonFlags">-2042347265</int>
<int key="NSButtonFlags2">134</int>
<object class="NSCustomResource" key="NSNormalImage" id="277891411">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">slow</string>
</object>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
</object>
</object>
<reference key="NSToolbarItemImage" ref="277891411"/>
<nil key="NSToolbarItemTarget"/>
<nil key="NSToolbarItemAction"/>
<string key="NSToolbarItemMinSize">{32, 32}</string>
<string key="NSToolbarItemMaxSize">{32, 32}</string>
<bool key="NSToolbarItemEnabled">YES</bool>
<bool key="NSToolbarItemAutovalidates">YES</bool>
<int key="NSToolbarItemTag">0</int>
<bool key="NSToolbarIsUserRemovable">YES</bool>
<int key="NSToolbarItemVisibilityPriority">0</int>
</object>
<object class="NSToolbarItem" key="737868E5-40A9-4B03-B2FD-E67F9EE16B2B" id="731736621">
<object class="NSMutableString" key="NSToolbarItemIdentifier">
<characters key="NS.bytes">737868E5-40A9-4B03-B2FD-E67F9EE16B2B</characters>
@ -238,9 +289,11 @@
<string key="NSToolbarItemPaletteLabel">&gt;&gt;</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSButton" key="NSToolbarItemView" id="976019007">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {32, 32}}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1491</string>
<int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
@ -248,11 +301,7 @@
<int key="NSCellFlags">67763712</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<object class="NSFont" key="NSSupport" id="488220547">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double>
<int key="NSfFlags">1044</int>
</object>
<reference key="NSSupport" ref="488220547"/>
<string key="NSCellIdentifier">_NS:1491</string>
<reference key="NSControlView" ref="976019007"/>
<int key="NSButtonFlags">-2042347265</int>
@ -286,9 +335,11 @@
<string key="NSToolbarItemPaletteLabel">&lt;&lt;</string>
<nil key="NSToolbarItemToolTip"/>
<object class="NSButton" key="NSToolbarItemView" id="9628001">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {32, 32}}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1491</string>
<int key="NSTag">-1</int>
<bool key="NSEnabled">YES</bool>
@ -403,13 +454,14 @@
</object>
</object>
</dictionary>
<array key="NSToolbarIBAllowedItems">
<array class="NSMutableArray" key="NSToolbarIBAllowedItems">
<reference ref="994417195"/>
<reference ref="376436287"/>
<reference ref="40496700"/>
<reference ref="941963392"/>
<reference ref="496749697"/>
<reference ref="228134409"/>
<reference ref="583756323"/>
<reference ref="731736621"/>
<reference ref="495025048"/>
<reference ref="382790746"/>
@ -422,6 +474,7 @@
<reference ref="376436287"/>
<reference ref="941963392"/>
<reference ref="496749697"/>
<reference ref="583756323"/>
<reference ref="228134409"/>
<reference ref="376436287"/>
<reference ref="731736621"/>
@ -1584,7 +1637,7 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1036200358"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{890, 428}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<int key="NSWindowCollectionBehavior">128</int>
@ -1800,7 +1853,7 @@
</array>
<string key="NSFrameSize">{338, 127}</string>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{213, 129}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
@ -2385,7 +2438,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
</array>
<string key="NSFrameSize">{372, 142}</string>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{213, 129}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
@ -3757,7 +3810,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<string key="NSFrameSize">{537, 336}</string>
<reference key="NSNextKeyView" ref="863383585"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{213, 129}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
@ -4500,6 +4553,14 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
</object>
<int key="connectionID">100528</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">playMusic:</string>
<reference key="source" ref="562471562"/>
<reference key="destination" ref="583756323"/>
</object>
<int key="connectionID">100533</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@ -6069,6 +6130,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<reference ref="941963392"/>
<reference ref="769048935"/>
<reference ref="60467166"/>
<reference ref="583756323"/>
</array>
<reference key="parent" ref="99906386"/>
</object>
@ -6184,6 +6246,27 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<reference key="parent" ref="0"/>
<string key="objectName">PDF Window</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">100529</int>
<reference key="object" ref="583756323"/>
<array class="NSMutableArray" key="children">
<reference ref="562272867"/>
</array>
<reference key="parent" ref="133015297"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">100530</int>
<reference key="object" ref="562272867"/>
<array class="NSMutableArray" key="children">
<reference ref="1030377542"/>
</array>
<reference key="parent" ref="583756323"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">100531</int>
<reference key="object" ref="1030377542"/>
<reference key="parent" ref="562272867"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@ -6343,6 +6426,10 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<string key="100512.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100517.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100518.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100529.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100530.CustomClassName">VLToolbarButton</string>
<string key="100530.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100531.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="101.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="102.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="114.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@ -6478,7 +6565,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">100528</int>
<int key="maxID">100533</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -6865,6 +6952,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
<string key="display">{512, 512}</string>
<string key="fwd">{512, 512}</string>
<string key="play">{512, 512}</string>
<string key="slow">{512, 512}</string>
<string key="vlsong">{128, 128}</string>
<string key="zoomin">{512, 512}</string>
<string key="zoomout">{512, 512}</string>

BIN
Resources/slow.icns Normal file

Binary file not shown.

View File

@ -195,6 +195,16 @@
case 1: // Fwd
VLSoundOut::Instance()->Fwd();
break;
case 0: {
float slowDown = 0.5f;
int modifiers=
[NSEvent modifierFlags] & (NSShiftKeyMask|NSAlternateKeyMask|NSCommandKeyMask|NSControlKeyMask);
while (modifiers) {
slowDown *= 0.75f;
modifiers &= modifiers-1;
}
VLSoundOut::Instance()->Slow(slowDown); }
break;
case -1: // Rew
VLSoundOut::Instance()->Bck();
break;

View File

@ -37,6 +37,7 @@ public:
virtual void SetPlayRate(float rate);
virtual void Fwd();
virtual void Bck();
virtual void Slow(float rate);
virtual void SetMelodyState(MelodyState state);
virtual ~VLAUSoundOut();
@ -56,6 +57,7 @@ private:
MusicTimeStamp fMusicLength;
bool fRunning;
bool fForward;
float fPlayRate;
dispatch_source_t fMusicPoll;
void Play(const int8_t * note, size_t numNotes = 1);
@ -75,6 +77,39 @@ private:
OSType fDataFormat;
};
class VLResetTimer {
public:
VLResetTimer(int64_t interval, void (^block)());
~VLResetTimer();
void Prime();
private:
dispatch_source_t fTimer;
int64_t fInterval;
void (^fBlock)();
};
VLResetTimer::VLResetTimer(int64_t interval, void (^block)())
: fInterval(interval), fBlock(Block_copy(block))
{
fTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_event_handler(fTimer, fBlock);
dispatch_source_set_timer(fTimer, DISPATCH_TIME_FOREVER, INT64_MAX, 1000*NSEC_PER_USEC);
dispatch_resume(fTimer);
}
VLResetTimer::~VLResetTimer()
{
Block_release(fBlock);
}
void VLResetTimer::Prime()
{
dispatch_source_set_timer(fTimer, dispatch_time(DISPATCH_TIME_NOW, fInterval),
INT64_MAX, 10*NSEC_PER_MSEC);
}
VLSoundEvent::~VLSoundEvent()
{
}
@ -211,6 +246,7 @@ void VLAUSoundOut::PlaySequence(MusicSequence music)
fMusic = music;
fMusicLength = SequenceLength(music);
fPlayRate = 1.0;
R(MusicSequenceSetAUGraph(fMusic, fGraph));
R(MusicPlayerSetSequence(fPlayer, fMusic));
@ -248,11 +284,12 @@ void VLAUSoundOut::SetPlayRate(float rate)
MusicSequenceReverse(fMusic);
MusicPlayerSetTime(fPlayer, fMusicLength - rightNow);
}
MusicPlayerSetPlayRateScalar(fPlayer, fabsf(rate));
fPlayRate = fabsf(rate);
MusicPlayerSetPlayRateScalar(fPlayer, fPlayRate);
}
static MusicTimeStamp sLastSkip = 0.0;
static dispatch_source_t sResetTimer;
static MusicTimeStamp sLastSkip = 0.0;
static VLResetTimer * sSkipResetTimer;
void VLAUSoundOut::SkipTimeInterval()
{
@ -260,17 +297,11 @@ void VLAUSoundOut::SkipTimeInterval()
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, ^{
if (!sSkipResetTimer)
sSkipResetTimer = new VLResetTimer(500*NSEC_PER_MSEC, ^{
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);
sSkipResetTimer->Prime();
MusicPlayerSetTime(fPlayer, time);
}
@ -288,6 +319,18 @@ void VLAUSoundOut::Bck()
SkipTimeInterval();
}
static VLResetTimer * sSlowResetTimer;
void VLAUSoundOut::Slow(float rate)
{
if (!sSlowResetTimer)
sSlowResetTimer = new VLResetTimer(500*NSEC_PER_MSEC, ^{
MusicPlayerSetPlayRateScalar(fPlayer, fPlayRate);
});
sSlowResetTimer->Prime();
MusicPlayerSetPlayRateScalar(fPlayer, fPlayRate*rate);
}
void VLAUSoundOut::Stop(bool pause)
{
MusicPlayerStop(fPlayer);

View File

@ -48,6 +48,7 @@ public:
virtual void SetPlayRate(float rate) = 0;
virtual void Fwd() = 0;
virtual void Bck() = 0;
virtual void Slow(float rate) = 0;
enum MelodyState {
kMelodyMute,
kMelodyRegular,

View File

@ -118,6 +118,7 @@
95AC700514099C64007EA050 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95AC700314099C64007EA050 /* AudioUnit.framework */; };
95AC700714099CF0007EA050 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95AC700614099CF0007EA050 /* Quartz.framework */; };
95AC70091409A291007EA050 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95AC70081409A291007EA050 /* Carbon.framework */; };
95B2C10F141D154B00C96B56 /* slow.icns in Resources */ = {isa = PBXBuildFile; fileRef = 95B2C10E141D154B00C96B56 /* slow.icns */; };
95B3E1A70960E58B000E9C0D /* Music in Resources */ = {isa = PBXBuildFile; fileRef = 95B3E1980960E58B000E9C0D /* Music */; };
95B66658096BCA1F00FE18C9 /* VLSheetViewNotes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95B66657096BCA1F00FE18C9 /* VLSheetViewNotes.mm */; };
95BDA15909540BF1009F9D65 /* VLSheetView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95BDA15809540BF1009F9D65 /* VLSheetView.mm */; };
@ -335,6 +336,7 @@
95AC700314099C64007EA050 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AudioUnit.framework; sourceTree = DEVELOPER_DIR; };
95AC700614099CF0007EA050 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework; sourceTree = DEVELOPER_DIR; };
95AC70081409A291007EA050 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Carbon.framework; sourceTree = DEVELOPER_DIR; };
95B2C10E141D154B00C96B56 /* slow.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = slow.icns; path = Resources/slow.icns; sourceTree = "<group>"; };
95B3E1980960E58B000E9C0D /* Music */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Music; path = Resources/Music; sourceTree = "<group>"; };
95B66653096BC6A100FE18C9 /* VLSheetViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = VLSheetViewInternal.h; path = Sources/VLSheetViewInternal.h; sourceTree = "<group>"; };
95B66656096BCA1F00FE18C9 /* VLSheetViewNotes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLSheetViewNotes.h; path = Sources/VLSheetViewNotes.h; sourceTree = "<group>"; };
@ -574,6 +576,7 @@
953F4B70140B041800C627F9 /* Icons */ = {
isa = PBXGroup;
children = (
95B2C10E141D154B00C96B56 /* slow.icns */,
953F4B6C140B040000C627F9 /* next.icns */,
953F4B6D140B040000C627F9 /* prev.icns */,
953F4B6A140AFF2A00C627F9 /* display.icns */,
@ -1039,6 +1042,7 @@
953F4B6B140AFF2A00C627F9 /* display.icns in Resources */,
953F4B6E140B040100C627F9 /* next.icns in Resources */,
953F4B6F140B040100C627F9 /* prev.icns in Resources */,
95B2C10F141D154B00C96B56 /* slow.icns in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};