Showing posts with label MIDI. Show all posts
Showing posts with label MIDI. Show all posts

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 https://vimeo.com/57762697):


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, 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 http://www.denemo.org/Using+a+Midi+Keyboard). 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.

Monday, 14 March 2011

Playing with different temperaments (tuning systems)

It all started with the entry exam for the Conservatoire, where one of the questions was about the Harmonic Series, then a comment by my Harmony teacher about Bach's well-tempered clavier. So I decided to learn a bit more about tuning systems in particular, and about the relation between music and mathematics in general. Reading material will be the book Music and Mathematics: From Pythagoras to Fractals and playing material will be the Scala software, which according to its webpage is "a powerful software tool for experimentation with musical tunings, such as just intonation scales, equal and historical temperaments, microtonal and macrotonal scales, and non-Western scales".

In order to get Scala to work on my computer (Ubuntu 10.04 64bits) I just had to follow these steps:
  • Download the software (the source code is available upon request to the author, but the downloaded package comes with the compiled code). Version 2.30d for 64-bit GNU/Linux on PC/Intel, http://www.huygens-fokker.org/software/scala-22-pc64-linux.tar.bz2
  • Make sure that gnuplot, libgnat-4.4, playmidi, and timidity are installed (all available through Synaptic Package Manager).
  • Copy the provided libgtkada-2.14.so.0 to /usr/lib/
  • Since I need the ISO8859 characters, I make my own script to launch scala:
angelv@vaso:~/Music-Guitar/Software/scala-22-pc64-linux$ cat my_scala.sh
#!/bin/bash
export LANG=en_US.iso8859-15
./scala
angelv@vaso:~/Music-Guitar/Software/scala-22-pc64-linux$


angelv@vaso:~/Music-Guitar/Software/scala-22-pc64-linux$ sudo modprobe snd-virmidi
angelv@vaso:~/Music-Guitar/Software/scala-22-pc64-linux$ cat /proc/asound/cards
0 [Intel ]: HDA-Intel - HDA Intel
HDA Intel at 0xefffc000 irq 16
1 [VirMIDI ]: VirMIDI - VirMIDI
Virtual MIDI Card 1
angelv@vaso:~/Music-Guitar/Software/scala-22-pc64-linux$

  • Now we just connect the output of this Virtual MIDI card to timidity with acconectgui 


  • And we can start experimenting with weird tuning systems, for example TET-19 (19 equal temperament):


The sound is fine, but if I try to record a screencast of it (as per my previous post http://angel-de-vicente.blogspot.com/2011/03/screencasts-with-xvidcap-in-ubuntu-1004.html), I cannot do it, so I will have to investigate further.

After a few tests, I discovered that the problem is with timidity and PulseAudio. Googling didn't give me any good results, but after trying different things, I realized that the one that works best to record the output of timidity with xvidcap is just to start another timidity process, but under padsp. Then, the method described in my previous xvidcap post works without any trouble, as can be seen in this demo video.

By the way, experimenting with different tunings can be quite fun, and interesting music can be made (as an example of a song composed in 19-TET see Incidence and Coincidence from William A. Sethares' Xentonality disc).

Friday, 14 January 2011

Virtual Pianola...

In my quest to try out new things related to sound and music with my Ubuntu Studio laptop, I decided to try and emulate a pianola (or player piano), as seen in this video (you can see in the following link a real piano player in action).

The first thing was to change the preferences in MuseScore (version 0.9.6.2). In the I/O preferences tab, I selected "Use JACK MIDI output":



Then I restarted, Jack, Musescore and VMPK (version 0.3.0), but in the Jack Audio Connection Kit "Connections" view, I could see "Mscore1" in the MIDI tab as a readable client, but VMPK input only showed in the ALSA tab, so I could not connect them.




With the help of the experts at the UbuntuStudio mailing list I found out that I would require a bridge between alsa midi and jack midi: a2jmidid. The best option seems to just put "a2jmidid &" in the Jack Connection Setup "Execute script after Startup" Option, so that the bridge will be in place every time I start Jack.

With this in place, and after restarting everything, I can connect the output from MuseScore into VMPK (and also into "FLUID Synth": otherwise I will see the keys in VMPK being pressed, but we will get no sound).



Now we only need some nice music to demonstrate... and I download "Lock and Key" from http://musescore.org/en/node/6707. And everything seems to work pretty well. But I don't want you to take my word for it, so I planned to record it.

I used gtk-recordMyDesktop (version 0.3.8), which is a front-end for recordMyDesktop. With it (in the Sound tab), you can click "Use jack for audio capture", but with this option enabled I always got errors like "... exited with status: 2816. Description: Improper window specification.", so I decided to record the sound (with Ardour) and the video (with recordMyDesktop) separately, and then mix it with Kdenlive.

Kdenlive is not happy with the .ogv file created by recordMyDesktop, so first I had to convert it to an .avi file with the command:

angelv@palas:~$ mencoder -ovc lavc -ofps 30 pianola.ogv -o pianola.avi

Synchronizing audio and video is not always straightforward always, but for this video it was quite easy. The resulting video can be seen at: http://vimeo.com/18783287



Friday, 7 January 2011

AKAI LPK25 MIDI Keyboard

The three kings were good (and very musical) to me this year. One of the things that they brought me was a small MIDI keyboard (AKAI LPK25). This is a very small keyboard, but very convenient for quick note entry (the computer keyboard feels very awkward for this).



Quickly after unwrapping it I set it to try it in my laptop, which has Ubuntu Studio 10.04 (64 bits) installed. For me, the most important feature is just to be able to quickly "type" a music score into a music notation software, so I decided to try with MuseScore. The section MIDI keyboard in the MuseScore documentation looked like I would have no problems, but though the keyboard was recognized and note entry was possible in a contrived way, it was not as expected. The blame was on the version of MuseScore, which in this version of Ubuntu Studio was 0.9.6 (revision: 2613). Luckily, Toby Smithe maintains a PPA with a more recent and stable version of MuseScore. Following the instructions in the PPA page and upgrading (via Synaptic the packages musescore-soundfont-gm, musescore and musescore-common), brings MuseScore up to verion 0.9.6.2 (revision: 3400), and with it note entry with my LPK25 is as advertised in the documentation. Now it is time to do some music with it...

Monday, 18 October 2010

From music sheet to MIDI (fourth round)

Time for SmartScore:

the Joropó piece, which comes from a PDF file generated with a music notation software (oh, well, if you look at the original score, you will see that this is far from perfect... not so Smart, after all!):



Given the previous performance, I couldn't expect too much for the old scanned document at http://www2.kb.dk/elib/noder/rischel/RiBS0848.pdf, but for completeness sake here it goes (although is almost useless):


And what about the scanned copy of one of my music books? Well, it gets confused with some of the bars, and it certainly would require some manual tweaking.


As per PhotoScore, MIDI files cannot be exported in the demo version, so I cannot test how well the music would be encoded.

So far, from the different softwares that I have tried, I think the ones that I would to try a bit better are SharpEye and PhotoScore

Wednesday, 13 October 2010

From music sheet to MIDI (third round)

Today is the time to try another piece of software: PhotoScore Ultimate 6

As with the others, we start with an easy one, the Joropó piece, which comes from a PDF file generated with a music notation software. And PhotoScore Ultimate 6 gets this:


A perfect performance. It is a pity that I could not save it to a MIDI file to try to load it with Rosegarden, since this was the Demo version, and that feature is not present.

The old scanned document at http://www2.kb.dk/elib/noder/rischel/RiBS0848.pdf does not get recognized very well with this program either:


And for my scanned copy of my book, PhotoScore does a quite decent job, although not better than SharpEye:


 It is a pity that the demo version cannot export to MIDI, because it would be nice to be able to compare PhotoScore's generated MIDI to that generated by SharpEye.

Saturday, 9 October 2010

From music sheet to MIDI (second round)

Yesterday I tried PDFtoMusic Pro and Audiveris for getting MIDI files out of music sheets. Today I'm trying another software, which looks much more promising: SharpEye.

So, let's start with the easy one, the Joropó piece, which comes from a PDF file generated with a music notation software. SharpEye gets this:


Not a single mistake for the first seven bars, for all the guitars. Not bad at all. And the generated MIDI file can be loaded into Rosegarden without any trouble.

How does SharpEye cope with the old scanned document at http://www2.kb.dk/elib/noder/rischel/RiBS0848.pdf? Well, the side-by-side view of the original document and the music recognized shows that there is still plenty of room for improvement, although it does work much better than Audiveris.


But it is true that the quality of the original is a bit poor, so let's be a bit nicer with the poor silicon brain, and let's compare Audiveris and SharpEye with a nicely scanned piece (I scan a random piece in one of my books at 600 dpi, though put it back to 300 dpi when transforming it to JPG (for Audiveris) and TIFF (for SharpEye)), and the first 9 bars of the scanned document look like:


What Audiveris gets is this:


You can see that many of the notes are correct, but this would definitely require some time to tidy it up. Worse is the fact that the MIDI created out of this seems to be broken, and when trying to load it in Rosegarden it simply refuses to do it, showing the message: "Attempt to read past MIDI file end"

SharpEye does a much better job:

For the first nine bars, it looks like SharpEye has done an excellent job. Actually, for the whole piece (24 bars), I counted only three mistakes, which is very good, but we shouldn't get too carried away... When the created MIDI file is imported into Rosegarden, the first nine bars look like this:



A lot of mistakes now... More or less OK to recognize the piece, but given the quality inside SharpEye, one would like to get a better MIDI file...

The quest for the perfect sheet-to-MIDI tool is still on!

Friday, 8 October 2010

From music sheet to MIDI (originally from PDFs to MIDI)

There is a LOT of music out there... thousands and thousands of pieces, and not much time to practice all of them, so it would be very nice to be able to get a PDF file, convert it to MIDI and quickly have an idea of how it is supposed to be, and then perhaps use that MIDI file in order to practice. So I have been trying two different software tools to do it. The first one is PDFtoMusic Pro, which is not available for Linux and is not free, and the other one  Audiveris, which is Open Source Software and will happily work in Linux.

In order to test each software, I start with the piece Joropó (for four guitars), which can be downloaded from http://www.forrestguitarensembles.co.uk/quartets.html

PDFtoMusic Pro

I don't have Windows, but I installed this in my Ubuntu 10.04 machine with Wine 1.1.42, and it runs without any (apparent) trouble.


I had no trouble at all to load the file, and to play directly inside it, without exporting it to MIDI, but actually I'm more interested in being able to export it to a MIDI file, so that later I can tweak it from inside Rosegarden or similar.

Exporting the file (or only selected pages) to MIDI is trivial, and when loaded in Rosegarden, there is no problem with playback. If we want to edit the file with the Notation Editor in Rosegarden, the result is pretty good, as can be seen from the first measures:


In order to get the same notation as the original score, we would have to tweak some of the sharps and turn them into flats, connect some notes with ligados, and change the clef of the fourth guitar, but those are quite small things.

If we make changes to the score and then want to print the music, then the result is also quite good from within Rosegarden. In this case, I just changed the clef of the fourth guitar, and printed it from within Rosegarden (which uses Lilypond as the printing engine), and the result was quite acceptable:



So, with PDFs that are generated with a music notation software, PDFtoMusic Pro works very well, but it cannot handle scanned music. For instance, when trying to load the file http://www2.kb.dk/elib/noder/rischel/RiBS0848.pdf it will come up with the message:



Audiveris

Audiveris is different from PDFtoMusic Pro (besides being Open Source), in which it is actually an OMR software and it will scan any document for music, even if it hasn't been generated by a music notation software.

I start Audiveris like:

angelv@vaso:~/audiveris$ java -Xmx256M -jar dist/audiveris-3.4.jar


Audiveris can only handle one page at at time, so we decide to go for the first page, which I save as a PDF (with evince), but the result when loaded is just not there:


So, I convert it to png first, but then Audiveris cannot even load it:

angelv@vaso:~/temp$ convert -density 300 first_page.pdf first_page.png

[...]

omr.sheet.picture.PictureLoader.loadFile(PictureLoader.java:101) -- INFO: Loading image from /home/angelv/temp/first_page.png ...
 omr.sheet.picture.PictureLoader$Listener.imageComplete(PictureLoader.java:366) -- INFO: Image loading complete
 omr.step.SheetSteps$LoadTask.doit(SheetSteps.java:489) -- WARNING: Exception [java.lang.RuntimeException: Unsupported pixel size:16]
 omr.step.Step.doStepRange(Step.java:354) -- WARNING: Processing aborted [omr.step.StepException: java.lang.RuntimeException: Unsupported pixel size:16]


With JPG all looks much better:

convert -density 300 first_page.pdf first_page.jpg


And all is fine now:




So far we have only loaded the image. If we now want to perform the OMR step, we just go to the menu Step-Score, and we get the scanned music. If you look carefully below, there are some mistakes, but most of it is in the right place.


Now, in theory one can export this to MusicXML format and use something like Lilypond to create a printable score, but something is not working. If I export it to MusicXML (Score-Export), and then try to use musicxml2ly I get the following errors:


angelv@vaso:~/temp$ musicxml2ly first_page.xml
Reading MusicXML from first_page.xml ...
Traceback (most recent call last):
  File "/usr/bin/musicxml2ly", line 2969, in
    main()
  File "/usr/bin/musicxml2ly", line 2964, in main
    voices = convert (filename, options)
  File "/usr/bin/musicxml2ly", line 2874, in convert
    (voices, staff_info) = get_all_voices (parts)
  File "/usr/bin/musicxml2ly", line 2583, in get_all_voices
    all_voices = voices_in_part_in_parts (parts)
  File "/usr/bin/musicxml2ly", line 2573, in voices_in_part_in_parts
    voices = voices_in_part (p)
  File "/usr/bin/musicxml2ly", line 2560, in voices_in_part
    part.interpret ()
  File "/usr/share/lilypond/2.12.3/python/musicxml.py", line 676, in interpret
    int (attributes_dict.get ('divisions').get_text ()))
ValueError: invalid literal for int() with base 10: '4.0'
angelv@vaso:~/temp$



But I don't really care, as I'm interested in getting MIDI stuff (a basic PDF file can be created OK with Audiveris' own Score-PrintPDF option), though this will have the mistakes present in the scan, so it is not that useful...

But now let's go for the real thing: getting a MIDI file and playing it. Midi-Store MIDI will create a MIDI file, which then can be uploaded to a MIDI sequencer, in my case Rosegarden. Without any modification, the MIDI is more or less OK, though obviously the mistakes that were present in the scan are there, so a crucial part will be the ability to edit the score manually.

So, if we open the score editor in Rosegarden, we see that the notes are in there (the third guitar's first three bars don't show up when opening the editor in multitrack mode, but they are there if we open the editor just for the guitar's part), but they are all messed up (different clef for 3rd and 4th guitar, different key, different time signature,...).


How difficult is to change it back to a recognizable score?

Well, I did try to adjust it without looking at the Rosegarden documentation, but it was certainly not that trivial, so I decided to follow one of the Rosegarden tutorials to learn the basics, and then come back to this Joropó score, to try to adjust it properly. I followed the following Rosegarden tutorial, but even after reading that, it looks like doing all the modifications to get a score similar to the original one would be quite costly. A simpler task would be just to modify the MIDI file to "sound" like the original, but it is certainly going to take also some time to do it right.

So, if your music is in a PDF generated by a music notation software and you are happy to pay for it, then certainly PDFtoMusic Pro does a much better job. But how can Audiveris handle scanned music? As with PDFtoMusic Pro, I tried to scan the first page of http://www2.kb.dk/elib/noder/rischel/RiBS0848.pdf but I'm afraid that the result speaks for itself...:


So, I'm afraid that so far Audiveris is work in progress, but cannot really compete with PDFtoMusic Pro. I will continue my quest to see if I can find some way of making MIDI files out of scanned music sheets, but for the moment it looks like either they are PDF files produced with music notation software (in which case I can use PDFtoMusic Pro) or I will have to type them by hand...

Monday, 4 October 2010

First Steps with Music Software in Linux

There are not (so far) many musical things that I want to do in the computer, but playing a MIDI file; mixing it with my own recording of playing one of the parts, and exporting it all into an audio file is one of them, so today I set some time to learn the basics.  In the computer I did this I'm running Ubutu 10.04, and I have followed the instructions in the Ubuntu Studio pages to quickly install all the software that I need (and much more), and to configure it.

With that in place, I rebooted the PC into the RealTime Kernel, and then I started by running JACK, Qsynth and Rosegarden. (Qsynth needs some soundfonts, and I downloaded some into the file /usr/share/sounds/sf2/FluidR3_GM.sf2. I don't remember where I got them from, but you can get them, for example, at http://musescore.org/handbook/soundfont). This looks like:


Then, it is time to check that all connectivity is working OK. The "Connect" button in the JACK interface will show the connections available. In my case:


This shows that the "General MIDI Device" in Rosegarden is connected to FLUID Synth (QSynth is just the GUI for fluidsynth), so all should be OK.

Then in Rosegarden we load a MIDI file, and select the instruments you want, modify the volume, reverb, etc. It took me a while (perhaps it should have been faster if I had read the documentation) to figure out how to select different instruments for each track, but it is actually quite easy. Just select one of the tracks:


Then say which instrument number you are going to use for that track:


My confusion for a while was to trust the name of what it would appear in the "Instrument" description, before I actually configured each instrument sound. So, the description in the "Instrument" field can be wrong. I guess it keeps whatever it was used last time with whatever synthesizer, so don't trust it, and instead, once you have selected the instrument number, you should specify the sound to be used for that instrument number:



With that in place (you will see that now the Instrument description in the track parameters section above reflects the change made here), you can now use Rosegarden to play the MIDI file with whatever instruments you choose.

So now we just have to record it into an audio file. This is done quite easily by just routing the output of Qsynth to Ardour. First, we will need to create at least one track with Ardour (here in the example: Audio1):


 Then, in JACK we will have to connect the output from Qsynth to Ardour:


And lastly is just a matter of recording (first we have to select in which track we will be recording, in this case Audio 1,and then proceed with the "main" recording):


Adding other audio tracks (from an external mic, another software, etc.) would follow similar steps in Ardour. The last step is just to "export session to audiofile".

A  basic MIDI-performance obtained in this way can be found at vimeo