|
Post by marek on Nov 16, 2019 2:35:55 GMT
Hi, I've been looking for any way how to translate midi to osc and then to a network and found out that MidiFire has OSC Exchanger. Just after I bought it I realized it does only osc to midi. Do anyone has any idea how can I do this in iOS world, please? Thanks for any help!
Marek
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Nov 16, 2019 8:00:37 GMT
Hi marek , OSC Exchange will handle both directions, but the idea is that you have MidiFire on either side of the MIDI link converting the OSC to/from MIDI at either end. If you want to convert MIDI events to OSC (and send over UDP), you can use StreamByter although it's a bit fiddly. There is an example in the MidiFire manual under the StreamByter 'SEND' rule. Here it is: IF LOAD # setup two OSC messages in W array ASS W00 = 4F 53 43 00 # 'OSC' ASS W10 = 41 42 43 00 # 'ABC' # you can use variables for start, size and port # this example for second 'ABC' message ASS I0 = 10 4 ALIAS I2 PORT ASSIGN PORT = $2468 END
# send our OSC messages when we see sustain pedal IF M0 = B0 40 7F # send 'OSC' to host1 on port 1234 SND 0 4 +Uhost1:$1234 # send 'ABC' to local IP on port 2468 # using variables I0-2 for credentials SND I0 I1 +U192.168.1.1:PORT ENDRegards, Nic.
|
|
|
Post by marek on Nov 18, 2019 23:49:41 GMT
Hi Nic, I'm so glad it's possible with MidiFire, you made my day! However, from the example you sent me I'm not really sure how can I achieve this: For example, if I want to send MIDI CC 10 channel 5 from the external controller to OSC with address "/mix/monitor/0/matrix/fader" on 192.168.1.1:1234 ? Thank you so much for your help !!!
Marek
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Nov 19, 2019 11:22:37 GMT
Hi marek , Like I said, it's a little fiddly. This feature was added for a specific customer so it is not as user friendly as it should be. I have made an online script to make this a little easier though. Here is how you do it: The first thing you want to do is trap when we see CC10 on channel 5: if M0 == B4 $10 # got CC10 on channel 5, convert to OSC here endSecond, you want to setup your OSC message into StreamByter's 'W' array. I have made an OSC2SB script here. Using it, will generate the following for your specific OSC message: # osc2sb - /mix/monitor/0/matrix/fader ASS W000 = 2F 6D 69 78 2F 6D 6F 6E 69 74 6F 72 2F 30 2F 6D ASS W010 = 61 74 72 69 78 2F 66 61 64 65 72The script also gives you a line of code on how to send that message: SEND $0 $27 +U192.168.1.1:1234So, putting all of the above together, this code sends the OSC message when one a CC 10 on channel 5 message comes in: # convert CC10/CH5 to OSC send if M0 == B4 $10 # osc2sb - /mix/monitor/0/matrix/fader ASS W000 = 2F 6D 69 78 2F 6D 6F 6E 69 74 6F 72 2F 30 2F 6D ASS W010 = 61 74 72 69 78 2F 66 61 64 65 72 SEND $0 $27 +U192.168.1.1:1234 endThat's the gist of it. If you want to use the CC's value in the OSC message then that's a bit more complex. Regards, Nic.
|
|
|
Post by logxen on May 19, 2020 19:02:22 GMT
Hello! I have been really enjoying midifire so far. I am also working on midi to osc atm. I have a working script but it stops sending udp messages after a while ... usually in less than a minute. I first assumed that it was trying to send too fast as I'm tracking midi CC changes. So I implemented a delay that makes it so it only sends a udp message every so often instead of for every midi message. It still stops sending after a while though. It still seems to be receiving midi data and the blocks flash and numbers on screen update as expected. However if, having reached this state, I then open the Scenes menu it will say no files instead of listing my saved scenes. If I force close and restart the midifire it works again for a while.
Looking at my code I have another question too ... in one example in the university you show what appears to be the alias host1 being used to represent an ip address but you do not show an example of initializing that alias. I tried what seemed the obvious way to me here but it throws an error.
Anyway ... here's my code:
#Alias 192.168.86.40 host Alias $8888 port Alias $50 delay Alias L00 data Alias L00 group Alias L01 public Alias L02 page Alias L03 mode Alias L04 actives Alias L05 hueOffset Alias L06 saturation Alias L07 brightness Alias L08 speed Alias L09 density Alias L0A lfo1 Alias L0B lfo2 Alias L0C lfo3 Alias L0D lfo4 Alias L10 changed Alias L11 lastosc Alias L12 lastmidi Alias T00 osctimer
If LOAD Ass data = 00 00 00 06 0A 00 00 00 00 00 00 00 00 00 Ass changed = 00 50 osctimer End
Ass lastmidi = osctimer Mat lastosc = lastosc + lastmidi
If M00 == BF 7F 7F If lastmidi < delay Block Exit End End
If M00 == B0 01 Set LB0 M02 Ass hueOffset = M02 Ass changed = 1 End
If M00 == B0 03 Set LB1 M02 Ass brightness = M02 Ass changed = 1 End
If changed == 1 If lastosc > delay Ass changed = 00 00 Ass W000 = 2F 70 61 74 74 65 72 6E 00 00 00 00 2C 69 69 69 Ass W010 = 69 69 69 69 69 69 69 69 69 69 69 00 00 00 00 group Ass W020 = 00 00 00 public 00 00 00 page 00 00 00 mode 00 00 00 actives Ass W030 = 00 00 00 hueOffset 00 00 00 saturation 00 00 00 brightness 00 00 00 speed Ass W040 = 00 00 00 density 00 00 00 lfo1 00 00 00 lfo2 00 00 00 lfo3 Ass W050 = 00 00 00 lfo4 Send M00 M01 M02 Send $0 $84 +U192.168.86.30:port Else If M0 != BF 7F 7F Send BF 7F 7F Send BF 7F 7F +Ddelay +inject End End End
Block
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on May 20, 2020 15:19:42 GMT
Hi logxen , Second question first. I imagine I was thinking that host would be a define (like an alias but different): if load define host 192.168.1.1 end send $0 $84 +Uhost:portNow, the first issue/question is more troublesome! I have not encountered this before (or have had that reported) but it suspiciously sounds like MidiFire is so busy dealing with events from MIDI messages that it gets bogged down to the point of more or less crashing. It's hard to know unless I can reproduce exactly, but it sounds like there could be an event loop - either externally via the interfaces or your script is injecting an event that cause the script to eject an event in an infinite loop, which will pretty well kill the app. I didn't look at your code closely, and I can see you're injecting albeit with a test that the trigger event is not re-triggering the inject. My suggestion is to shove an Event Monitor on the canvas before the StreamByter and see if it gets swamped. On the other hand it is possible there is a bug somewhere in MidiFire, but I would rather eliminate infinite event loops in your setup before I start looking into that. Regards, Nic.
|
|
|
Post by logxen on May 20, 2020 19:28:06 GMT
That makes sense for the host thx. Yeah there’s not THAT much data ... it is just a single midi instrument. The data Im watching is basically just a mod wheel. Also the problem was happening before i started using inject. The inject is to help with the delay loop ... if no more messages come in it still needs to send out the last recieved data. I have also used an event monitor on both ends and the inject does not seem to be triggering more than it should. I have since tried out just streambyter in an audiobus host without midifire and that seems to last longer but still exhibits similar systems eventually ... including the save open interface being empty.
|
|
|
Post by logxen on May 20, 2020 20:46:25 GMT
Hmmm, on testing, the define statement does not seem to work for the host.
Here is a simplified version of the code without the delay and a couple comments:
If LOAD #Define host 192.168.86.30 Alias $8888 port
# OSC Packet Data Alias L00 data Alias L00 group Alias L01 public Alias L02 page Alias L03 mode Alias L04 actives Alias L05 hueOffset Alias L06 saturation Alias L07 brightness Alias L08 speed Alias L09 density Alias L0A lfo1 Alias L0B lfo2 Alias L0C lfo3 Alias L0D lfo4 Alias L10 changed Ass data = 00 00 00 06 3E 00 7F 7F 7F 7F 00 00 00 00 Ass changed = 00 End
# Mod wheel packet ... apply to Q1-Q5 as selected by Q0 If M00 == B0 01 #Mat I0 = M01 + 4 Mat I0 = Q0 + 4 Mat LI0 = M02 * 2 Set LB0 LI0 Ass changed = 1 End
# Send OSC packet If changed == 1 Ass changed = 00
Ass W000 = 2F 70 61 74 74 65 72 6E 00 00 00 00 2C 69 69 69 Ass W010 = 69 69 69 69 69 69 69 69 69 69 69 00 00 00 00 group Ass W020 = 00 00 00 public 00 00 00 page 00 00 00 mode 00 00 00 actives Ass W030 = 00 00 00 hueOffset 00 00 00 saturation 00 00 00 brightness 00 00 00 speed Ass W040 = 00 00 00 density 00 00 00 lfo1 00 00 00 lfo2 00 00 00 lfo3 Ass W050 = 00 00 00 lfo4
#Send $0 $84 +Uhost:port Send $0 $84 +U192.168.86.30:port Else Block End
|
|