Toggle button question

Joined
Apr 22, 2012
Messages
2
Reaction score
0
Points
1
hi,

i'm a beginner on Xcode so please help me with some code exemple
for my first post, i have a question :


i work on a midi interface with some buttons sending midi note

this code is for an Uibutton switch
if you press it , it send a midi noteON message,wait a little and send midi noteOFF

my question is :
how to make a toggle button with this code
i want press one time, the button send a midi noteON message, wait
and it sent the midi noteOFF only if i press it again

same question to do this :
how to make a flash button with this code
i press the button and hold my finger on it, so the midi noteON message is transmited,
and when i release the button, only at this time it send a midi noteOFF message



in the .h
@property (retain, nonatomic) IBOutlet UIButton *button6;
- (IBAction) sendMidiData38;



in the .m
- (IBAction) sendMidiData38
{[self performSelectorInBackground:mad:selector(sendMidiData InBackground38) withObject:button6];}
- (void) sendMidiDataInBackground38
{
const UInt8 note = 101;
const UInt8 noteOn[] = { 0x92, note, 127 };
const UInt8 noteOff[] = { 0x82, note, 0 };

[midi sendBytes:noteOn size:sizeof(noteOn)];
[NSThread sleepForTimeInterval:0.1];
[midi sendBytes:noteOff size:sizeof(noteOff)];
}

Thank's for your future answer(s), but as i told you, i'm a beginner in Xcode so if you can help me give me some code example to explain
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
In iOS, a button has several events each of which can trigger a unique method. So on the Touch Down event, connect that to a method to send the noteOn bytes. If you have to loop to repeatably send the note, you'll need to do that in a thread that is not the main thread. When the button is released, the Touch Up Inside event is triggered so connect that to a different method.

To use the same button in the two different scenarios will be tricky. You'll have to decide and time how long a tap is to turn on the button an leave it on. Anything beyond that time is a hold and release action instead. For some reason I think I've seen Apple code that demonstrates this. Perhaps others here can point to that if it indeed exists.

P.S. I have no experience with MIDI.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top