-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaunchPadKeyCore.m
98 lines (78 loc) · 2.4 KB
/
LaunchPadKeyCore.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// LaunchPadKeyCore.m
// iLaunchPad
//
// Created by Max on 11/29/13.
// Copyright (c) 2013 GIST. All rights reserved.
//
#import "LaunchPadKeyCore.h"
@implementation LaunchPadKeyCore
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:[NSNumber numberWithBool:self.looping] forKey:@"looping"];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self != nil) {
self.looping = [[aDecoder decodeObjectForKey:@"looping"] boolValue];
return self;
}
return nil;
}
- (instancetype) initWithLoopingMode: (BOOL) loopingMode {
self = [super init];
if (self != nil) {
self.looping = loopingMode;
return self;
}
return nil;
}
- (instancetype) init {
self = [super init];
if (self != nil) {
self.looping = NO;
return self;
}
return nil;
}
- (NSError *) initializePlayerWithSoundAtPath: (NSString *) path {
//converting string to an URL
NSURL *fileURL = [NSURL fileURLWithPath:path];
// NSLog(@"launchpadkeycore initializeplayerwithsoundatpat fileurl %@", [fileURL description]);
NSError *error;
self.keySoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if (error == nil) {
// [self.keySoundPlayer setNumberOfLoops:-1];
[self.keySoundPlayer prepareToPlay];
return nil;
}
NSLog(@"launchpadkeycore keysoundplayer %@", [self.keySoundPlayer description]);
NSLog(@"%@", [error description]);
return error;
}
// This method starts playing sound and returns the time when the playback began
- (NSTimeInterval) play {
//NSTimeInterval currentTime = [[NSDate alloc] timeIntervalSince1970];
if (self.keySoundPlayer != nil) {
if ([self.keySoundPlayer isPlaying]) {
[self.keySoundPlayer stop];
[self.keySoundPlayer setCurrentTime:0];
}
[self.keySoundPlayer play];
}
//return currentTime;
return 0;
}
// This method stops playing sound and returns the time when the playback stopped
- (NSTimeInterval) stop {
// NSTimeInterval currentTime = [[NSDate alloc] timeIntervalSince1970];
if (self.keySoundPlayer != nil) {
[self.keySoundPlayer stop];
self.keySoundPlayer.currentTime = 0.0;
}
// return currentTime;
return 0;
}
- (BOOL) isPlayerInitialized {
return (self.keySoundPlayer != nil);
}
@end