-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
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
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,22 @@ | ||
// | ||
// DMMusicPlayer.h | ||
// DaftMan | ||
// | ||
// Created by Tanner Smith on 12/16/13. | ||
// Copyright (c) 2013 Tanner Smith. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AudioToolbox/AudioToolbox.h> | ||
|
||
@interface DMMusicPlayer : NSObject | ||
|
||
@property (nonatomic, assign) MusicPlayer musicPlayer; | ||
@property (nonatomic, assign) MusicSequence musicSequence; | ||
@property (nonatomic, assign) MusicTrack tempoTrack; | ||
|
||
+ (id)sharedMusicPlayer; | ||
|
||
- (void)playSequence:(NSURL *)url beatsPerMinute:(double)bpm; | ||
|
||
@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,86 @@ | ||
// | ||
// DMMusicPlayer.m | ||
// DaftMan | ||
// | ||
// Created by Tanner Smith on 12/16/13. | ||
// Copyright (c) 2013 Tanner Smith. All rights reserved. | ||
// | ||
|
||
#import "DMMusicPlayer.h" | ||
|
||
@implementation DMMusicPlayer | ||
|
||
@synthesize musicPlayer; | ||
@synthesize musicSequence, tempoTrack; | ||
|
||
+ (id)sharedMusicPlayer { | ||
static dispatch_once_t onceToken; | ||
static DMMusicPlayer *player; | ||
|
||
dispatch_once(&onceToken, ^{ | ||
player = [[DMMusicPlayer alloc] init]; | ||
}); | ||
|
||
return player; | ||
} | ||
|
||
- (id)init { | ||
if (self = [super init]) { | ||
NewMusicPlayer(&musicPlayer); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)playSequence:(NSURL *)url beatsPerMinute:(double)bpm { | ||
if (musicSequence) { | ||
[self stop]; | ||
|
||
DisposeMusicSequence(musicSequence); | ||
} | ||
|
||
if (NewMusicSequence(&musicSequence) != 0) { | ||
[NSException raise:@"play" format:@"Can't create MusicSequence"]; | ||
} | ||
|
||
if (MusicSequenceFileLoad(musicSequence, (__bridge CFURLRef) url, 0, 0) != 0) { | ||
[NSException raise:@"play" format:@"Can't load MusicSequence"]; | ||
} | ||
|
||
if (MusicSequenceGetTempoTrack(musicSequence, &tempoTrack) != noErr) { | ||
[NSException raise:@"main" format:@"Cannot get tempo track."]; | ||
} | ||
|
||
if (MusicTrackNewExtendedTempoEvent(tempoTrack, 0.0, 120) != noErr) { | ||
[NSException raise:@"main" format:@"Cannot add tempo event."]; | ||
} | ||
|
||
MusicPlayerSetSequence(musicPlayer, musicSequence); | ||
MusicPlayerPreroll(musicPlayer); | ||
|
||
[self start]; | ||
} | ||
|
||
- (void)start { | ||
if (musicPlayer) { | ||
MusicPlayerStart(musicPlayer); | ||
} | ||
} | ||
|
||
- (void)stop { | ||
if (musicPlayer) { | ||
MusicPlayerStop(musicPlayer); | ||
} | ||
} | ||
|
||
- (void)dealloc { | ||
[self stop]; | ||
|
||
if (musicSequence) { | ||
DisposeMusicSequence(musicSequence); | ||
} | ||
|
||
DisposeMusicPlayer(musicPlayer); | ||
} | ||
|
||
@end |