24 Sep 2014

Conquer the Melodyspace (DOSED)

I like music and I like technical aspects of music.

How great would it be if you were able to perfectly characterize melodies in mathematical terms? You could populate an abstract "melodyspace" with your own melodies and find similar or totally different ones.

Lets reduce the complexity right away and consider only pitch and note length. These two quantities offer plenty possibilities to characterize melodies. Later we could expand our analysis by considering meter, dynamics in general, harmonic context (scale) and probably many more aspects.
I think it is sufficient to consider only a relative pitch and note length. You could shift a whole melody by some semitones and it would still be the same.

What is a note in our system?
We consider only two aspects. This results in a 2-tuple, e.g. $\left( \mathrm{A4}, \frac{1}{4} \right)$, of some pitch value, here A4 (see scientific notation), and a length, 1/4th.
But this is an absolute measure. We could look a little to the side and shift the focus to the gap between the notes - lets talk in terms of intervals! The pitch is represented as some stepsize, e.g. $+5$ for a perfect fourth (see interval), and could be limited to meaningful values. No stepsize should lead to a lower note than C0 or a higher note than G9 (highest possible MIDI note). Interestingly this restricts the ability to transpose the melody. The melody C0 G9 C0 G9 can't be shifted at all - in contrast to something like C4 E4 C4 E4.
It would be also a good idea to normalize the note length to a whole note and limit it to values between $\frac{1}{32}$ and $1$.
Finally this would lead to a 2-tuple of the form $\left( \pm n, \frac{1}{m} \right)$, with $n,m \in \mathbb{N}$ and some arbitrary meaningful restrictions for $n$ and $m$.

What is a melody in our system?
A melody would be just a sequence of notes. Something like
$$\left(\mathrm{A4}, \frac{1}{2} \right),\left( +5, \frac{1}{2} \right), \left( +5, \frac{1}{2} \right), \left( -7,  1 \right) $$
Which corresponds to the sequence A4, D5, G5, C5, if you start with a note A4.
To underline the generic nature it could be a good idea to define a special tuple for the first note. Something like $\left( n', \frac{1}{m} \right)$, with $n' \in  \left[ n_{\mathrm{lowest}}, n_{\mathrm{highest}}\right]$ and $m$ as above. $\left[ n_{\mathrm{lowest}}, n_{\mathrm{highest}}\right]$ is the interval of possible starting notes, which has to be computed according to the limit of C0 as the lowest and G9 as the highest note.

Creating the melodyspace:
What quantities can we think of to characterize such a melody?
There are quantities which do not rely on the order of the involved intervals. These are for example a mean-interval + the according variance, the amount of dissonant/consonant intervals, the length of the melody, the mean note-length + according variance, etc.
Other quantities could be dependent on the order. I don't know if this is important later, but it surely is interesting!

And what the heck is this melodyspace I am talking of?
If you consider every of the above quantities as an (independent) direction in a multidimensional space, then a melody is characterized by a vector in this space.
For example you could imagine that we want to characterize a melody only by its total length and its tendency to be "rising" or "falling". (0 would mean something like 100% falling, e.g. the melody C9 C8 C7 C6, and 1 would mean something like 100% rising, like A6 A7 A8 A9)
In this case the melodyspace would only be a two dimensional graph with the length on the x-axis and the tendency on the y-axis.
Both example melodies, C9 C8 C7 C6 and A6 A7 A8 A9, would have a $x$ value of $4$, but the former would be at $y = 0$ and the later would be at $y = 1$

I have no clue at all if this leads to something useful, but I surely will implement this model in some programming language and look where it leads to.

22 Sep 2014

DOSED: DO Something Every Day

I like to make big plans. And usually I end up with nothing at all, since big plans, which aren't divided into manageable subtasks, are hard to accomplish.

Combined with my ever-changing focus and with my tendency to procrastinate, to waste my time with the limitless distractions of the internet, I figured it would be a good idea to establish some kind of obligation.

I want to work on my plans in a somewhat stochastically fashion. I try to create at least one, maybe even a trivial, puzzle-piece each day. No matter what my current project is. In the end I will have increased the probability that something useful grows out of this big pile of puzzle-pieces.
My hope is that I'll develop a feeling of how much I am actually working, if I write my findings down.

The bottom line is, that it is better to DO something (little), than to PLAN on doing something big.

8 Sep 2014

Logitech G600 in (Arch-)Linux

I like optimizing my workflow and therefore I like potent input devices!

I use the Logitech G600 mouse and it offers an insane amount of buttons. But how do you make use of those in Linux?

If you want to make use of the G-shift functionality and to improve the further configuration-experience, you should (sadly) plug this mouse into a windows machine with the Logitech software installed. Here you are able to define three profiles, which are stored internally in the mouse.
You should start by choosing cool colours for the RGB-LEDs. After this is done you should define all standard mouse buttons, profile-change and g-shift button to be the same for all three profiles. The twelve thumb buttons should have different symbols for every possible case! (normal and g-shift for three profiles = 6 sets. You don't need to make use of all three profiles if you don't need them)
I chose something like {1, 2, 3, ..., 9, 0, ß, ´} for the first profile and the keypad numbers 0 - 9 and keypad + and - for the G-shift case of the first profile. Another possibility would be the letters A - Z. With this you make sure that for example G9 (first thumb button) and G-shift+G9 are received as different events in Linux.
Maybe it's possible to define your wished shortcuts here, but I want to have a more generic way.

Back to Linux:
It didn't take long until I noticed, that this mouse is actually registering two events in /dev/input/ . One for the normal mouse-stuff (like clicking, you know) - and the other for all the fancy extra buttons and functionality. The second one is actually acting like a keyboard.


    sudo evtest 

you will be able to detect the scancodes of each button-event. First choose the event corresponding to the "keyboard-part" of the G600 and then hit each combination possible. (G9, G10, ..., G20, G-shift+G9, ... , G-shift+G20, for each profile you want to use)
You are searching for lines like:

    Event: time 1410191730.438246, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e

The bold part is the scancode you will need for this specific button.

Now we want to make a rule that those buttons behave differently for this device only. For our rule we should know the vendor and product ID of our USB-device. This is done through
    lsusb -v

this leads to something like:
    idVendor           0x046d Logitech, Inc.     
    idProduct          0xc24a G600 Gaming Mouse 

The creation of such a rule is nowadays done through the udev-hwdb (hardwaredatabase). In Arch you have to create a file in /etc/udev/hwdb.d/
with the name


There we need to write the line


followed by many definitions of the form
    KEYBOARD_KEY_<hex scan code>=<key code identifier>

where <hex scan code> is the scancode we obtained with evtest and <key code identifier> is a keycode of a currently (unused!) keyboard symbol. (You can find a list of possible keycodes at here)
I used some Japanese stuff, because I'm quite sure that I never have to use a Japanese keyboard. So this looks something like:


After this you need to run

    udevadm hwdb --update

and you need to reconnect the device. (e.g. physically)

Now we can use xbindkeys and xautomation to define the shortcuts.

    xbindkeys -k

for each button. This will result into something like:

    "(Scheme function)"       

Now create a file named ".xbindkeysrc" in your homefolder and add one entry of the above format per button-event. (again: G-shift+GX is separate from GX) The entries could look like this:

    "xte 'keydown Super_L' 'key j' 'keyup Super_L'" 
    #G18 +G-shift    
    "xte 'keydown Super_L' 'keydown Shift_L' 'key j' 'keyup Shift_L' 'keyup Super_L'"       

Now just start xbindkeys, and create some way of autostarting xbindkeys and you are done.

I used this procedure to define some Awesome WM shortcuts (like switching the current tag and changing layouts), and to improve browsing in Firefox. (changing tabs, closing tabs, reopen the last tab, back, forward, etc.)   

UPDATE (26.06.2015):

Today I had an issue that the mapping doesn’t work anymore (after an update). Long story short: with
instead of 

in the beginning of the hwdb file it worked again.