1 #import "MainController.h"
2 #import "PreferencesController.h"
3 #import "HotKeyCenter.h"
4 #import "StatusWindow.h"
6 @interface MainController(Private)
7 - (ITMTRemote *)loadRemote;
8 - (void)rebuildUpcomingSongsMenu;
9 - (void)rebuildPlaylistMenu;
10 - (void)rebuildEQPresetsMenu;
11 - (void)updateRatingMenu;
14 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
15 onItem:(NSMenuItem *)item;
19 @implementation MainController
21 /*************************************************************************/
23 #pragma mark INITIALIZATION/DEALLOCATION METHODS
24 /*************************************************************************/
28 if ( ( self = [super init] ) ) {
29 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
30 statusWindow = [StatusWindow sharedWindow];
38 [refreshTimer invalidate];
39 [refreshTimer release];
48 - (void)applicationDidFinishLaunching:(NSNotification *)note
50 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
51 currentRemote = [self loadRemote];
53 //Setup for notification of the remote player launching or quitting
54 [[[NSWorkspace sharedWorkspace] notificationCenter]
56 selector:@selector(applicationTerminated:)
57 name:NSWorkspaceDidTerminateApplicationNotification
60 [[[NSWorkspace sharedWorkspace] notificationCenter]
62 selector:@selector(applicationLaunched:)
63 name:NSWorkspaceDidLaunchApplicationNotification
66 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
67 [[PreferencesController sharedPrefs] registerDefaults];
70 statusItem = [[ITStatusItem alloc]
71 initWithStatusBar:[NSStatusBar systemStatusBar]
72 withLength:NSSquareStatusItemLength];
74 menu = [[NSMenu alloc] initWithTitle:@""];
75 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
76 [self applicationLaunched:nil];
78 [self applicationTerminated:nil];
81 [statusItem setImage:[NSImage imageNamed:@"menu"]];
82 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
83 // Below line of code is for creating builds for Beta Testers
84 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
87 - (void)applicationWillTerminate:(NSNotification *)note
90 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
93 - (ITMTRemote *)loadRemote
95 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
98 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
99 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
100 NSString *bundlePath;
102 while ( (bundlePath = [enumerator nextObject]) ) {
103 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
106 Class remoteClass = [remoteBundle principalClass];
108 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
109 [remoteClass isKindOfClass:[NSObject class]]) {
111 id remote = [remoteClass remote];
112 [remoteArray addObject:remote];
117 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
118 // if ( [remoteArray count] > 1 ) {
119 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
121 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
124 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
125 return [remoteArray objectAtIndex:0];
131 - (void)applicationLaunched:(NSNotification *)note
133 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
134 [currentRemote begin];
136 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
138 isAppRunning = ITMTRemotePlayerRunning;
142 - (void)applicationTerminated:(NSNotification *)note
144 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
145 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
146 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
147 [notRunningMenu addItem:[NSMenuItem separatorItem]];
148 [notRunningMenu addItemWithTitle:@"Preferences..." action:@selector(showPreferences:) keyEquivalent:@""];
149 [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@""] setTarget:NSApp];
150 [statusItem setMenu:[notRunningMenu autorelease]];
152 [currentRemote halt];
153 [refreshTimer invalidate];
154 [refreshTimer release];
157 isAppRunning = ITMTRemotePlayerNotRunning;
161 /*************************************************************************/
163 #pragma mark INSTANCE METHODS
164 /*************************************************************************/
166 - (void)startTimerInNewThread
168 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
169 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
170 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
172 selector:@selector(timerUpdate)
174 repeats:YES] retain];
179 //Recreate the status item menu
182 NSUserDefaults *defaults;
186 unichar fullstar = 0x2605;
187 unichar emptystar = 0x2606;
188 NSString *fullStarChar;
189 NSString *emptyStarChar;
191 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
195 defaults = [NSUserDefaults standardUserDefaults];
196 myMenu = [defaults arrayForKey:@"menu"];
197 playlist = [currentRemote currentPlaylistIndex];
198 fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
199 emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
202 lastPlaylistIndex = -1;
205 menu = [[NSMenu alloc] initWithTitle:@""];
207 //Release the old submenus
209 upcomingSongsItem = nil;
210 [upcomingSongsMenu release];
211 upcomingSongsMenu = nil;
213 [playlistMenu release];
219 [ratingItem setSubmenu:nil];
220 [ratingItem release];
224 //Build the rating menu
225 [ratingMenu release];
226 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
227 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:0];
228 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:20];
229 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:40];
230 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:60];
231 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:80];
232 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:100];
234 //Build the custom menu
235 for (i = 0; i < [myMenu count]; i++) {
236 NSString *item = [myMenu objectAtIndex:i];
237 if ([item isEqualToString:@"Play/Pause"]) {
238 ITKeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
239 playPauseItem = [menu addItemWithTitle:@"Play"
240 action:@selector(playPause:)
244 [self setKeyEquivalentForCode:[tempCombo keyCode]
245 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
248 } else if ([item isEqualToString:@"Next Track"]) {
249 ITKeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
250 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
251 action:@selector(nextSong:)
255 [self setKeyEquivalentForCode:[tempCombo keyCode]
256 andModifiers:[tempCombo modifiers] onItem:nextTrack];
259 } else if ([item isEqualToString:@"Previous Track"]) {
260 ITKeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
261 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
262 action:@selector(prevSong:)
266 [self setKeyEquivalentForCode:[tempCombo keyCode]
267 andModifiers:[tempCombo modifiers] onItem:prevTrack];
270 } else if ([item isEqualToString:@"Fast Forward"]) {
271 [menu addItemWithTitle:@"Fast Forward"
272 action:@selector(fastForward:)
274 } else if ([item isEqualToString:@"Rewind"]) {
275 [menu addItemWithTitle:@"Rewind"
276 action:@selector(rewind:)
278 } else if ([item isEqualToString:@"Show Player"]) {
279 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
280 action:@selector(showPlayer:)
282 } else if ([item isEqualToString:@"Upcoming Songs"]) {
283 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
286 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
287 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
288 [upcomingSongsItem setEnabled:NO];
289 } else if ([item isEqualToString:@"Playlists"]) {
290 playlistItem = [menu addItemWithTitle:@"Playlists"
293 } else if ([item isEqualToString:@"EQ Presets"]) {
294 eqItem = [menu addItemWithTitle:@"EQ Presets"
297 } else if ([item isEqualToString:@"Preferences…"]) {
298 [menu addItemWithTitle:@"Preferences…"
299 action:@selector(showPreferences:)
301 } else if ([item isEqualToString:@"Quit"]) {
302 [[menu addItemWithTitle:@"Quit"
303 action:@selector(terminate:)
304 keyEquivalent:@""] setTarget:NSApp];
305 } else if ([item isEqualToString:@"Current Track Info"]) {
306 trackInfoIndex = [menu numberOfItems];
307 [menu addItemWithTitle:@"No Song"
310 } else if ([item isEqualToString:@"Song Rating"]) {
311 ratingItem = [[menu addItemWithTitle:@"Song Rating"
313 keyEquivalent:@""] retain];
314 [ratingItem setSubmenu:ratingMenu];
315 } else if ([item isEqualToString:@"<separator>"]) {
316 [menu addItem:[NSMenuItem separatorItem]];
321 [self rebuildPlaylistMenu];
325 [self rebuildEQPresetsMenu];
328 isPlayingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
330 if (upcomingSongsItem) {
331 [self rebuildUpcomingSongsMenu];
335 if (isPlayingRadio || !playlist) {
336 [ratingItem setEnabled:NO];
338 int currentSongRating = ([currentRemote currentSongRating] * 5);
339 lastSongRating = currentSongRating;
340 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
341 [ratingItem setEnabled:YES];
345 //Set the new unique song identifier
346 lastSongIdentifier = [[currentRemote playerStateUniqueIdentifier] retain];
348 //If we're in a playlist or radio mode
349 if ( ![lastSongIdentifier isEqualToString:@"0-0"] && (trackInfoIndex > -1) ) {
352 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
354 [menu removeItemAtIndex:i];
355 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
359 title = [currentRemote currentSongTitle];
361 if (!isPlayingRadio) {
362 if ([defaults boolForKey:@"showTime"]) {
363 NSString *length = [currentRemote currentSongLength];
364 char character = [length characterAtIndex:0];
365 if ( (character > '0') && (character < '9') ) {
366 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
370 if ([defaults boolForKey:@"showTrackRating"]) {
371 if (title) { //Check to see if there's a song playing
372 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
376 if ([defaults boolForKey:@"showArtist"]) {
377 NSString *artist = [currentRemote currentSongArtist];
378 if ([artist length] > 0) {
379 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
383 if ([defaults boolForKey:@"showTrackNumber"]) {
384 int track = [currentRemote currentSongTrack];
385 int total = [currentRemote currentAlbumTrackCount];
387 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
391 if ([defaults boolForKey:@"showAlbum"]) {
392 NSString *album = [currentRemote currentSongAlbum];
394 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
399 if ([title length] > 0) {
400 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
404 [statusItem setMenu:menu];
410 //Rebuild the upcoming songs submenu. Can be improved a lot.
411 - (void)rebuildUpcomingSongsMenu
413 int curIndex = [currentRemote currentPlaylistIndex];
414 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
415 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
417 if (!isPlayingRadio) {
419 int curTrack = [currentRemote currentSongIndex];
422 [upcomingSongsMenu release];
423 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
424 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
425 [upcomingSongsItem setEnabled:YES];
427 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
429 NSString *curSong = [currentRemote songTitleAtIndex:i];
430 NSMenuItem *songItem;
431 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
432 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
433 [upcomingSongsMenu addItem:songItem];
441 [upcomingSongsItem setSubmenu:nil];
442 [upcomingSongsItem setEnabled:NO];
446 - (void)rebuildPlaylistMenu
448 NSArray *playlists = [currentRemote playlists];
449 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
451 [playlistMenu release];
452 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
454 for (i = 0; i < [playlists count]; i++) {
455 NSString *playlistName = [playlists objectAtIndex:i];
456 NSMenuItem *tempItem;
457 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
458 [tempItem setTag:i + 1];
459 [playlistMenu addItem:tempItem];
462 [playlistItem setSubmenu:playlistMenu];
463 [playlistItem setEnabled:YES];
465 if (!isPlayingRadio && currentPlaylist) {
466 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
470 //Build a menu with the list of all available EQ presets
471 - (void)rebuildEQPresetsMenu
473 NSArray *eqPresets = [currentRemote eqPresets];
476 [eqMenu autorelease];
477 eqMenu = [[NSMenu alloc] initWithTitle:@""];
479 for (i = 0; i < [eqPresets count]; i++) {
481 NSMenuItem *tempItem;
482 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
483 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
485 [eqMenu addItem:tempItem];
486 [tempItem autorelease];
490 [eqItem setSubmenu:eqMenu];
491 [eqItem setEnabled:YES];
492 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
495 - (void)updateRatingMenu
497 int currentSongRating = ([currentRemote currentSongRating] * 5);
498 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
499 if ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) {
502 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
503 lastSongRating = currentSongRating;
504 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
510 NSString *currentIdentifier = [currentRemote playerStateUniqueIdentifier];
511 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
512 (!isPlayingRadio && ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist))) {
515 // If we want to show the new track floater, do it here!
516 //[self showCurrentTrackInfoStatusWindow];
522 [self updateRatingMenu];
524 //Update Play/Pause menu item
528 // If we want to show the song played/paused, show it here!
531 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
532 [playPauseItem setTitle:@"Pause"];
534 [playPauseItem setTitle:@"Play"];
545 - (void)selectSong:(id)sender
547 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
550 - (void)selectPlaylist:(id)sender
552 int playlist = [sender tag];
553 [currentRemote switchToPlaylistAtIndex:playlist];
556 - (void)selectEQPreset:(id)sender
558 int curSet = [currentRemote currentEQPresetIndex];
559 int item = [sender tag];
561 [currentRemote switchToEQAtIndex:item];
562 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
563 [[eqMenu itemAtIndex:item] setState:NSOnState];
566 - (void)selectSongRating:(id)sender
568 int newRating = [sender tag];
569 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
570 [sender setState:NSOnState];
571 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
572 lastSongRating = newRating / 20;
575 - (void)playPause:(id)sender
577 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
579 if (state == ITMTRemotePlayerPlaying) {
580 [currentRemote pause];
581 [playPauseItem setTitle:@"Play"];
582 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
583 [currentRemote pause];
584 [currentRemote play];
586 [currentRemote play];
587 [playPauseItem setTitle:@"Pause"];
591 - (void)nextSong:(id)sender
593 [currentRemote goToNextSong];
596 - (void)prevSong:(id)sender
598 [currentRemote goToPreviousSong];
601 - (void)fastForward:(id)sender
603 [currentRemote forward];
604 [playPauseItem setTitle:@"Play"];
607 - (void)rewind:(id)sender
609 [currentRemote rewind];
610 [playPauseItem setTitle:@"Play"];
616 - (void)showPlayer:(id)sender
618 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
619 [currentRemote showPrimaryInterface];
621 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
622 NSLog(@"Error Launching Player");
627 - (void)showPreferences:(id)sender
629 [[PreferencesController sharedPrefs] setController:self];
630 [[PreferencesController sharedPrefs] showPrefsWindow:self];
633 - (void)closePreferences
635 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
640 - (ITMTRemote *)currentRemote
642 return currentRemote;
653 [[ITHotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
654 [[ITHotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
655 [[ITHotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
656 [[ITHotKeyCenter sharedCenter] removeHotKey:@"ToggleVisualizer"];
657 [[ITHotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
658 [[ITHotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
659 [[ITHotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"];
660 [[ITHotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"];
661 [[ITHotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"];
662 [[ITHotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"];
663 [[ITHotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"];
664 [[ITHotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"];
669 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
671 if ([defaults objectForKey:@"PlayPause"] != nil) {
672 [[ITHotKeyCenter sharedCenter] addHotKey:@"PlayPause"
673 combo:[defaults keyComboForKey:@"PlayPause"]
674 target:self action:@selector(playPause:)];
677 if ([defaults objectForKey:@"NextTrack"] != nil) {
678 [[ITHotKeyCenter sharedCenter] addHotKey:@"NextTrack"
679 combo:[defaults keyComboForKey:@"NextTrack"]
680 target:self action:@selector(nextSong:)];
683 if ([defaults objectForKey:@"PrevTrack"] != nil) {
684 [[ITHotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
685 combo:[defaults keyComboForKey:@"PrevTrack"]
686 target:self action:@selector(prevSong:)];
689 if ([defaults objectForKey:@"ToggleVisualizer"] != nil) {
690 [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleVisualizer"
691 combo:[defaults keyComboForKey:@"ToggleVisualizer"]
692 target:self action:@selector(toggleVisualizer)];
695 if ([defaults objectForKey:@"TrackInfo"] != nil) {
696 [[ITHotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
697 combo:[defaults keyComboForKey:@"TrackInfo"]
698 target:self action:@selector(showCurrentTrackInfoStatusWindow)];
701 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
702 [[ITHotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
703 combo:[defaults keyComboForKey:@"UpcomingSongs"]
704 target:self action:@selector(showUpcomingSongsStatusWindow)];
707 if ([defaults objectForKey:@"ToggleLoop"] != nil) {
708 [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleLoop"
709 combo:[defaults keyComboForKey:@"ToggleLoop"]
710 target:self action:@selector(showToggleLoopStatusWindow)];
713 if ([defaults objectForKey:@"ToggleShuffle"] != nil) {
714 [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle"
715 combo:[defaults keyComboForKey:@"ToggleShuffle"]
716 target:self action:@selector(showToggleShuffleStatusWindow)];
719 if ([defaults objectForKey:@"IncrementVolume"] != nil) {
720 [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementVolume"
721 combo:[defaults keyComboForKey:@"IncrementVolume"]
722 target:self action:@selector(showVolumeIncrementStatusWindow)];
725 if ([defaults objectForKey:@"DecrementVolume"] != nil) {
726 [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementVolume"
727 combo:[defaults keyComboForKey:@"DecrementVolume"]
728 target:self action:@selector(showVolumeDecrementStatusWindow)];
731 if ([defaults objectForKey:@"IncrementRating"] != nil) {
732 [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementRating"
733 combo:[defaults keyComboForKey:@"IncrementRating"]
734 target:self action:@selector(showRatingIncrementStatusWindow)];
737 if ([defaults objectForKey:@"DecrementRating"] != nil) {
738 [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementRating"
739 combo:[defaults keyComboForKey:@"DecrementRating"]
740 target:self action:@selector(showRatingDecrementStatusWindow)];
746 // Status Window Methods
750 - (void)showCurrentTrackInfoStatusWindow
752 NSString *trackName = [currentRemote currentSongTitle];
753 if (!statusWindow && [trackName length]) {
754 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
755 NSString *stringToShow = @"";
757 if ([defaults boolForKey:@"showName"]) {
758 if ([defaults boolForKey:@"showArtist"]) {
759 NSString *trackArtist = [currentRemote currentSongArtist];
760 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
762 stringToShow = [stringToShow stringByAppendingString:trackName];
763 stringToShow = [stringToShow stringByAppendingString:@"\n"];
766 if ([defaults boolForKey:@"showAlbum"]) {
767 NSString *trackAlbum = [currentRemote currentSongAlbum];
769 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
770 stringToShow = [stringToShow stringByAppendingString:@"\n"];
774 if ([defaults boolForKey:@"showTime"]) {
775 NSString *trackTime = [currentRemote currentSongLength];
776 if ([trackTime length]) {
777 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
782 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
783 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
785 stringToShow = [stringToShow stringByAppendingString:
786 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
788 stringToShow = [stringToShow stringByAppendingString:
789 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
794 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
797 /*[statusWindow setText:stringToShow];
798 [NSTimer scheduledTimerWithTimeInterval:3.0
800 selector:@selector(fadeAndCloseStatusWindow)
806 - (void)showUpcomingSongsStatusWindow
808 int curPlaylist = [currentRemote currentPlaylistIndex];
810 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
813 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
814 int curTrack = [currentRemote currentSongIndex];
816 NSString *songs = @"";
818 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
820 NSString *curSong = [currentRemote songTitleAtIndex:i];
821 songs = [songs stringByAppendingString:curSong];
822 songs = [songs stringByAppendingString:@"\n"];
827 //SHOW STATUS WINDOW HERE WITH STRING songs
830 /*[statusWindow setText:songs];
831 [NSTimer scheduledTimerWithTimeInterval:3.0
833 selector:@selector(fadeAndCloseStatusWindow)
840 - (void)showVolumeIncrementStatusWindow
844 - (void)showVolumeDecrementStatusWindow
848 - (void)showRatingIncrementStatusWindow
852 - (void)showRatingDecrementStatusWindow
856 - (void)showToggleLoopStatusWindow
860 - (void)showToggleShuffleStatusWindow
864 - (void)toggleVisualizer
866 NSLog(@"Visualizer On/Off");
869 - (void)fadeAndCloseStatusWindow
871 [statusWindow orderOut:self];
874 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
875 onItem:(NSMenuItem *)item
877 unichar charcode = 'a';
879 long cocoaModifiers = 0;
880 static long carbonToCocoa[6][2] =
882 { cmdKey, NSCommandKeyMask },
883 { optionKey, NSAlternateKeyMask },
884 { controlKey, NSControlKeyMask },
885 { shiftKey, NSShiftKeyMask },
888 for (i = 0; i < 6; i++) {
889 if (modifiers & carbonToCocoa[i][0]) {
890 cocoaModifiers += carbonToCocoa[i][1];
893 [item setKeyEquivalentModifierMask:cocoaModifiers];
895 //Missing key combos for some keys. Must find them later.
909 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
910 SetMenuItemCommandKey(menuRef, 1, NO, 49);
911 SetMenuItemModifiers(menuRef, 1, kMenuNoCommandModifier);
912 SetMenuItemKeyGlyph(menuRef, 1, kMenuBlankGlyph);*/
919 charcode = NSDeleteFunctionKey;
935 charcode = NSF5FunctionKey;
939 charcode = NSF6FunctionKey;
943 charcode = NSF7FunctionKey;
947 charcode = NSF3FunctionKey;
951 charcode = NSF8FunctionKey;
955 charcode = NSF9FunctionKey;
959 charcode = NSF11FunctionKey;
963 charcode = NSF3FunctionKey;
967 charcode = NSF14FunctionKey;
971 charcode = NSF10FunctionKey;
975 charcode = NSF12FunctionKey;
979 charcode = NSF13FunctionKey;
983 charcode = NSInsertFunctionKey;
987 charcode = NSHomeFunctionKey;
991 charcode = NSPageUpFunctionKey;
995 charcode = NSDeleteFunctionKey;
999 charcode = NSF4FunctionKey;
1003 charcode = NSEndFunctionKey;
1007 charcode = NSF2FunctionKey;
1011 charcode = NSPageDownFunctionKey;
1015 charcode = NSF1FunctionKey;
1019 charcode = NSLeftArrowFunctionKey;
1023 charcode = NSRightArrowFunctionKey;
1027 charcode = NSDownArrowFunctionKey;
1031 charcode = NSUpArrowFunctionKey;
1035 if (charcode == 'a') {
1036 unsigned long state;
1041 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1042 keyTrans = KeyTranslate(kchr, code, &state);
1043 charCode = keyTrans;
1044 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1045 } else if (charcode != 'b') {
1046 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];