diff --git a/OrthoCtrl/AppDelegate.m b/OrthoCtrl/AppDelegate.m index 2042375..18d7bab 100644 --- a/OrthoCtrl/AppDelegate.m +++ b/OrthoCtrl/AppDelegate.m @@ -126,7 +126,8 @@ - (void) registerHotkeys @[@35, @"Volume Up"], @[@45, @"Volume Down"], @[@3, @"Next Track"], - @[@11, @"Prev Track"] + @[@11, @"Prev Track"], + @[@46, @"Toggle Playback"] ]; for (NSArray* key in keys) { @@ -150,7 +151,7 @@ - (void) hotkeyWithEvent:(NSEvent *)hkEvent object:(id)anObject { return; } - NSArray* items = @[@"Volume Up", @"Volume Down", @"Next Track", @"Prev Track"]; + NSArray* items = @[@"Volume Up", @"Volume Down", @"Next Track", @"Prev Track", @"Toggle Playback"]; NSUInteger match = [items indexOfObject:(NSString*)anObject]; switch (match) { @@ -160,6 +161,17 @@ - (void) hotkeyWithEvent:(NSEvent *)hkEvent object:(id)anObject { case 1: [self.selectedDevice decreaseVolume]; break; + case 2: + [self.selectedDevice skipToNextTrack]; + break; + case 3: + [self.selectedDevice skipToPreviousTrack]; + break; + case 4: + [self.selectedDevice togglePlayback]; + + break; + } } diff --git a/OrthoCtrl/Device.h b/OrthoCtrl/Device.h index 9017b8d..d754a55 100644 --- a/OrthoCtrl/Device.h +++ b/OrthoCtrl/Device.h @@ -21,6 +21,7 @@ @property NSTimer* timer; @property (weak) id delegate; @property BOOL isConnected; +@property BOOL isPlaying; @property BOOL isUpdatingVolume; @property int pendingVolumeUpdate; @property int volume; @@ -35,5 +36,10 @@ - (void) decreaseVolume; - (void) increaseVolume; - (void) updateVolume: (int) volume; +- (void) skipToNextTrack; +- (void) skipToPreviousTrack; +- (void) startPlayback; +- (void) stopPlayback; +- (void) togglePlayback; @end diff --git a/OrthoCtrl/Device.m b/OrthoCtrl/Device.m index 3a4f592..24bc67a 100644 --- a/OrthoCtrl/Device.m +++ b/OrthoCtrl/Device.m @@ -17,6 +17,7 @@ - (Device*) init:(NSNetService *)service { self = [super init]; self.pendingVolumeUpdate = -1; + self.isPlaying = false; if (self != nil) { @@ -140,6 +141,36 @@ - (void) updateVolume:(int)volume } } +- (void) skipToNextTrack +{ + [self websocketWriteString:@"{ \"action\": \"track_skip_to_next\" }"]; +} + +- (void) skipToPreviousTrack +{ + [self websocketWriteString:@"{ \"action\": \"track_skip_to_prev\" }"]; +} + +- (void) stopPlayback +{ + [self websocketWriteString:@"{ \"action\": \"playback_stop\" }"]; +} + +- (void) startPlayback +{ + [self websocketWriteString:@"{ \"action\": \"playback_start\" }"]; +} + +- (void) togglePlayback +{ + if (self.isPlaying) { + [self stopPlayback]; + } + else { + [self startPlayback]; + } +} + - (void) ping { NSLog(@"ping"); @@ -229,7 +260,7 @@ - (void) handleUpdate:(NSString*) update json: (NSDictionary*) json { NSLog(@"received update: %@", update); - NSArray* updates = @[@"group_volume_changed"]; + NSArray* updates = @[@"group_volume_changed", @"playback_state_changed"]; NSUInteger match = [updates indexOfObject:update]; switch (match) { @@ -244,7 +275,10 @@ - (void) handleUpdate:(NSString*) update json: (NSDictionary*) json self.pendingVolumeUpdate = -1; } break; - + case 1: + self.isPlaying = [[json valueForKey:@"playing"] boolValue]; + NSLog(@"playback state changed. playing: %d", self.isPlaying); + break; default: break; } diff --git a/README.md b/README.md index b8b9400..b90966b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ from Teenage Engineering ![ortho-ctrl](ortho-ctrl.png) -**This project is very WIP. Your help is much appreciated** +**This project is in development. Your help is much appreciated** ## Installation @@ -18,19 +18,22 @@ $ pod install ## Usage -| Action | Shortcut | -|------------|----------------| -| Volume up | ctrl + alt + p | -| Volume down| ctrl + alt + n | +| Action | Shortcut | +|-----------------|----------------| +| Volume up | ctrl + alt + p | +| Volume down | ctrl + alt + n | +| Next track | ctrl + alt + f | +| Previous track | ctrl + alt + b | +| Toggle playback | ctrl + alt + m | ## TODO - [x] Auto discover device IP - [x] Handle multiple groups - [x] Volume slider +- [x] More actions, like skipping tracks - [ ] Show real device name in list - [ ] Configurable shortcuts -- [ ] More actions, like skipping tracks - [ ] Show connection status in toolbar icon ## Licence