diff --git a/Application/AppController.h b/Application/AppController.h index 447089574..46ca8cc2d 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -76,4 +76,9 @@ - (void)registerHotKeys; OSStatus handleHotKey(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData); + +- (void)clickPlay; +- (void)clickPrev; +- (void)clickNext; + @end diff --git a/Application/AppController.m b/Application/AppController.m index 0272494fe..519e96269 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -191,7 +191,7 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ - (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key { - return [key isEqualToString:@"currentEntry"]; + return [key isEqualToString:@"currentEntry"] || [key isEqualToString:@"play"]; } - (void)initShowColumn:(NSMenuItem *)showColumn withIdentifier:(NSString *)identifier diff --git a/Application/MediaKeysApplication.h b/Application/MediaKeysApplication.h new file mode 100644 index 000000000..a57b0e740 --- /dev/null +++ b/Application/MediaKeysApplication.h @@ -0,0 +1,17 @@ +// +// MediaKeysApplication.h +// Cog +// +// Created by Vincent Spader on 10/3/07. +// Copyright 2007 __MyCompanyName__. All rights reserved. +// + +#import +#import + +@interface MediaKeysApplication : NSApplication +{ +} + +@end + diff --git a/Application/MediaKeysApplication.m b/Application/MediaKeysApplication.m new file mode 100644 index 000000000..ec4f10734 --- /dev/null +++ b/Application/MediaKeysApplication.m @@ -0,0 +1,49 @@ +// +// MediaKeysApplication.m +// Cog +// +// Created by Vincent Spader on 10/3/07. +// Copyright 2007 __MyCompanyName__. All rights reserved. +// + +#import "MediaKeysApplication.h" +#import "AppController.h" + +@implementation MediaKeysApplication + +- (void)mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat +{ + switch( key ) + { + case NX_KEYTYPE_PLAY: + if( state == 0 ) + [[self delegate] clickPlay]; //Play pressed and released + break; + + case NX_KEYTYPE_FAST: + if( state == 0 ) + [[self delegate] clickNext]; //Next pressed and released + break; + + case NX_KEYTYPE_REWIND: + if( state == 0 ) + [[self delegate] clickPrev]; //Previous pressed and released + break; + } +} + +- (void)sendEvent: (NSEvent*)event +{ + if( [event type] == NSSystemDefined && [event subtype] == 8 ) + { + int keyCode = (([event data1] & 0xFFFF0000) >> 16); + int keyFlags = ([event data1] & 0x0000FFFF); + int keyState = (((keyFlags & 0xFF00) >> 8)) ==0xA; + int keyRepeat = (keyFlags & 0x1); + + [self mediaKeyEvent: keyCode state: keyState repeat: keyRepeat]; + } + + [super sendEvent: event]; +} +@end diff --git a/Audio/Chain/ConverterNode.m b/Audio/Chain/ConverterNode.m index 5fd84f25a..9134389ea 100644 --- a/Audio/Chain/ConverterNode.m +++ b/Audio/Chain/ConverterNode.m @@ -8,10 +8,6 @@ #import "ConverterNode.h" -#define BUFFER_SIZE 512 * 1024 -#define CHUNK_SIZE 16 * 1024 - - void PrintStreamDesc (AudioStreamBasicDescription *inDesc) { if (!inDesc) { @@ -36,16 +32,12 @@ void PrintStreamDesc (AudioStreamBasicDescription *inDesc) static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumberDataPackets, AudioBufferList* ioData, AudioStreamPacketDescription** outDataPacketDescription, void* inUserData) { ConverterNode *converter = (ConverterNode *)inUserData; - id previousNode = [converter previousNode]; OSStatus err = noErr; - void *readPtr; int amountToWrite; - int availInput; int amountRead; if ([converter shouldContinue] == NO || [converter endOfStream] == YES) { -// NSLog(@"END OF STREAM IN CONV"); ioData->mBuffers[0].mDataByteSize = 0; *ioNumberDataPackets = 0; @@ -59,14 +51,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber converter->callbackBuffer = malloc(amountToWrite); amountRead = [converter readData:converter->callbackBuffer amount:amountToWrite]; -/* if ([converter endOfStream] == YES) - { - ioData->mBuffers[0].mDataByteSize = 0; - *ioNumberDataPackets = 0; - - return noErr; - } -*/ if (amountRead == 0) + if (amountRead == 0) { ioData->mBuffers[0].mDataByteSize = 0; *ioNumberDataPackets = 0; @@ -74,43 +59,6 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber return 100; //Keep asking for data } - /* - availInput = [[previousNode buffer] lengthAvailableToReadReturningPointer:&readPtr]; - if (availInput == 0 ) - { -// NSLog(@"0 INPUT"); - ioData->mBuffers[0].mDataByteSize = 0; - *ioNumberDataPackets = 0; - - if ([previousNode endOfStream] == YES) - { - NSLog(@"END OF CONVERTER INPUT"); - [converter setEndOfStream:YES]; - [converter setShouldContinue:NO]; - - return noErr; - } - - return 100; //Keep asking for data - } - - if (amountToWrite > availInput) - amountToWrite = availInput; - - *ioNumberDataPackets = amountToWrite/(converter->inputFormat.mBytesPerPacket); - - if (converter->callbackBuffer != NULL) - free(converter->callbackBuffer); - converter->callbackBuffer = malloc(amountToWrite); - memcpy(converter->callbackBuffer, readPtr, amountToWrite); - - if (amountToWrite > 0) - { - [[previousNode buffer] didReadLength:amountToWrite]; - [[previousNode semaphore] signal]; - } -*/ -// NSLog(@"Amount read: %@ %i", converter, amountRead); ioData->mBuffers[0].mData = converter->callbackBuffer; ioData->mBuffers[0].mDataByteSize = amountRead; ioData->mBuffers[0].mNumberChannels = (converter->inputFormat.mChannelsPerFrame); @@ -138,34 +86,6 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber [self writeData:writeBuf amount:amountConverted]; } - -/* void *writePtr; - int availOutput; - int amountConverted; - - while ([self shouldContinue] == YES) - { - - availOutput = [buffer lengthAvailableToWriteReturningPointer:&writePtr]; - - while (availOutput == 0) - { - [semaphore wait]; - - if (shouldContinue == NO) - { - return; - } - - availOutput = [buffer lengthAvailableToWriteReturningPointer:&writePtr]; - } - - amountConverted = [self convert:writePtr amount:availOutput]; - - if (amountConverted > 0) - [buffer didWriteLength:amountConverted]; - } - */ } - (int)convert:(void *)dest amount:(int)amount @@ -185,43 +105,8 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber { return [self convert:dest amount:amount]; } -// if (err != noErr) -// NSLog(@"Converter error: %i", err); return ioData.mBuffers[0].mDataByteSize; -/* - void *readPtr; - int availInput; - - availInput = [[previousLink buffer] lengthAvailableToReadReturningPointer:&readPtr]; -// NSLog(@"AMOUNT: %i %i", amount, availInput); - - if (availInput == 0) - { - if ([previousLink endOfInput] == YES) - { - endOfInput = YES; - NSLog(@"EOI"); - shouldContinue = NO; - return 0; - } - } - - - if (availInput < amount) - amount = availInput; - - memcpy(dest, readPtr, amount); - - if (amount > 0) - { -// NSLog(@"READ: %i", amount); - [[previousLink buffer] didReadLength:amount]; - [[previousLink semaphore] signal]; - } - - return amount; - */ } - (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf @@ -249,10 +134,6 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber } } - // DBLog(@"Created converter"); - PrintStreamDesc(&inf); - PrintStreamDesc(&outf); - return YES; } diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index 96fe6fd7c..11f7c5dec 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -64,6 +64,10 @@ 17818A990C0B27AC001C4916 /* shn.icns in Resources */ = {isa = PBXBuildFile; fileRef = 17818A920C0B27AC001C4916 /* shn.icns */; }; 17818A9A0C0B27AC001C4916 /* wav.icns in Resources */ = {isa = PBXBuildFile; fileRef = 17818A930C0B27AC001C4916 /* wav.icns */; }; 17818A9B0C0B27AC001C4916 /* wv.icns in Resources */ = {isa = PBXBuildFile; fileRef = 17818A940C0B27AC001C4916 /* wv.icns */; }; + 1791005E0CB44D6D0070BC5C /* Cog.scriptSuite in Resources */ = {isa = PBXBuildFile; fileRef = 1791005C0CB44D6D0070BC5C /* Cog.scriptSuite */; }; + 1791005F0CB44D6D0070BC5C /* Cog.scriptTerminology in Resources */ = {isa = PBXBuildFile; fileRef = 1791005D0CB44D6D0070BC5C /* Cog.scriptTerminology */; }; + 1791FF8F0CB43A2C0070BC5C /* MediaKeysApplication.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1791FF8D0CB43A2C0070BC5C /* MediaKeysApplication.h */; }; + 1791FF900CB43A2C0070BC5C /* MediaKeysApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 1791FF8E0CB43A2C0070BC5C /* MediaKeysApplication.m */; }; 179790E10C087AB7001D6996 /* OpenURLPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 179790DF0C087AB7001D6996 /* OpenURLPanel.m */; }; 179790F20C087B46001D6996 /* OpenURLPanel.nib in Resources */ = {isa = PBXBuildFile; fileRef = 179790F00C087B46001D6996 /* OpenURLPanel.nib */; }; 17BB5CED0B8A86010009ACB1 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17BB5CEC0B8A86010009ACB1 /* AudioToolbox.framework */; }; @@ -104,8 +108,6 @@ 8E75757409F31D5A0080F1EE /* PlaylistView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E75753209F31D5A0080F1EE /* PlaylistView.m */; }; 8E75757509F31D5A0080F1EE /* Shuffle.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E75753409F31D5A0080F1EE /* Shuffle.m */; }; 8E7575BE09F31D800080F1EE /* wheel.icns in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575A609F31D800080F1EE /* wheel.icns */; }; - 8E7575CC09F31DCA0080F1EE /* Cog.scriptSuite in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575C409F31DCA0080F1EE /* Cog.scriptSuite */; }; - 8E7575CD09F31DCA0080F1EE /* Cog.scriptTerminology in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575C509F31DCA0080F1EE /* Cog.scriptTerminology */; }; 8E7575DB09F31E930080F1EE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575D909F31E930080F1EE /* Localizable.strings */; }; 8E9A2E860BA78B500091081B /* SecondsFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A2E840BA78B500091081B /* SecondsFormatter.m */; }; 8E9A2EDA0BA78D9D0091081B /* IndexFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A2ED80BA78D9D0091081B /* IndexFormatter.m */; }; @@ -335,6 +337,7 @@ 17F561400C3BD4F30019975C /* CogAudio.framework in CopyFiles */, 170680840B950164006BA573 /* Growl.framework in CopyFiles */, 17F94CCD0B8D090800A34E87 /* Sparkle.framework in CopyFiles */, + 1791FF8F0CB43A2C0070BC5C /* MediaKeysApplication.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -441,6 +444,10 @@ 17818A920C0B27AC001C4916 /* shn.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = shn.icns; sourceTree = ""; }; 17818A930C0B27AC001C4916 /* wav.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = wav.icns; sourceTree = ""; }; 17818A940C0B27AC001C4916 /* wv.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = wv.icns; sourceTree = ""; }; + 1791005C0CB44D6D0070BC5C /* Cog.scriptSuite */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Cog.scriptSuite; sourceTree = ""; }; + 1791005D0CB44D6D0070BC5C /* Cog.scriptTerminology */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Cog.scriptTerminology; sourceTree = ""; }; + 1791FF8D0CB43A2C0070BC5C /* MediaKeysApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaKeysApplication.h; sourceTree = ""; }; + 1791FF8E0CB43A2C0070BC5C /* MediaKeysApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MediaKeysApplication.m; sourceTree = ""; }; 179790DE0C087AB7001D6996 /* OpenURLPanel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OpenURLPanel.h; sourceTree = ""; }; 179790DF0C087AB7001D6996 /* OpenURLPanel.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = OpenURLPanel.m; sourceTree = ""; }; 179790F10C087B46001D6996 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/OpenURLPanel.nib; sourceTree = ""; }; @@ -500,8 +507,6 @@ 8E75753309F31D5A0080F1EE /* Shuffle.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Shuffle.h; sourceTree = ""; }; 8E75753409F31D5A0080F1EE /* Shuffle.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Shuffle.m; sourceTree = ""; }; 8E7575A609F31D800080F1EE /* wheel.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = wheel.icns; sourceTree = ""; }; - 8E7575C409F31DCA0080F1EE /* Cog.scriptSuite */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Cog.scriptSuite; sourceTree = ""; }; - 8E7575C509F31DCA0080F1EE /* Cog.scriptTerminology */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Cog.scriptTerminology; sourceTree = ""; }; 8E7575C809F31DCA0080F1EE /* English */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html; name = English; path = English.lproj/Credits.html; sourceTree = ""; }; 8E7575DA09F31E930080F1EE /* English */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/Localizable.strings; sourceTree = ""; }; 8E9A2E830BA78B500091081B /* SecondsFormatter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SecondsFormatter.h; sourceTree = ""; }; @@ -607,6 +612,8 @@ 177042980B8BC53600B86321 /* AppController.m */, 177042990B8BC53600B86321 /* PlaybackController.h */, 1770429A0B8BC53600B86321 /* PlaybackController.m */, + 1791FF8D0CB43A2C0070BC5C /* MediaKeysApplication.h */, + 1791FF8E0CB43A2C0070BC5C /* MediaKeysApplication.m */, ); path = Application; sourceTree = ""; @@ -909,10 +916,10 @@ 8D1107310486CEB800E47090 /* Info.plist */, 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 8E7575D909F31E930080F1EE /* Localizable.strings */, + 1791005C0CB44D6D0070BC5C /* Cog.scriptSuite */, + 1791005D0CB44D6D0070BC5C /* Cog.scriptTerminology */, 179790F00C087B46001D6996 /* OpenURLPanel.nib */, 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, - 8E7575C409F31DCA0080F1EE /* Cog.scriptSuite */, - 8E7575C509F31DCA0080F1EE /* Cog.scriptTerminology */, 17E41E060C130DFF00AC744D /* Credits.html */, ); name = Resources; @@ -1244,8 +1251,6 @@ 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 8E7575BE09F31D800080F1EE /* wheel.icns in Resources */, - 8E7575CC09F31DCA0080F1EE /* Cog.scriptSuite in Resources */, - 8E7575CD09F31DCA0080F1EE /* Cog.scriptTerminology in Resources */, 17E41E070C130DFF00AC744D /* Credits.html in Resources */, 8E7575DB09F31E930080F1EE /* Localizable.strings in Resources */, 177EC0440B8BC2FF0000BC8C /* add_blue.png in Resources */, @@ -1283,6 +1288,8 @@ 17818A990C0B27AC001C4916 /* shn.icns in Resources */, 17818A9A0C0B27AC001C4916 /* wav.icns in Resources */, 17818A9B0C0B27AC001C4916 /* wv.icns in Resources */, + 1791005E0CB44D6D0070BC5C /* Cog.scriptSuite in Resources */, + 1791005F0CB44D6D0070BC5C /* Cog.scriptTerminology in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1338,6 +1345,7 @@ 8E9A2EDA0BA78D9D0091081B /* IndexFormatter.m in Sources */, 8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */, 179790E10C087AB7001D6996 /* OpenURLPanel.m in Sources */, + 1791FF900CB43A2C0070BC5C /* MediaKeysApplication.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Info.plist b/Info.plist index f548fe0c0..baddbccc0 100644 --- a/Info.plist +++ b/Info.plist @@ -214,7 +214,7 @@ NSMainNibFile MainMenu NSPrincipalClass - NSApplication + MediaKeysApplication SUFeedURL http://cogx.org/appcast/stable.xml