The first thing to check is that you can see midi cues in the cues log when you play your midi file in midiplayer x. If this is the case, make sure midi player is then stopped, and you have pressed the stop button on Sonic Pi. The you should be able to drag across the cues in the cues log and copy and paste a reasonable section. If you post this (use three back quotes before and after the paste to format it nicely) and I’ll see what code you need to play it.
@robin.newman: I attached a few pictures by following up the steps you suggested. 1) All Midi cues connected from Midi PlayerX.
Hmm. A couple of problems. First, looking at the pink coloured cues reaching Sonic Pi these are of the form:
In my video I set up a midi port called
/iac_driver_spconnect and you have appeared to use this in the code, copying directly the code I used in the video. This will NOT match the incoming midi cues because the names are different.
There are three solutions. Either 1) set up the port exactly as detailed in the video, or 2) alter the code in your program to use the current midi port
or 3) you can use a wild card
* which will match any connected port name, although you will also have to match the port number (the 0 following this in the midi cue) so that it matches what is arriving. Again this
0 can be replaced with a wild card
* if you will only have 1 active port connected.
The second problem is that currently you are looking at input from channel 10. This channel is normally reserved as a percussion/drums channel, and as such the note values being received are not meant to be played (by synth :tri for example) but as selectors to select a particular percussion instrument eg hi-hat or triangle. Better to look at the input coming in channel1 1 and 2 which are both being received here.
So in conclusion, with the same midi file being used alter your code in Sonic Pi to read
use_synth :tri live_loop :midi_in do n,v = sync "/midi/*/*/1/note_on" play n, release: 0.1,amp: v/127.0 end
and see if this lets you here the input on channel 1.
You can try channel 2 by altering the /1/note_on to /2/note_on
Alternatively you could duplicate the live_loop and name the copy midi_in2 and change the channel to 2 in that loop giving
use_synth :tri live_loop :midi_in do n,v = sync "/midi/*/*/1/note_on" play n, release: 0.1,amp: v/127.0 end live_loop :midi_in2 do use_synth :saw n,v = sync "/midi/*/*/2/note_on" play n, release: 0.1,amp: v/127.0 end
(I"ve used a different synth for channel 2)
Hoep this works for you.
@robin.newman: Thank you very much for your suggestion! Something a bit weird happened:-)After following your suggested steps as 1): I use your 2nd recommended solution by altering the code in my program to use the current midi port iac_driver_bus_1; 2) both tried in bus 1 and bus 2. Still, it didn’t sound and it seemed that I didn’t change from channel 10 to channel 1 or 2. But this is what happened after I did alteration: when I re-play Midi Player X, I can hear that it began to play one of individual tracks, sometimes is Bass sound or synth keyboard sound. (assuming due to we connected to the synth instrument tri, right? ) At the same time, it synced with Sonic Pi with all related information. (please see the attached images. When it was played by Midi Player X, I can see channel 1 & 2 , and 10 are flashing.) But, after I copy and paste (like what you suggested in your previous message)the Midi cues across the cue log, and when I press “play” in Sonic Pi, it still didn’t sound. I am wondering: probably because the Midi file I use is a multi-tracked file(combine keyboard, drum and bass)? Or if it is a single Midi track, then we won’t have this type of issue? Have you ever used a multi-tracked Midi file (your musical project with Midi format)into Sonic Pi?
A few observations:
- You are filtering on MIDI channel 1. In the cue log visible in your last screenshot, I only see messages for channels
10. The presence of played notes in the run log above it imply that some messages are coming on channel
1, but maybe not continuously
- The notes I see being played are pretty low pitches, with very short release times. A lot of these are not audible or barely audible to me with my volume cranked. With such a short release time the most you’ll get is a percussive sound. Is that your intent?
General advice from an old programmer - try to break your problem into the simplest possible case first. I recommend removing the
amp options until you have notes playing as expected. Once all of your notes are playing, then you can go back and start decorating them.
perpetual_monday is right. You can only hear notes corrsponding to the channel you are looking at. Also you have some low notes and a short duration so they may be difficult to hear.
Following this long thread, I have started to look again at getting a reasonable midi file player working in Sonic Pi, which is not really designed for this purpose. However I have something working now which I am testing and refining. (Tested on MacOS and on Raspberry Pi 4) which will I think make this much easier. It is working with 15 channel midi input (I’m ignoring percussion at present but may try and do something with this too later). It will play notes for the correct length rather than a fixed value as in the simple examples above.
Watch this space…
You’ll have an enthusiastic supporter and tester here!
This would be a great addition for users like me who have a collection of MIDI files and/or generate them from other sources. I have bittersweet reactions when I see people’s tedious work to hand-code in long sequences of note and rest values. We already have a pretty good standard for encoding this data (MIDI) and good tools for creating and editing it (instruments, DAWs, …) [end old man rant]
There’s a wealth of decent to good MIDI files on the internets - everything from multi-track songs, to melodies, drum patterns, chord loops, etc. Having this support would open up a new avenue for experimenting and jamming.
The midiplayer is working pretty well now. Just testing different genres. I’ve added a set of midi GM drum samples so it can handle channel 10 as well now.I have it spreading the channels over the pan spectrum (adjustable) and you can specify synth for each channel, but at the moment I am using about three synths in a ring which are allocated in turn across the channels in use. As a crude allocation it works in separating out the channel so you can hear them distinctly. You can then fine tune allocation to suit the particular piece you want to play.
I am using midiplayer X to play the files on a Mac, but it works OK with just using aplaymidi or pmidi on Raspberry Pi to send gthe mdi stream to Sonic Pi. I’ve also set it so that it can automatically switch between using note_off signals or note_on with velocity 0 to terminate playing notes. The whole program is surprisingly short just some 70 lines. You could make up your own sample libraries for differnt drumkits. You just have to make sure that they canbe accessed by the appropriate midi number. I used a Ruby hash to do this.
I will write an article about it explaining how it works and how to use it and then publish the code.
@perpetual_monday: @robin.newman: Hello, first of all, thank you so much for warm participation! @perpetual_monday: My intention is want Sonic Pi plays exactly or at least function wise, plays similar functions as my original Midi file is supposed to sound. (e.g., my original file contains three Midi tracks composed of Keyboard, Percussion and Bass as one experimental example to start with .) By following your advice, I removed the
amp options, but the issue remained the same: Midi Player X sounded perfectly but Sonic Pi doesn’t sound at all. @robin.newman: There is no issue for Midi Player and it sounded just fine as I can switch the internal sound source from Synth to Piano, and I can hear the Piano sound when it is playing those Midi notes. I understanding your advice, “you can only hear notes corresponding to the channel you are looking at.” By following up your logic, if I want to hear those notes corresponding to 3 channels, should I program 3 paragraphs of simple programming languages so that I can hear those multiple (let’s say 3 ) tracks of Midi sounds? Due to my extremely limited /entry level of programming knowledge, can either or both of you provide some programming languages/code templates here so I can adjust/customize based on my situation? @robin.newman: you mentioned that to use a ring to handle those three separated tracks(synths), would you mind to give more details about you codes? My intention is want to hear them collaboratively, or distinctly per each Midi track though Sonic Pi if needed so I can freely mix/re-arrange with internal synths from Sonic Pi to re-compose my music via coding. At the moment, I haven’t gone further to explore my knowledge concerning Raspberry PI (but will do at the later phase:-) Let’ s say if I can fix all issues regarding Midi connections. Again, thank you very much for digging this topic deeper and for always being there for assistance and guidance!
Looking at your screenshot at4:45:06 (the last one) it seems that it is working for you as the log shows the tri synth playing 5 notes on channel 1. You are right in saying that you will need two more live loops to interrogate the other two channels so that you can hear all three. These should be identical to the first one, except for having different names eg :midi_in :midi_in2 and :midi_in3 and with the channels changed to match the other two you want to look at. However, channel 10 has to be treated differently and should be used to trigger drum, cymbal, triangle samples etc. This is more complicated to do.
However, I suggest you wait a little. Partly because of this thread, I have ben doing work to develop a mofe sophisticated 16 channel midi player for Sonic Pi, which will also handle the percussion track 10 correctly using a range of percussion samples to play the standard GM (general midi) instruments specified for that channel. It is more or less complete, and just undergoing testing before I publish it. It should do exactly what you want for playing midi files in Sonic Pi sent from midiplayer X. Hopefully I will release it during the coming week.
@robin.newman: Hello, just had a break here and hope all your developments go well as planned. Just would like to get more updates regarding your testing and release. One more question here: I am about to explore my knowledge concerning OSC and just learning Python now as a beginner. Where I can download Python version Sonic Pi? or Raspberry Pi? many thanks!
Sonic pi is only made for Ruby. If you want to do live coding with python, look into FoxDot. If you want to work with OSC and sonic pi, just make your code send OSC Messages and make the sonic pi code react to it. There is a section in the tutorial re: OSC.
Best of luck