diff --git a/Plugins/MonkeysAudio/MonkeysAudio.xcodeproj/project.pbxproj b/Plugins/MonkeysAudio/MonkeysAudio.xcodeproj/project.pbxproj index e526f78c4..48bbc6d3b 100644 --- a/Plugins/MonkeysAudio/MonkeysAudio.xcodeproj/project.pbxproj +++ b/Plugins/MonkeysAudio/MonkeysAudio.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ 17ADB1E80B9793E300257CA2 /* MonkeysAudioPlugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17ADB1E60B9793E300257CA2 /* MonkeysAudioPlugin.h */; }; 17ADB1E90B9793E300257CA2 /* MonkeysAudioPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 17ADB1E70B9793E300257CA2 /* MonkeysAudioPlugin.mm */; }; 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; + 8EB1E6F90B9B39AA008F9F45 /* SourceIO.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8EB1E6F80B9B39AA008F9F45 /* SourceIO.h */; }; + 8EB1E6FD0B9B39D4008F9F45 /* SourceIO.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8EB1E6FC0B9B39D4008F9F45 /* SourceIO.mm */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -27,6 +29,7 @@ 179CFD7A0B90C70E00C8C4DB /* MAC.framework in CopyFiles */, 177FCFB50B90C97E0011C3B5 /* Plugin.h in CopyFiles */, 17ADB1E80B9793E300257CA2 /* MonkeysAudioPlugin.h in CopyFiles */, + 8EB1E6F90B9B39AA008F9F45 /* SourceIO.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -47,6 +50,8 @@ 32DBCF630370AF2F00C91783 /* MonkeysAudio_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MonkeysAudio_Prefix.pch; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* MonkeysAudio.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MonkeysAudio.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; + 8EB1E6F80B9B39AA008F9F45 /* SourceIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceIO.h; sourceTree = ""; }; + 8EB1E6FC0B9B39D4008F9F45 /* SourceIO.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SourceIO.mm; sourceTree = ""; }; D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -95,13 +100,15 @@ 08FB77AFFE84173DC02AAC07 /* Classes */ = { isa = PBXGroup; children = ( + 177FCFB40B90C97E0011C3B5 /* Plugin.h */, 17ADB1E60B9793E300257CA2 /* MonkeysAudioPlugin.h */, 17ADB1E70B9793E300257CA2 /* MonkeysAudioPlugin.mm */, - 177FCFB40B90C97E0011C3B5 /* Plugin.h */, 1745C2E70B90BDD100A6768C /* MonkeysAudioDecoder.h */, 1745C2E80B90BDD100A6768C /* MonkeysAudioDecoder.mm */, 1745C2E90B90BDD100A6768C /* MonkeysAudioPropertiesReader.h */, 1745C2EA0B90BDD100A6768C /* MonkeysAudioPropertiesReader.mm */, + 8EB1E6F80B9B39AA008F9F45 /* SourceIO.h */, + 8EB1E6FC0B9B39D4008F9F45 /* SourceIO.mm */, ); name = Classes; sourceTree = ""; @@ -196,6 +203,7 @@ 1745C2ED0B90BDD100A6768C /* MonkeysAudioDecoder.mm in Sources */, 1745C2EE0B90BDD100A6768C /* MonkeysAudioPropertiesReader.mm in Sources */, 17ADB1E90B9793E300257CA2 /* MonkeysAudioPlugin.mm in Sources */, + 8EB1E6FD0B9B39D4008F9F45 /* SourceIO.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Plugins/MonkeysAudio/MonkeysAudioDecoder.h b/Plugins/MonkeysAudio/MonkeysAudioDecoder.h index f99492b8e..5629a658b 100644 --- a/Plugins/MonkeysAudio/MonkeysAudioDecoder.h +++ b/Plugins/MonkeysAudio/MonkeysAudioDecoder.h @@ -12,9 +12,14 @@ #import "Plugin.h" +#import "SourceIO.h" + @interface MonkeysAudioDecoder : NSObject { - IAPEDecompress * decompress; + IAPEDecompress *decompress; + + id source; + SourceIO *sourceIO; int channels; int bitsPerSample; diff --git a/Plugins/MonkeysAudio/MonkeysAudioDecoder.mm b/Plugins/MonkeysAudio/MonkeysAudioDecoder.mm index 355d4b83a..43b747bec 100644 --- a/Plugins/MonkeysAudio/MonkeysAudioDecoder.mm +++ b/Plugins/MonkeysAudio/MonkeysAudioDecoder.mm @@ -12,17 +12,12 @@ @implementation MonkeysAudioDecoder -- (BOOL)open:(NSURL *)url +- (BOOL)open:(id)s { int n; - str_utf16 *chars = NULL; - - chars = GetUTF16FromUTF8((const unsigned char *)[[url path] UTF8String]); - if(chars == NULL) - return NO; + sourceIO = new SourceIO(s); - decompress = CreateIAPEDecompress(chars, &n); - free(chars); + decompress = CreateIAPEDecompressEx(sourceIO, &n); if (decompress == NULL) { @@ -36,6 +31,9 @@ length = ((double)decompress->GetInfo(APE_INFO_TOTAL_BLOCKS)*1000.0)/frequency; + [self willChangeValueForKey:@"properties"]; + [self didChangeValueForKey:@"properties"]; + return YES; } @@ -60,8 +58,13 @@ // DBLog(@"CLOSE"); if (decompress) delete decompress; + if (sourceIO) + delete sourceIO; + + [source release]; decompress = NULL; + sourceIO = NULL; } - (double)seekToTime:(double)milliseconds @@ -89,5 +92,10 @@ return [NSArray arrayWithObject:@"ape"]; } +- (BOOL)seekable +{ + return [source seekable]; +} + @end diff --git a/Plugins/MonkeysAudio/MonkeysAudioPropertiesReader.mm b/Plugins/MonkeysAudio/MonkeysAudioPropertiesReader.mm index 8830cc49f..d0eeea244 100644 --- a/Plugins/MonkeysAudio/MonkeysAudioPropertiesReader.mm +++ b/Plugins/MonkeysAudio/MonkeysAudioPropertiesReader.mm @@ -11,13 +11,13 @@ @implementation MonkeysAudioPropertiesReader -- (NSDictionary *)propertiesForURL:(NSURL *)url ++ (NSDictionary *)propertiesForSource:(id)source { NSDictionary *properties; MonkeysAudioDecoder *decoder; decoder = [[MonkeysAudioDecoder alloc] init]; - if (![decoder open:url]) + if (![decoder open:source]) { return nil; } diff --git a/Plugins/MonkeysAudio/SourceIO.h b/Plugins/MonkeysAudio/SourceIO.h new file mode 100644 index 000000000..1a2ed47f9 --- /dev/null +++ b/Plugins/MonkeysAudio/SourceIO.h @@ -0,0 +1,45 @@ +/* + * SourceCIO.h + * MonkeysAudio + * + * Created by Zaphod Beeblebrox on 3/4/07. + * Copyright 2007 __MyCompanyName__. All rights reserved. + * + */ + +#include + +#include "Plugin.h" + +class SourceIO : public CIO +{ +public: + //construction / destruction + SourceIO(id s); + ~SourceIO(); + + // open / close + int Open(const wchar_t * pName); + int Close(); + + // read / write + int Read(void * pBuffer, unsigned int nBytesToRead, unsigned int * pBytesRead); + int Write(const void * pBuffer, unsigned int nBytesToWrite, unsigned int * pBytesWritten); + + // seek + int Seek(int nDistance, unsigned int nMoveMode); + + // creation / destruction + int Create(const wchar_t * pName); + int Delete(); + + // other functions + int SetEOF(); + + // attributes + int GetPosition(); + int GetSize(); + int GetName(wchar_t * pBuffer); +protected: + id source; +}; diff --git a/Plugins/MonkeysAudio/SourceIO.mm b/Plugins/MonkeysAudio/SourceIO.mm new file mode 100644 index 000000000..fe7590186 --- /dev/null +++ b/Plugins/MonkeysAudio/SourceIO.mm @@ -0,0 +1,110 @@ +// +// SourceCIO.m +// MonkeysAudio +// +// Created by Zaphod Beeblebrox on 3/4/07. +// Copyright 2007 __MyCompanyName__. All rights reserved. +// + +#import "SourceIO.h" + +#import +#include + +SourceIO::SourceIO(id s) +{ + source = [s retain]; +} + +SourceIO::~SourceIO() +{ + [source release]; +} + +int SourceIO::Open(const wchar_t * pName) +{ + return -1; +} + +int SourceIO::Close() +{ + [source close]; + + return 0; +} + +// read / write +int SourceIO::Read(void * pBuffer, unsigned int nBytesToRead, unsigned int * pBytesRead) +{ + int l = [source read:pBuffer amount:nBytesToRead]; + + if (l < 0) { + *pBytesRead = 0; + NSLog(@"Error!"); + return -1; + } + *pBytesRead = l; + + return 0; +} +int SourceIO::Write(const void * pBuffer, unsigned int nBytesToWrite, unsigned int * pBytesWritten) +{ + *pBytesWritten = 0; + + return -1; +} + +// seek +int SourceIO::Seek(int nDistance, unsigned int nMoveMode) +{ + return ([source seekable] && [source seek:nDistance whence:nMoveMode] ? 0 : -1); +} + +// creation / destruction +int SourceIO::Create(const wchar_t * pName) +{ + return -1; +} + +int SourceIO::Delete() +{ + return -1; +} + +// other functions +int SourceIO::SetEOF() +{ + return -1; +} + +// attributes +int SourceIO::GetPosition() +{ + return [source tell]; +} + +int SourceIO::GetSize() +{ + if ([source seekable]) { + long currentPos = [source tell]; + + [source seek:0 whence:SEEK_END]; + long size = [source tell]; + + [source seek:currentPos whence:SEEK_SET]; + + return size; + } + else + { + return -1; + } +} + +int SourceIO::GetName(wchar_t * pBuffer) +{ + wcscpy(pBuffer,(const wchar_t*)[[[[source url] path] substringWithRange:NSMakeRange(0, MAX_PATH)] UTF8String]); + + return 0; +} +