| 1 |
/* |
| 2 |
|
| 3 |
MidiTestViewController.m: |
| 4 |
|
| 5 |
Copyright (C) 2014 Steven Yi, 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 |
#import "MidiTestViewController.h" |
| 27 |
|
| 28 |
@implementation MidiTestViewController |
| 29 |
|
| 30 |
-(void)viewDidLoad { |
| 31 |
self.title = @"04. Hardware: MIDI Controller"; |
| 32 |
|
| 33 |
widgetsManager = [[MidiWidgetsManager alloc] init]; |
| 34 |
|
| 35 |
[widgetsManager addSlider:mAttackSlider forControllerNumber:1]; |
| 36 |
[widgetsManager addSlider:mDecaySlider forControllerNumber:2]; |
| 37 |
[widgetsManager addSlider:mSustainSlider forControllerNumber:3]; |
| 38 |
[widgetsManager addSlider:mReleaseSlider forControllerNumber:4]; |
| 39 |
|
| 40 |
[widgetsManager addSlider:mCutoffSlider forControllerNumber:5]; |
| 41 |
[widgetsManager addSlider:mResonanceSlider forControllerNumber:6]; |
| 42 |
|
| 43 |
[widgetsManager openMidiIn]; |
| 44 |
|
| 45 |
[super viewDidLoad]; |
| 46 |
} |
| 47 |
|
| 48 |
-(void)viewWillDisappear:(BOOL)animated { |
| 49 |
|
| 50 |
[widgetsManager closeMidiIn]; |
| 51 |
|
| 52 |
[super viewWillDisappear:animated]; |
| 53 |
} |
| 54 |
|
| 55 |
-(IBAction) toggleOnOff:(id)component { |
| 56 |
UISwitch *uiswitch = (UISwitch *)component; |
| 57 |
NSLog(@"Status: %d", [uiswitch isOn]); |
| 58 |
|
| 59 |
if(uiswitch.on) { |
| 60 |
|
| 61 |
NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"midiTest" ofType:@"csd"]; |
| 62 |
NSLog(@"FILE PATH: %@", tempFile); |
| 63 |
|
| 64 |
[self.csound stop]; |
| 65 |
|
| 66 |
self.csound = [[CsoundObj alloc] init]; |
| 67 |
[self.csound addListener:self]; |
| 68 |
|
| 69 |
CsoundUI *csoundUI = [[CsoundUI alloc] initWithCsoundObj:self.csound]; |
| 70 |
|
| 71 |
[csoundUI addSlider:mCutoffSlider forChannelName:@"cutoff"]; |
| 72 |
[csoundUI addSlider:mResonanceSlider forChannelName:@"resonance"]; |
| 73 |
|
| 74 |
[csoundUI addSlider:mAttackSlider forChannelName:@"attack"]; |
| 75 |
[csoundUI addSlider:mDecaySlider forChannelName:@"decay"]; |
| 76 |
[csoundUI addSlider:mSustainSlider forChannelName:@"sustain"]; |
| 77 |
[csoundUI addSlider:mReleaseSlider forChannelName:@"release"]; |
| 78 |
|
| 79 |
[self.csound setMidiInEnabled:YES]; |
| 80 |
|
| 81 |
[self.csound play:tempFile]; |
| 82 |
|
| 83 |
} else { |
| 84 |
[self.csound stop]; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
-(IBAction) midiPanic:(id)component { |
| 89 |
[self.csound sendScore:@"i\"allNotesOff\" 0 1"]; |
| 90 |
} |
| 91 |
|
| 92 |
- (IBAction)showInfo:(UIButton *)sender { |
| 93 |
UIViewController *infoVC = [[UIViewController alloc] init]; |
| 94 |
infoVC.modalPresentationStyle = UIModalPresentationPopover; |
| 95 |
|
| 96 |
UIPopoverPresentationController *popover = infoVC.popoverPresentationController; |
| 97 |
popover.sourceView = sender; |
| 98 |
popover.sourceRect = sender.bounds; |
| 99 |
[infoVC setPreferredContentSize:CGSizeMake(300, 110)]; |
| 100 |
|
| 101 |
UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)]; |
| 102 |
infoText.editable = NO; |
| 103 |
infoText.selectable = NO; |
| 104 |
NSString *description = @"This example demonstrate MIDI input from hardware, as well an on-screen (simulated) MIDI keyboard."; |
| 105 |
[infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]]; |
| 106 |
infoText.font = [UIFont fontWithName:@"Menlo" size:16]; |
| 107 |
[infoVC.view addSubview:infoText]; |
| 108 |
popover.delegate = self; |
| 109 |
|
| 110 |
[popover setPermittedArrowDirections:UIPopoverArrowDirectionUp]; |
| 111 |
|
| 112 |
[self presentViewController:infoVC animated:YES completion:nil]; |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
#pragma mark CsoundObjListener |
| 118 |
|
| 119 |
|
| 120 |
-(void)csoundObjCompleted:(CsoundObj *)csoundObj { |
| 121 |
[mSwitch setOn:NO animated:YES]; |
| 122 |
} |
| 123 |
|
| 124 |
#pragma mark CsoundVirtualKeyboardDelegate |
| 125 |
|
| 126 |
-(void)keyUp:(CsoundVirtualKeyboard *)keybd keyNum:(int)keyNum { |
| 127 |
int midikey = 60 + keyNum; |
| 128 |
[self.csound sendScore:[NSString stringWithFormat:@"i-1.%003d 0 0", midikey]]; |
| 129 |
} |
| 130 |
|
| 131 |
-(void)keyDown:(CsoundVirtualKeyboard *)keybd keyNum:(int)keyNum { |
| 132 |
int midikey = 60 + keyNum; |
| 133 |
[self.csound sendScore:[NSString stringWithFormat:@"i1.%003d 0 -2 %d 0", midikey, midikey]]; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
@end |