Saturday, 19 January 2013

Adding dynamics to MIDI files

My current setting for creating a MIDI file for practicing duets was not very good, and the resulting files were always poor in dynamics, because it was quite a long and tedious process. So I asked in LAU the following:

"[...] I'm looking for an alternative way for note input. I am hoping for something like the following:

1. I just enter the notes, regardless of the duration of each of them.
2. Then I go into a second phase, where (using the PC keyboard or a MIDI
   keyboard) I just worry about the rhythm (the note durations). Every
   time I press a new key in the keyboard the program would play the
   next note from the ones entered in step 1. and record its duration. I
   don't care about how the score will look with these durations. I just
   want an easy way to create a more musical accompaniment. This way, at
   this step I only have to worry about the durations of each note.

Is there any MIDI editor that would let me do something like this?"

I ended up following the suggestion of using Pure Data. Despite never having used it, the YouTube tutoring videos by Rafael Hernandez are great, and after viewing the first 10 (about 90 minutes), the impatient guy in me had to code something and I managed to get a proof-of-concept implementation of the above. The code is horrible, and I'm sure it can be done much more efficiently and in a more elegant way (if any reader has suggestions, they are very welcome!), but for the moment this works.

The code itself is available, and  it looks like this:

I'm sure it hurts the eyes of any PureData programmer, but bear in mind that my exposure to PureData has been about two-three hours.

So, how does it work?  First, let's get everything connected (the MIDI keyboard to Pure Data, and Pure Data both to Midi Through and to FluidSynth):

Then, in step 1 (by clicking the toggle "To get notes from keyboard") and "Initialize list", we enter the notes of a melody, without worrying about rhythm or velocities. Then, in step 2, by selecting the other toggle (without a name), the notes will be played in the order of the notes just recorded, regardless of which keys I press, but recording their rhythm and velocities. A mini-demo can be seen below (also uploaded to


If I send that to, for example, MusE, the resulting score is quite different to the original score, but it has the rhythm and the velocities as entered in the second step:

Then, the tweaks to do are much less than for my original setting, and it involves writing chords, and perhaps changing a few note durations using the piano roll.

This is certainly a big improvement in my MIDI recording from my previous ways.

Tuesday, 15 January 2013

Virtual machine with persistence in VirtualBox

Now that I have a nice Multiboot USB stick (, I have been asked a couple of times to show it to someone. This involves re-booting a machine, so I looked for a way to try one of the distros installed in the USB inside VirtualBox. This is only a quick hack, and there is plenty of room for improvement, but it worked OK (with ideas from

The steps were:

1.- Create a new virtual machine (with 8GB of hard disk in a .vdi file), and attach to it the xubuntu CD.

2.- Create an ext3 partition in the .vdi file (the virtual machine's hard disk) and label it casper-rw:

3.- Try it.

When starting the virtual machine, type F6 to get into the LiveCD options, then with F6 again, include "persistent". (Also useful to change the keymap with F3). Every time we want to access the persistent partition, we will need to add "persistent" to the boot options (there are ways to modify the .ISO file so we don't need to do this, but I'm only using this option rarely, so it is not worth it).

4.- Transfer one of my LiveCD with persistent file to the VirtualBox.

Since this is almost only for demo purposes of my multiboot stick, when I don't want to reboot a PC, I want to be able to load one of my existing LiveCD distros (which use a casper-rw file instead of a casper-rw partition) in VirtualBox (somehow I only got the persistent mode to work inside VirtualBox with a casper-rw partition, not with a casper-rw file as I do it now with the Multiboot USB stick).

At my desktop I have the casper-rw file with all the required modifications at: /home/angelv/Desktop/xubuntu-casper-rw

I start Xubuntu in VirtualBox (without the persistent option), and then I want to copy the contents of the casper-rw file into the casper-rw partition. If you have shared folders or USB support for VirtualBox this is easier, but since I don't right now, I just do it through ssh to the VirtualBox host ( in my case).

That's it. Now we have a copy of our LiveCD with the persitent changes, that we can use from within VirtualBox.

(In my case, and to match the experience in my Multiboot USB stick, I not only add persistent to the boot options, but I add: persistent hostname=nomada username=angelv userfullname=AngeldeVicente)

Wednesday, 9 January 2013

Classical guitar progress logging (Jan'13)

I restart the monthly recordings in order to see my progress with the guitar. The settings to record with my Aria Sinsonido guitar are explained in:

The piece for this month is September, by Robin Pearson, and the video is here.

September, by Robin Pearson from Angel de Vicente on Vimeo.

Settings for recording a guitar performance

I just decided to write my current settings for recording a guitar performance in my Ubuntu Studio 12.10 distribution.

For capturing video I use a Live! Cam Chat HD de CreativeHD 720p which can manage 30 frames per second (this webcam comes with an incorporated microphone, so for simple tests, this is perfect and I can record both video/audio with vlc: open capture device (capture mode: Video for Linux 2, video device:  /dev/video0, audio: hw:1,0).

But most of the time I will want to get a different audio track, and then to post-process the video slightly. This is not very elegant but sort of works: I open Audacity and VLC at the same time. I start recording audio with Audacity (before opening the media capture with VLC, otherwise it gets stuck), then I start recording video with VLC. Once finished, I can apply one of the plugin effects in Audacity (most likely just a gentle reverb) and then export the Audacity audio to an MP3 file (the video captured with VLC goes by default to the Videos folder), and then I need to synchronize them.

To get the audio and video synchronized I use Kdenlive (0.9.2, and I set the default profile as Video4Linux). But I need to preprocess the video from my webcam, since it gets all broken when imported into Kdenlive. To get it right, when importing a new clip I first transcode it to HD720p 23.976fps (for 60 Mb/s). After this I get a .mov file, which can be loaded fine in Kdenlive.

Then I just load the .mp3 file from Audacity, the .mov file created above, and  I synchronize them (I do it manually with a visual cue, though Kdenlive has options for "Set audio reference", and "align with audio reference", which I should investigate). I apply basic effects fade-from-black, fade-to-black, fade-in, and fade-out, and I also add a basic title (any odd picture serves as background image, and nice fonts are Coolvetica).

Then I just choose the option to render to MPEG-4, which does a good job, the file created is small, and there are no audio lag issues that I notice with either Movie Player, VLC or Xine.

The resulting .mp4 file can be uploaded to Vimeo, and the result is also fine, with no apparent big audio lag issues.

Tuesday, 8 January 2013

Creating a MIDI part for duet practice

I wanted to get a decent-ish silicon partner to play a guitar duet, so I ended up with the following steps:

1.- Enter the basic music score

The first step is to get the music score for the second voice in the computer. I could either enter the "perfect" score and then tweak for some rhythmic/melodic changes or the other way around. I'm not a keyobard player, so the second option is out for me, though this is easy with, for example, MusE, where I can get a "live" MIDI stuff recorded, and then I could fix errors. In my case, better to start with a "perfect" score and then try to add some rhythmic/melodic changes.

So, to get the score in MIDI format I found that a pretty fast option is to use Denemo (to get the MIDI keyboard working, you probably have to follow the steps in For a first version of the MIDI file I will need only the JACK server and Denemo. Denemo launches its own FluidSynth, so we don't need another one. The only thing we need is to connect the output of the LPK25 to that FluidSynth instance, as in:

With this in place, entering the score is a piece of cake. We do in in two steps: first we enter the rhythm, by using the PC keyboard: to enter notes of different durations we just press the numbers from 0-7, and to enter rests of the corresponding durations Alt+[0-7]. With this, we have a score with the same note, but with the right durations, something like:

Once that is done, we can move to the beginning of the score, and with the help of the MIDI keyboard enter the actual notes. You don't need to enter them accurately in time, just enter them as you can, and Denemo will place them consecutively to match the previously entered rhythm pattern. At the end, we get something like:

In order to better control the duration (and later on the volume) for the bass and the melody lines, I prefer to enter them as separate MIDI tracks. Otherwise (or to enter chords), you can enter various notes by pressing the Alt key in the PC keyboard.

My final alpha-score looks now like:

In order to add some dynamics, I export it as a MIDI file. Denemo has been nice to use, but we don't need it anymore. Now we open Qsynth and Rosegardend, connect them appropriately, import the MIDI file, and now we have a basic version of the duo part that we can tweak with Rosegarden. 

2.- Add some dynamics in Rosegarden

Getting a polished MIDI file is quite a lot of work, but as a minimum we should be able to make some tempo changes, and some crescendos, diminuendos, etc. All of this can be done with Rosegarden.

First of all, we transpose it 12 semitones down, to get to the real frequency of the guitar. Then each track can have different volume levels, and we usually add some reverb:

Then, from the Notation Editor window, we can add crescendos and diminuendos, and by looking at the velocity editor below, we can also stress and silence individual notes at will:

And by using tempo changes, we can use different tempos, tempos that ramp up gradually to the next tempo, sudden tempo changes, etc., in order to make it sound more musical:

Now, for practice, I would like to take this music and slow it down, and slowly get to the final playing speed. If you only have on tempo in the whole composition, then that is not a problem as you can just change the tempo to apply to the whole piece and that's it. But if you made several tempo changes, then we need some other way. Not very elegant, but you can use the Segment-> Stretch or Squash option. First, start with a very low tempo, one that would be OK for practice, then when the piece is finished, you can use Stretch or Squash applied to all the tracks at the same time, so you can make it play faster than the original (I think that you cannot make it slower than the original time of the composition, hence the advice to set the initial tempo at practice speed. Probably you can get around this by adding empty extra bars at the beginning, so Rosegarden will have room to stretch the notes, but I haven't tried this).

As I said, this solution is not very elegant, since after applying it, then you will see that the tempo has not changed, but all the notes have been squashed together to occupy a smaller number of bars. Now, if you try to use the Metronome or see the score in the Notation Editor you will not like it, but if you work only with the slow tempo until you are satisfied with the result, and then just use the squashing option to play faster as your skill progresses, then this should be enough. But I'll be in the lookout for a better way to do this.

So that's it. With this in place, I can now play together with Rosegarden, and when I'm ready I can route it to Ardour (for example), and mix it with my own guitar input to get a final silicon-human duet.