Hacking gnu-linux things

This is a handy way to control running instances of VLC from external scripts (if you invoke vlc in the script, there are better interfaces like rc). It’s also useful if want to control VLC through keyboard shortcuts while it’s running in the background. If your window manager doesn’t pass the shortcuts to the background process (xfwm4 at least doesn’t), you can start by issuing this in a shell:

dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

It should start/pause the backgrounded player. If it works, you can assign a shortcut to the command using the standard keyboard shortcut editor of your window manager.

VLC adheres to the Media Player Remote Interface Specification (MPRIS) which opens up for the commands listed here.  The usual start/pause etc. are in the .Player interface.

Note that some commands require a numeric argument. Seek for example needs a number of microseconds to seek forward or backward. But you don’t just give it the number. You must manually specify the type of the argument like this:

dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:"2000000"

There are other weird (unpredictable ?) syntaxes for rates and volumes. Check this post for more examples.

20160921 093815

20160921 093815
Sonic Visualiser (SV) is a great opensource software to analyse various aspects of sound. Here I explain how to measure the scale of an instrument. I will use this tiny (maybe) Indonesian flute as an example.

The point in finding its scale is to program Yoshimi, a soft synth, to play in tune with it. The microtonal tuning of Yoshimi will be covered in another tutorial.

Useful and (imho) elegant bash script found here to remove duplicate files based on their md5 sum. I use it to get rid on duplicate emails in my mailbox.

declare -A arr
shopt -s globstar

for file in **; do
  [[ -f "$file" ]] || continue

  read cksm _ < <(md5sum "$file")
  if ((arr[$cksm]++)); then 
    echo "rm $file"

Of course, remove the echo on line 10 to put the rm in effect. I actually replace the rm by a mv $file ~/.local/share/Trash/files/, for more safety.

I recently ripped a 5 CDs collection of "1001 sound effects". There was no CDDB info for it, so the tracks came all as "01 - 1001 Sound effects.flac", "02 - 1001 Sound effects.flac" and so on. This makes the ripped files pretty useless. I needed meaningful filenames in order to later find specific effects.

Fortunately, a website had the complete list of 1001 names (someone may have OCRd the booklet). I copied/pasted it in a text file named ListeCD1.txt, one name per line. Then with the help of this stackoverflow answer,  I could batch-rename all the files in the CD1 directory (I actually used cp to a new directory rather than mv in place, just to be safe)

files=( *.flac )


while read -r newname; do

    cp "${files[$i]}" "renamed/`printf %02d $(( i+1 ))`_$newname.flac";

    (( i++ ));

done < ListeCD1.txt


Command to remove older kernels on a linux machine:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Check with an extra 'uname -r' that the current kernel is not amongst those being removed.