forked from pweiskircher/Theremin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added possibility to toggle output devices. this fixes bug nr. #125.
- Loading branch information
1 parent
6268107
commit 659874f
Showing
11 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright (C) 2006-2007 Patrik Weiskircher | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
MA 02110-1301, USA. | ||
*/ | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface OutputDeviceHandler : NSObject { | ||
NSMenu *_menu; | ||
} | ||
- (id) initWithMenu:(NSMenu *)theMenu; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// OutputDeviceHandler.m | ||
// Theremin | ||
// | ||
// Created by Patrik Weiskircher on 18.05.09. | ||
// Copyright 2009 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "OutputDeviceHandler.h" | ||
#import "WindowController.h" | ||
#import "PreferencesController.h" | ||
|
||
@interface OutputDeviceHandler (PrivateMethods) | ||
- (void) discoverOutputDevices; | ||
- (void) removeMenuItems; | ||
@end | ||
|
||
const static int menuTagOutputDevices = 123411; | ||
const static int menuTagOutputSeperator = 123412; | ||
|
||
@implementation OutputDeviceHandler | ||
- (id) initWithMenu:(NSMenu *)theMenu { | ||
self = [super init]; | ||
if (self != nil) { | ||
_menu = [theMenu retain]; | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(connected:) | ||
name:(NSString *)nMusicServerClientConnected | ||
object:nil]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(disconnected:) | ||
name:(NSString *)nMusicServerClientDisconnected | ||
object:nil]; | ||
|
||
} | ||
return self; | ||
} | ||
|
||
- (void) dealloc | ||
{ | ||
[[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
[_menu release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) connected:(NSNotification *)theNotification { | ||
if (!([[MusicServerClient musicServerClientClassForProfile:[[[WindowController instance] preferences] currentProfile]] capabilities] & eMusicClientCapabilitiesOutputDevices)) { | ||
[self removeMenuItems]; | ||
} else { | ||
[self discoverOutputDevices]; | ||
} | ||
} | ||
|
||
- (void) disconnected:(NSNotification *)theNotification { | ||
[self removeMenuItems]; | ||
} | ||
|
||
- (void) removeMenuItems { | ||
NSMenuItem *item = [_menu itemWithTag:menuTagOutputDevices]; | ||
if (item != nil) | ||
[_menu removeItemAtIndex:[_menu indexOfItem:item]]; | ||
|
||
item = [_menu itemWithTag:menuTagOutputSeperator]; | ||
if (item != nil) | ||
[_menu removeItemAtIndex:[_menu indexOfItem:item]]; | ||
} | ||
|
||
- (void) discoverOutputDevices { | ||
[self removeMenuItems]; | ||
|
||
NSMenuItem *seperatorItem = [NSMenuItem separatorItem]; | ||
[seperatorItem setTag:menuTagOutputSeperator]; | ||
[_menu addItem:seperatorItem]; | ||
|
||
NSMenuItem *outputDeviceItem = [[[NSMenuItem alloc] initWithTitle:@"Output Devices" action:nil keyEquivalent:@""] autorelease]; | ||
[outputDeviceItem setSubmenu:[[[NSMenu alloc] init] autorelease]]; | ||
[outputDeviceItem setTag:menuTagOutputDevices]; | ||
[_menu addItem:outputDeviceItem]; | ||
|
||
NSArray *outputDevices = [[[WindowController instance] musicClient] getOutputDevices]; | ||
for (int i = 0; i < [outputDevices count]; i++) { | ||
NSDictionary *outputDevice = [outputDevices objectAtIndex:i]; | ||
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:[outputDevice objectForKey:dName] | ||
action:@selector(toggleOutputDevice:) | ||
keyEquivalent:@""] autorelease]; | ||
[item setTarget:self]; | ||
[item setTag:[[outputDevice objectForKey:dId] intValue]]; | ||
[item setState:[[outputDevice objectForKey:dEnabled] boolValue] == YES ? NSOnState : NSOffState]; | ||
|
||
[[outputDeviceItem submenu] addItem:item]; | ||
} | ||
} | ||
|
||
- (void) toggleOutputDevice:(NSMenuItem *)sender { | ||
BOOL toggleValue = [sender state] == NSOnState ? NO : YES; | ||
|
||
[[[WindowController instance] musicClient] setOutputDeviceWithId:[sender tag] toEnabled:toggleValue]; | ||
|
||
[sender setState:toggleValue == YES ? NSOnState : NSOffState]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters