How Sonic Pi upload Midi Files From My Computer?

How Sonic Pi upload Midi files from my computer?

I am a Los-Angeles based composer and really enjoyed my Sonic Pi experience so far. I want to see if I can upload some midi files into Sonic Pi workstation so I can code/play with my existing music. For example, the midi file I exported from Logic. (not audio file) I would greatly appreciate it if I can get assistance from this community.

Hi here
YOu can’t load a midi file directly into Sonic Pi. However if you are using Logic I wonder if you are using a Mac? That has a nice little app called MidiPlayer-X which you can buy (£1.99 GBP) on the App Store and this enables you either to play midi-files in the MidiPlayer-X app, or to send them as a stream of midi commands to Sonic Pi where they can be used to trigger built in Synths in Sonic Pi. I mentioned it in this article

1 Like

Hi @yangzhang8805 welcome to in_thread, and hello also from LA (County)!

Sonic Pi doesn’t have any built-in support for loading MIDI files. I have a similar interest to be able to use a bunch of my own MIDI files and have explored this a little bit.

There are some tools out there that can help. At the top of my list to evaluate is Midiot (link below). I stumbled across this recently and looks like it has all the features needed. I haven’t had time to test beyond confirming that the base file appears to load OK but I’ll report back soon. The code hasn’t been updated in a few years so there may be things in there no longer compatible, but I’d be willing to hack at some fixes since this seems usable for me and possibly others.

A few months ago I hacked together a proof of concept Python script to convert a basic (drum-based) .mid to Sonic Pi code. I don’t expect it’s usable outside my hacking at the moment, but it’s a problem I want to solve… The Midiot approach seems good so I’m hoping it works out of the box or with a little nudging. :slight_smile:

Midiot: https://github.com/mojoD/hack-spi/wiki/4)-Using-Midiot-in-Sonic-Pi
My hack: https://gist.github.com/unbracketed/17b46c575463fb5dae2d5a0d58083264

1 Like

@robin.newman: and yes, I am using Mac. Okey, I will try MidiPlayer-X app to see how it can send those Midi events to Sonic Pi.
@perpetual_monday: Greeting from LA as well! I am interested in experimenting something. The purpose of using Midi file rather than Audio file is to change those notes, scale freely from the existing score/production. Certainly I can do everything in the traditional music production world, but it would be cool to mingle everything by coding/re-coding. :slight_smile: I will check out those links and let’s keep updated. Anyway, many thanks!

1 Like

@robin.newman: I wish your 2020 started with a high note, and to proceed to more happiness, accomplishments and luck! It was a long interruption during the holiday session and here I am:-) Just purchased MidiPlayer-X and now I had an issue to set up with Sonic P. May you provide more specifications following step by step with pictures/images to set up/synchronize Sonic P and MidiPlayer-X? I am still new to Sonic P:-) Many thanks!

Assuming that MidiPlayer-X basically pretends to be a sequencer and sends Midi signals at certain intervals, you would first need to see if Sonic Pi identifies MidiPlayer-X as a Midi channel by looking in the prefs under IO, like this. Mine does not show any Midi channels, but the first thing you will want to do is to make sure that MidiPlayer-X’s channel shows up here:

PiScreen

Once you have that down, you can read about reading and sending Midi signals in section 11 in the built-in tutorial. I haven’t done Midi myself, but OSC was pretty easy to get working and I can’t imagine Midi would be any more difficult.

@chris.krakou: @robin.newman: My first issue is after several times of trying, I cannot see MidiPlayer-X’s cannel shows up under IO, it seems that Sonic Pi doesn’t identify MidiPlayer-X as a Midi Channel. For anyone who successfully set up MidiPlayer-X in Sonic Pi, is there any special set-up I have to follow?

Just seen this. You set up an IAC Driver port in Audio MIDI setup. Select this as input in Sonic Pi IO Prefs. You use the popup list in MIdiPlayer-X to select the IAC port as the output channel, then the whole lot connects together. I’ll try and add some pictures tomorrow.

@robin.newman: I attached two screen shots, and still didn’t work out. Let me know if any step that I was missing.

2020-01-13 at 5.47.22 PM|433x500](upload://9tif8emXRzOWRAmYTEgSWwHpax1.png)

@robin.newman: another one

Open Audio MIDI Setup (located in Applications=>Utilities)
Select Midi Studio window from the Window Menu if it is not visible
Double Click on IAC Driver icon
Click the + sign below the (empty /) list of ports
Double click the newlyt created port “IAC Bus 1” and rename it spconnect

click the Apply Button

Open Sonic Pi, or if it is already open, open the IO prefs and click Reset MIDI

You should see iac_driver_spconnect listed as a midi port.

Open Midi Player X
Select the arrow beside Built in GM Synth, and from the popup list select IAC Driver spconnect

Now play a midi file in the Player and you should see the incoming cues in the Sonic Pi cues log.

Here is a simple program to play what is coming in.

use_synth :tri
live_loop :midi_in do
  n,v = sync "/midi/iac_driver_spconnect/*/*/note_on"
  play n,release: 0.1,amp: v/127.0 #gives each note a duration of 0.1
end

I haven’t time to do photos just now. If you are still having problems I can add some later today.

I’ve made a video to illustrate the process

2 Likes

@robin.newman: Millions of thanks! And yes, the first issue was solved:-) Now I can see those Midi device under the IO now. I will go head to the next step and will let you know if have any further issue. Greatly appreciate our community for all assistance and facilitation!

@robin.newman @chris.krakou: After I copy and paste your code as described above in one Buffer, now I can see all Midi cues are synchronized and connected with Sonic Pi, and now the issue is it doesn’t sound. I tried another Buffer in which I use internal synths/codes, and it sounds perfectly. Don’t know why.
Another paralleled question is regarding how to import external audio file(wave format)? I read your 3.6 section in Tutorial titled “External Samples” , still there are more details needed to import appropriately. For instance, I want to export tons of my Logic Musical files(Audio Wave format)into Sonic Pi, and improvise with some live coding possibilities. A detailed described procedure perhaps is needed here in order to appropriately import those audio files from my laptop. Many thanks!

Hm. You should be able to hear the sound.
I suspect that your midi cue may be a bit different. If you have run MidiPlayer X and prudced some cues in the Sonic Pi cues list, then rather than copy my code directly, when you ar typing in the line. 3

n,v = sync "/midi/iac_driver_spconnect/0/1/note_on"

instead type just the first bit
n,v = sync
making sure there is a space after sync, and you should see a popup window listing received cues. Choose one which ends with note_on and the rest of the line will automatically be added for you.
That should ensure that what you are trying to sync on in the program does actually match what is coming in tyo your cues list.
You can also post the program that is not working and I’ll see if I can spot any problem.

As regards samples from Logic, you should be able to access these. I’ve tried on my Mac and it works. However you cant load ALL of them at once. They take up too much memory. You can access groups of samples: for example

path= "/Library/Application Support/Logic/EXS Factory Samples/01 Acoustic Pianos/Yamaha Grand Piano/"
sample path,0
sleep 2
sample path,100

plays the first of the piano samples and the 101st sample in the folder. It is even possible to set up a piano instrument to play any specified note which I have done. (in a separate post)

1 Like

@robin.newman: Let’s focus on Audio file first, then later on go back to the Midi sound. Regarding the Logic samples library, it works. I use the Path (the simple programming language you provide) and now I can access all of the Logic samples library. The issue now is that I want to play with my own musical composition. (For instance, bounce one audio file from one of my Logic projects then save on my desktop.) I use the same program languages you provide, or Sam recommend in 3.6 section, and it seemed that it had a challenge to locate my file appropriately. The bar at the right side showed that there was no match found, skipping. Kindly let me know if you have other solutions when it comes to import your own musical composition(Audio file) from your laptop:

  1. path="/Desktop/My file name.wav/"
  2. path="/Users/sam/Desktop/My file name.wav/"

Many thanks!

The easiest way to make sure that you are accessing your sample or .wav file correctly is to locate its icon in the finder and to drag it to the Sonic Pi window. It will automatically produde the string to locate it.
For exampler if I locate a file text.wav in my Downloads folder and drag its icon to Sonic Pi and release it there then it will produce
"/Users/rbn/Downloads/test.wav" (it will have your user name instead of rbn there)
in the Sonic Pi window automatically.
You can then insert sample before that giving
sample "/Users/rbn/Downloads/test.wav"
which will play it when you click run.

1 Like

@robin.newman: sorry to reply a bit late, just fix my Mac laptop from my Apple store. And yes, I successfully accessed my audio files and it sounded. Now the new issue is (I am not sure if you ever had the similar experience before): it didn’t sound correctly, there was something wrong with playtime. I heard different parts of music have been overlapped. Do you know how to fix this type of issue?

@robin.newman: just fixed the overlapped issue as described above simply due to the programming language"sleep".:slight_smile: Once I remove “sleep”, it began to sound normal. Another question for live: I am experimenting the live version by mixing my own musical composition and coding together. If I am coding (by adding on new internal tracks or other sounds FX) while playing my track simultaneously, is there any possibility that I can hear the changed/progressed result continually without pressing “Run” twice or “Stop” and “Run”? I am experimenting some improvising without interruption while playing. Always feel thankful for your assistance!

Glad you fixed the overlap issues. As regards changing the Sonic Pi program and then having to use run or stop and run, I am afraid this is necessary, as you are only changing a text buffer contents when you alter the running program, and Sonic Pi has no means of knowing this until you press run and it reruns the entire buffer.
This problem has been discussed in a recent thread here which you may find useful.

@robin.newman: totally understand and no problem for me. Let’s go back to the Midi sound problem.:slight_smile: I double checked out the previous issue and what you suggested to me, until this moment, I am not sure that Midi files doesn’t sound due to the programing language or Midi file itself. (I am trying to upload my Midi file to see if you can open it and make it sound in your Sonic Pi, but it seems here you are only allowed to upload those image formats instead of sound files. ) Anyway, I greatly appreciate your assistance and let’s figure out the Midi file/sound issue.:slight_smile: