[Haskell-cafe] help with musical data structures
Henning Thielemann
lemming at henning-thielemann.de
Sun Nov 15 05:26:46 EST 2009
On Sat, 14 Nov 2009, Michael Mossey wrote:
> I'm pretty new to Haskell so I don't know what kind of data structure I
> should use for the following problem. Some kind of arrays, I guess.
>
> One data item, called OrientedPCSet ("oriented pitch class set," a musical
> term) will represent a set whose members are from the range of integers 0
> to 11. This could probably be represented efficiently as some kind of bit
> field for fast comparison.
In Haskore there is a type for pitch classes:
http://hackage.haskell.org/packages/archive/haskore/0.1/doc/html/Haskore-Basic-Pitch.html
but maybe it is not what you need, since it distinguishes between C sharp
and D flat and so on. It has Ix and Ord instance and thus can be used for
Array and Map, respectively. Both of them are of course not as efficient
as a bitset in your case. To this end you might try
http://hackage.haskell.org/packages/archive/EdisonCore/1.2.1.3/doc/html/Data-Edison-Coll-EnumSet.html
> Another item, PitchMatrix, will be a 2-d matrix of midi pitch numbers.
> This matrix will be constructed via a backtracking algortithm with an
> evaluation function at each step. It will probably be constructed by
> adding one number at a time, starting at the top of a column and working
> down, then moving to the next column. This matrix should probably be
> implemented as an array of some sort for fast lookup of the item row x,
> column y. It doesn't require update/modification to be as fast as lookup,
> and it won't get very large, so some sort of immutable array may work.
A MIDI pitch type can be found in
http://hackage.haskell.org/packages/archive/midi/0.1.4/doc/html/Sound-MIDI-Message-Channel-Voice.html#t%3APitch
it also is in Ix class and thus you can define
type PitchMatrix a = Array (Pitch, Pitch) a
The Pitch pair means that you have a pair as array index, thus an
two-dimensional array. Arrays provide the (//) operator for bundled
updates. Sometimes it is possible to use the (//) operator or the array
construction only once, because the order of filling the array is
determined by data dependencies and laziness. E.g. there is an LU
decomposition algorithm that does not need array element updates, only a
clever order of filling the matrix:
http://hackage.haskell.org/packages/archive/dsp/0.2.1/doc/html/Matrix-LU.html
You may be also interested in the haskell-art mailing list in order to
discuss musical experiments:
http://lists.lurk.org/mailman/listinfo/haskell-art
See also
http://www.haskell.org/haskellwiki/Category:Music
More information about the Haskell-Cafe
mailing list