| 1 |
/* |
| 2 |
|
| 3 |
SimpleTest2ViewController.h: |
| 4 |
|
| 5 |
Copyright (C) 2014 Steven Yi, Victor Lazzarini, Aurelius Prochazka |
| 6 |
Updated in 2017 by Dr. Richard Boulanger, Nikhil Singh |
| 7 |
|
| 8 |
This file is part of Csound iOS Examples. |
| 9 |
|
| 10 |
The Csound for iOS Library is free software; you can redistribute it |
| 11 |
and/or modify it under the terms of the GNU Lesser General Public |
| 12 |
License as published by the Free Software Foundation; either |
| 13 |
version 2.1 of the License, or (at your option) any later version. |
| 14 |
|
| 15 |
Csound is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU Lesser General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU Lesser General Public |
| 21 |
License along with Csound; if not, write to the Free Software |
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 23 |
02111-1307 USA |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
#import "SimpleTest2ViewController.h" |
| 28 |
|
| 29 |
@interface SimpleTest2ViewController() { |
| 30 |
IBOutlet UISwitch *onOffSwitch; |
| 31 |
|
| 32 |
IBOutlet UISlider *rateSlider; |
| 33 |
IBOutlet UISlider *durationSlider; |
| 34 |
IBOutlet UILabel *rateLabel; |
| 35 |
IBOutlet UILabel *durationLabel; |
| 36 |
|
| 37 |
IBOutlet UISlider *attackSlider; |
| 38 |
IBOutlet UISlider *decaySlider; |
| 39 |
IBOutlet UISlider *sustainSlider; |
| 40 |
IBOutlet UISlider *releaseSlider; |
| 41 |
|
| 42 |
IBOutlet UILabel *attackLabel; |
| 43 |
IBOutlet UILabel *decayLabel; |
| 44 |
IBOutlet UILabel *sustainLabel; |
| 45 |
IBOutlet UILabel *releaseLabel; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
@end |
| 50 |
|
| 51 |
@implementation SimpleTest2ViewController |
| 52 |
|
| 53 |
-(void)viewDidLoad { |
| 54 |
self.title = @"02. Simple Test 2"; |
| 55 |
self.csound = NULL; |
| 56 |
[super viewDidLoad]; |
| 57 |
} |
| 58 |
|
| 59 |
-(IBAction) toggleOnOff:(id)component { |
| 60 |
UISwitch *uiswitch = (UISwitch *)component; |
| 61 |
NSLog(@"Status: %d", [uiswitch isOn]); |
| 62 |
|
| 63 |
if(uiswitch.on) { |
| 64 |
|
| 65 |
NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"csd"]; |
| 66 |
NSLog(@"FILE PATH: %@", tempFile); |
| 67 |
|
| 68 |
//[self.csound stop]; |
| 69 |
if(self.csound == NULL){ |
| 70 |
self.csound = [[CsoundObj alloc] init]; |
| 71 |
[self.csound addListener:self]; |
| 72 |
|
| 73 |
CsoundUI *csoundUI = [[CsoundUI alloc] initWithCsoundObj:self.csound]; |
| 74 |
[csoundUI addSlider:rateSlider forChannelName:@"noteRate"]; |
| 75 |
[csoundUI addSlider:durationSlider forChannelName:@"duration"]; |
| 76 |
[csoundUI addSlider:attackSlider forChannelName:@"attack"]; |
| 77 |
[csoundUI addSlider:decaySlider forChannelName:@"decay"]; |
| 78 |
[csoundUI addSlider:sustainSlider forChannelName:@"sustain"]; |
| 79 |
[csoundUI addSlider:releaseSlider forChannelName:@"release"]; |
| 80 |
|
| 81 |
[csoundUI addLabel:rateLabel forChannelName:@"noteRate"]; |
| 82 |
[csoundUI addLabel:durationLabel forChannelName:@"duration"]; |
| 83 |
[csoundUI addLabel:attackLabel forChannelName:@"attack"]; |
| 84 |
[csoundUI addLabel:decayLabel forChannelName:@"decay"]; |
| 85 |
[csoundUI addLabel:sustainLabel forChannelName:@"sustain"]; |
| 86 |
[csoundUI addLabel:releaseLabel forChannelName:@"release"]; |
| 87 |
|
| 88 |
[csoundUI setLabelPrecision:2]; |
| 89 |
|
| 90 |
[self.csound play:tempFile]; |
| 91 |
} |
| 92 |
|
| 93 |
} else { |
| 94 |
[self.csound stop]; |
| 95 |
self.csound = NULL; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
- (IBAction)showInfo:(UIButton *)sender { |
| 100 |
UIViewController *infoVC = [[UIViewController alloc] init]; |
| 101 |
infoVC.modalPresentationStyle = UIModalPresentationPopover; |
| 102 |
infoVC.definesPresentationContext = YES; |
| 103 |
|
| 104 |
UIPopoverPresentationController *popover = infoVC.popoverPresentationController; |
| 105 |
popover.sourceView = sender; |
| 106 |
popover.sourceRect = sender.bounds; |
| 107 |
[infoVC setPreferredContentSize:CGSizeMake(300, 140)]; |
| 108 |
|
| 109 |
UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)]; |
| 110 |
infoText.editable = NO; |
| 111 |
infoText.selectable = NO; |
| 112 |
NSString *description = @"A generative music example that contains a number of sliders that affect the rate, duration, and envelope of each note."; |
| 113 |
[infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]]; |
| 114 |
infoText.font = [UIFont fontWithName:@"Menlo" size:16]; |
| 115 |
[infoVC.view addSubview:infoText]; |
| 116 |
popover.delegate = self; |
| 117 |
|
| 118 |
[popover setPermittedArrowDirections:UIPopoverArrowDirectionUp]; |
| 119 |
|
| 120 |
[self presentViewController:infoVC animated:YES completion:nil]; |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
#pragma mark CsoundObjListener |
| 125 |
|
| 126 |
-(void)csoundObjCompleted:(CsoundObj *)csoundObj { |
| 127 |
[onOffSwitch setOn:NO animated:YES]; |
| 128 |
} |
| 129 |
@end |