Skip to content

Commit

Permalink
Added more hotkeys and device actions
Browse files Browse the repository at this point in the history
  • Loading branch information
wallin committed Oct 28, 2016
1 parent 69197dd commit afb4085
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
16 changes: 14 additions & 2 deletions OrthoCtrl/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;

}
}

Expand Down
6 changes: 6 additions & 0 deletions OrthoCtrl/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@property NSTimer* timer;
@property (weak) id<DeviceDelegate> delegate;
@property BOOL isConnected;
@property BOOL isPlaying;
@property BOOL isUpdatingVolume;
@property int pendingVolumeUpdate;
@property int volume;
Expand All @@ -35,5 +36,10 @@
- (void) decreaseVolume;
- (void) increaseVolume;
- (void) updateVolume: (int) volume;
- (void) skipToNextTrack;
- (void) skipToPreviousTrack;
- (void) startPlayback;
- (void) stopPlayback;
- (void) togglePlayback;

@end
38 changes: 36 additions & 2 deletions OrthoCtrl/Device.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ - (Device*) init:(NSNetService *)service
{
self = [super init];
self.pendingVolumeUpdate = -1;
self.isPlaying = false;

if (self != nil)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit afb4085

Please sign in to comment.