Wednesday, 9 January 2013

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 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, 24 December 2012

Keeping a LiveCD distribution up-to-date

After learning how to put a number of LiveCD distributions in a USB stick (all with persistent modes): http://angel-de-vicente.blogspot.com.es/2012/11/multi-boot-usb-stick.html, I have quickly started using that quite a lot, and it has soon become clear that after a while I need to keep the distributions up-to-date. So, I learnt how to keep the distribution relevant and up-to-date and the persistent file small enough. I mostly followed http://this.is.thoughtcrime.org.nz/multi-boot-bt5-from-usb-with-grub2, but I modified slightly:


angelv@palas:~$ mkdir /tmp/iso /tmp/squash
angelv@palas:~$ sudo mount -o loop /media/angelv/angelv/ubuntustudio-12.10-dvd-amd64.iso /tmp/iso
[sudo] password for angelv: 
mount: warning: /tmp/iso seems to be mounted read-only.
angelv@palas:~$ sudo mount -o loop /tmp/iso/casper/filesystem.squashfs /tmp/squash


angelv@palas:~$ mkdir /tmp/changes
angelv@palas:~$ sudo mount /media/angelv/angelv/persistent/ubuntustudio/casper-rw /tmp/changes

angelv@palas:~$ mkdir /tmp/merged
angelv@palas:~$ sudo mount -t aufs -o br=/tmp/changes=rw:/tmp/squash none /tmp/merged

angelv@palas:~$ sudo mksquashfs /tmp/merged/ ~/ubuntustudio.squashfs
angelv@palas:~$ sudo umount /tmp/merged /tmp/squash /tmp/changes 

angelv@palas:~$ mkdir -p ubuntu_studio_changed/casper
angelv@palas:~$ mv  ubuntustudio.squashfs ubuntu_studio_changed/casper/filesystem.squashfs
angelv@palas:~$ mkdir /tmp/newiso
angelv@palas:~$ sudo mount -t aufs -o br=ubuntu_studio_changed=rw:/tmp/iso none /tmp/newiso
angelv@palas:~$ 

angelv@palas:~$ cd /tmp/newiso/
angelv@palas:/tmp/newiso$ sudo genisoimage -R -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o /home/angelv/new_ubuntu_studio.iso /tmp/newiso/

angelv@palas:/tmp/newiso$ cd
angelv@palas:~$ sudo umount /tmp/newiso 
angelv@palas:~$ sudo umount /tmp/iso 

angelv@palas:~$ mv new_ubuntu_studio.iso /media/angelv/angelv/ubuntustudio-12.10-dvd-amd64.iso
angelv@palas:~$ dd if=/dev/zero of=casper-rw bs=1M count=3072
angelv@palas:~$ mkfs.ext3 -F casper-rw
angelv@palas:~$ mv casper-rw /media/angelv/angelv/persistent/ubuntustudio/casper-rw

I try it, and I can see that I get the same as I had before, but now the casper-rw file is empty, so I can start a new round of customizations. Installation / removal of software goes all to the casper-rw file, so when we recreate the ISO file to incorporate the casper-rw file, we are also generating a ISO file with all the same software as our persistent-mode version.

Saturday, 8 December 2012

Remote Desktop with x11vnc

For years now I have been using screen (byobu) for remote connection to my workstation. I do most of my work in the terminal window, so that works well, but for those moments when I needed to also work graphically I have been slowly migrating...

Years ago I was using VNC, but at the time the whole thing was quite slow and a bit frustrating for regular use. A couple of years ago I discovered Xpra, with the up-to-date fork Winswitch. Very nice project: it works like screen but for X11, so I could keep graphical applications open and don't worry about broken internet connections. Also, I didn't have to export the whole desktop, only the applications that I was interested in. The downside was this would generate another X11 session, so that if at work I was doing some exciting work in an application and later I wanted to continue that from home it was not possible. I had to restart the application (not too bad, but a bit cumbersome at times).

In any case I was happy with xpra until I switched to Ubuntu 12.10. For some reason (probably due to the Nvidia drivers I'm using at my workstation) I could not get it working (it was working OK with the same hardware and Ubuntu 11.10, so perhaps I just had to spend some more time configuring it), so I gave up and tried x11vnc. x11vnc will export the whole desktop (I would prefer just individual applications), but not a new one, just your "real X11 display (i.e. one attached to a physical monitor, keyboard, and mouse: a Workstation or a SunRay session) from far away".  This has the advantage that I don't have to plan in advance when I'm going to work remotely or end up (as it was happening often to me before) with the same application open twice (one in my real X11 display and another one in the virtual one created by xpra). I was expecting, as for my old VNC experience, sluggish behaviour again over my home ADSL connection, but I was pleasantly surprised.

Installation was very easy. At the workstation apt-get install x11vnc, and at the laptop apt-get install  ssvnc

Running it is also very easy. After reading the manual page, I first generated a vnc password with the command vncpasswd, and then I came up with the following command line to run at the workstation:

x11vnc -display :0 -rfbauth .vnc/passwd -localhost -rfbport 5900 -forever -ncache -bg -o .vnc/x11vnc.log

The arguments mean in turn: it will attach to the "real X11 display" (-display :0) in my workstation;  it will use the previously generated .vnc/passwd file for authentication; for extra security it will allow only connections from localhost (obviouly I didn't get this working to connect physically from my workstation at work, but from my home laptop I create a ssh tunnel to the port 5900, so that when I connect to x11vnc via the viewer, the connection looks like it came from localhost); it will use port 5900; the server will not quite after the viewer exits, so this will be available forever; it will send extra information to the viewer, so it can cache portions of the display to make it work faster; -bg will send it to the background, and a log will be generated at .vnc/x11vnc.log.

Connecting remotely to my workstation is then performed via ssvnc. I just connect to localhost (will use by default port 5900, which is being tunnelled to my workstation):



Also, the -ncache option sends a lot of extra data that I don't want to see, so you can do that by cropping the display in the Y direction (in my case to 1024 pixels, which matches the resolution at my workstation):




With that in place, the experience is pretty good. Don't take my word for it and see a recording of it in action:  https://vimeo.com/55151357


EDIT (13/12/2012): In order to avoid other people interacting with my workstation when I'm connected remotely I came up with the following solution, which works pretty well. This is not bulletproof, and a malicious user could easily jump these protections, but to avoid accidental use of my workstation while I'm working remotely is sufficient. I now run x11vnc as:

x11vnc -display :0 -rfbauth .vnc/passwd -accept "/home/angelv/.vnc/turnoffconsole.sh" -gone "/home/angelv/.vnc/turnonconsole.sh" -localhost -rfbport 5900 -ncache -forever -o .vnc/x11vnc.log

The only difference is the -accept argument, which points to turnoffconsole.sh (this will: physically turn off the monitors, and they will not come back to life by moving the mouse or typing at the keyboard; disable the mouse and the keyboard, so somebody cannot interact with my session even accidentally):

#!/bin/bash                                                                                                                                                   
sudo vbetool dpms off
xinput set-prop "Dell Dell USB Keyboard" "Device Enabled" 0
xinput set-prop "Dell Premium USB Optical Mouse" "Device Enabled" 0


and the -gone argument, which points to turnonconsole.sh (which will revert the stuff done by turnoffconsole.sh):

#!/bin/bash                                                                                                                                                   
sudo vbetool dpms on
xinput set-prop "Dell Dell USB Keyboard" "Device Enabled" 1
xinput set-prop "Dell Premium USB Optical Mouse" "Device Enabled" 1


vbetool needs to be run with administrator privileges, but I include myself in the sudoers list (with visudo), so that I don't need to type the password for it:

angelv ALL=NOPASSWD:/usr/sbin/vbetool

Tuesday, 27 November 2012

Multi-boot USB Stick

Some time ago I discovered MultiSystem, which easily let's you create a USB stick with a number of different distributions (some basic instructions, for example, at http://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Create-a-Multi-boot-USB-Stick-with-MultiSystem).

The program is quite nice as it is (though the GUI is a little bit awkward), but I wanted to have a couple of things done differently, so the resulting USB stick could be more suited to my needs. Mainly two things:


  1. Allow persistent mode for several of the distros (by default you can only get persistent mode for one of them).
  2. Allow the usage of some of the space of the pendrive as a common storage area for all distributions.


In order to get it done I first installed MultiSystem:

sudo sh -c 'echo "deb http://liveusb.info/multisystem/depot all main" >> /etc/apt/sources.list'
wget -q http://liveusb.info/multisystem/depot/multisystem.asc -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install multisystem


Then, using the MultiSystem GUI I installed Xubuntu 12.10 and Linux Mint 14 in the pendrive. Then I chose one of them and using MultiSystem added the persistent mode. This will create the appropriate entry in the grug.cfg file in the pendrive, and it will also create a file, casper-rw. I delete the created casper-rw file and created my own one as ext3 (the one created with MultiSystem is ext2), instructions from http://blog.evolya.fr/public/appli/tuto-qemu/How_to_create_a_larger_casper-rw_loop_block_file___USB_Pen_Drive_Linux.htm:


dd if=/dev/zero of=casper-rw bs=1M count=1024
mkfs.ext3 -F casper-rw
Copy the new casper-rw file to the pendrive


But instead of leaving the casper-rw file in the root directory of the pendrive, I put it in the directory:

/persistent/xubuntu/

After that I modified the grub.cfg in the pendrive (/boot/grub/grub.cfg) so that it will look for that particular casper-rw file, and a different username and hostname will be used (the relevant options are persistent-path, hostname, username and userfullname, instructions taken from http://www.linuxcertif.com/man/7/casper/):

linux (loop)/casper/vmlinuz root=UUID=4088-F6F9 debian-installer/language=en keyboard-configuration/layoutcode=es  iso-scan/filename=/xubuntu-12.10-desktop-amd64.iso boot=casper showmounts persistent persistent-path=/persistent/xubuntu/ hostname=nomada username=angelv userfullname=AngeldeVicente file=/cdrom/preseed/xubuntu.seed noprompt quiet splash --

With that we have the way open to repeat the procedure for Linux Mint, another casper-rw will be created, which we get rid of and follow the steps above to create a personalized casper-rw file for that particular distro.

When booting a computer from the resulting USB stick, the GRUB options window looks like the following (there are two options for Xubuntu and two for Linux Mint: one of them will ignore the persistent (casper-rw) file and will just boot the clean liveCD version; the second one will use the persistent file, so that we can install some new software, change some settings, etc. and they will survive reboots):



As for the common storage for all the distributions, that was simply done with gparted, so that I resized the fat32 partition to leave space (10GB) for another partition (ext3), which can be mounted from the live USB distros, and used as a common space for documents, etc.

As an example, here it is the Linux Mint (with persistent option) desktop, in which the "common" partition is the ext3 partition created in the USB stick itself for common storage across the different distros: 






This is not an issue for me yet, but at some point I will probably make a lot of changes to the different distros. In order to merge the changes with the original LiveCD distribution, I will try to follow the instructions at http://this.is.thoughtcrime.org.nz/multi-boot-bt5-from-usb-with-grub2

EDIT (21/12/2012): After a few successful installations, I found that one of the persistence files was getting small, so I looked for information on resizing the casper-rw file. For adding to the file, this works OK:


dd if=/dev/zero bs=1M count=500 >> casper-rw
resize2fs casper-rw

For decreasing the size of the casper-rw, we probably should go something like:

dd if=/dev/zero of=newfile bs=1M count=number of blocks
mkfs.ext3 -F
newfile

mount -o loop oldfile /mnt/mountold
mount -o loop newfile /mnt/mountnew


Sunday, 18 November 2012

Lexmark X1190 with Ubuntu 12.10 (64 bits)

I have upgraded to Ubuntu 12.10, and the steps to make the X1190 work with this version are very similar to what we did for Ubuntu 11.10 (http://angel-de-vicente.blogspot.com.es/2012/07/lexmark-x1190-with-ubuntu-1110-64-bits.html), but easier.

The scanner works by default, so nothing to be done in there.

For the printer, the steps are the same as per 11.10, but we don't need to install libstdc++5:i386, since that is now part of ia32-libs.

Friday, 13 July 2012

Lexmark X1190 with Ubuntu 11.10 (64 bits)

I have installed this printer for a number of Ubuntu distributions, and I always forget to write the details, so here they go:

Printer (mostly from http://blog.rachaelbond.com/lexmark/)
  1. With synaptic, install ia32-libs, libstdc++5:i386 and rpm
  2. Download  CJLZ600LE-CUPS-1.0-1.TAR.gz, for example from: software.rachaelbond.com/CJLZ600LE-CUPS-1.0-1.TAR.gz
  3. tar xzvf CJLZ600LE-CUPS-1.0-1.TAR.gz
  4. tail -n +143 z600cups-1.0-1.gz.sh > install.tar.gz
  5. tar xzvf install.tar.gz
  6. sudo rpm --force-debian -ivh z600cups-1.0-1.i386.rpm z600llpddk-2.0-1.i386.rpm --nodeps
  7. sudo service cups restart
  8. configure printer from the system settings with driver Lexmark-Z600

 Scanner

  1. I get rid of libsane and libsane-extras
  2. I follow more or less the instructions by Ashley Hooper at: https://bugs.launchpad.net/ubuntu/+source/xsane/+bug/774475
  3. Instead of the 386 packages, I install the amd64 ones: http://ftp.us.debian.org/debian/pool/main/s/sane-backends-extras/libsane-extras_1.0.21.2_amd64.deb and http://ftp.us.debian.org/debian/pool/main/s/sane-backends/libsane_1.0.21-9_amd64.deb
  4. In order to avoid upgrading these by mistake, I fix them:
    gksudo gedit /etc/apt/preferences.d/libsane
    Now paste the below contents into the file, save and exit.
    Package: libsane
    Pin: version 1.0.21-9
    Pin-Priority: 900
  5. I confirm it is working using the apt-cache policy command: $ apt-cache policy libsane
  6. Now either simple-scan or xsane work nicely with the scanner.