Created
December 3, 2013 13:04
-
-
Save somtd/7768784 to your computer and use it in GitHub Desktop.
C4 Advent Calendar #3 AudioPlayerSample _1 #BLOG
This file contains hidden or 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
// | |
// C4WorkSpace.m | |
// AudioPlayerSample | |
// | |
// Created by SOMTD on 2013/12/03. | |
// | |
@implementation C4WorkSpace { | |
C4Sample *sample; | |
//UI(rate) | |
C4Slider *rateSlider; | |
C4Label *rateLabel; | |
//UI(pan) | |
C4Slider *panSlider; | |
C4Label *panLabel; | |
//UI(volume) | |
C4Slider *volumeSlider; | |
C4Label *volumeLabel; | |
} | |
-(void)setup { | |
sample = [C4Sample sampleNamed:@"C4Loop.aif"]; | |
sample.loops = YES; | |
sample.rate = 1.0; | |
sample.pan = 0.0; | |
sample.volume = 0.5; | |
[sample play]; | |
[self setupUI]; | |
} | |
-(void)changeRate:(C4Slider *)aSlider { | |
sample.rate = aSlider.value + 0.5; | |
rateLabel.text = [NSString stringWithFormat:@"Current rate is: %4.2f", sample.rate]; | |
} | |
-(void)changePan:(C4Slider *)aSlider { | |
sample.pan = (aSlider.value * 2) - 1; | |
panLabel.text = [NSString stringWithFormat:@"Current pan is: %4.2f", sample.pan]; | |
} | |
-(void)changeVolume:(C4Slider *)aSlider { | |
sample.volume = aSlider.value; | |
volumeLabel.text = [NSString stringWithFormat:@"Current volume is: %4.2f", sample.volume]; | |
} | |
-(void)setupUI { | |
//UI(rate) | |
rateSlider = [C4Slider slider:CGRectMake(0, 0, 300, 44)]; | |
rateSlider.center = CGPointMake(self.canvas.width/2, self.canvas.height/4); | |
rateSlider.value = sample.rate - 0.5; | |
NSString *rateText = [NSString stringWithFormat:@"Current rate is: %4.2f", sample.rate]; | |
rateLabel = [C4Label labelWithText:rateText]; | |
CGPoint rateLabelCenter = rateSlider.center; | |
rateLabelCenter.y -= rateSlider.height / 2 + rateLabel.height; | |
rateLabel.center = rateLabelCenter; | |
rateLabel.textColor = C4BLUE; | |
rateLabel.font = [C4Font fontWithName:@"ArialRoundedMTBold" size:22.0f]; | |
//UI(pan) | |
panSlider = [C4Slider slider:CGRectMake(0, 0, 300, 44)]; | |
panSlider.center = CGPointMake(self.canvas.width/2, self.canvas.height/2); | |
panSlider.value = (sample.pan + 1) / 2; | |
NSString *panText = [NSString stringWithFormat:@" Current pan is: %4.2f ", sample.pan]; | |
panLabel = [C4Label labelWithText:panText]; | |
CGPoint panLabelCenter = panSlider.center; | |
panLabelCenter.y -= panSlider.height / 2 + panLabel.height; | |
panLabel.center = panLabelCenter; | |
panLabel.textColor = C4RED; | |
panLabel.font = [C4Font fontWithName:@"ArialRoundedMTBold" size:22.0f]; | |
//UI(volume) | |
volumeSlider = [C4Slider slider:CGRectMake(0, 0, 300, 44)]; | |
volumeSlider.center = CGPointMake(self.canvas.width/2, self.canvas.height*3/4); | |
volumeSlider.value = sample.volume; | |
NSString *volumeText = [NSString stringWithFormat:@"Current volume is: %4.2f", sample.volume]; | |
volumeLabel = [C4Label labelWithText:volumeText]; | |
CGPoint volumeLabelCenter = volumeSlider.center; | |
volumeLabelCenter.y -= volumeSlider.height / 2 + volumeLabel.height; | |
volumeLabel.center = volumeLabelCenter; | |
volumeLabel.textColor = C4GREY; | |
volumeLabel.font = [C4Font fontWithName:@"ArialRoundedMTBold" size:22.0f]; | |
[rateSlider runMethod:@"changeRate:" target:self forEvent:VALUECHANGED]; | |
[panSlider runMethod:@"changePan:" target:self forEvent:VALUECHANGED]; | |
[volumeSlider runMethod:@"changeVolume:" target:self forEvent:VALUECHANGED]; | |
[self.canvas addSubview:rateSlider]; | |
[self.canvas addLabel:rateLabel]; | |
[self.canvas addSubview:panSlider]; | |
[self.canvas addLabel:panLabel]; | |
[self.canvas addSubview:volumeSlider]; | |
[self.canvas addLabel:volumeLabel]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment