com.e1.mxdublin
Class DublinHelper

java.lang.Object
  extended by com.e1.mxdublin.DublinHelper

public class DublinHelper
extends Object

Sets of helpers utilities for building note/chord/time values from strings and bridging python/java with pd/max.


Field Summary
static Hashtable<String,int[]> chords
          Chords definition to used with DublinHelper.chord(String chord).
static Hashtable<String,int[]> scales
          Scales definitions to be used with chord progressions.
 
Constructor Summary
DublinHelper()
           
 
Method Summary
static PyObject atom2py(Atom atom)
          Transform a atom to a python object.
static PyObject atoms2py(Atom[] atoms)
          Transform a list of atoms to a python sequence.
static Object choice(Object[] obj)
          Returns a random object from the list.
static int[] chord(String chord)
          Build a chord definition from a string.
static String note2trkr(int midiValue)
          Returns the string value (tracker format) of a midi note value
static String prettyTm(int tm)
          Returns a string representation of the trail position in quarter note.
static String prettyTm(int tm, int base)
          Returns a string representation of the trail position in quarter note
static int[] prog(String def)
          Build a chord definition based on the harmonic progression from a scale.
static int[] progInterval(String degree)
          Returns the interval used based on a chord progression degree.
static Atom py2atom(PyObject obj)
          Transform a python object into an atom.
static Atom[] py2atoms(PyObject obj)
          Transform a python sequence into atoms.
static float[] range(float start, float end, float step)
          Returns a list containing an arithmetic progression of floats.
static float rnd()
          Random number generator, returns something between 0.0 and 1.0.
static int tm2int(String tm)
          Translate a time reference in string format into a int in ppq.
static int[] tm2list(String list)
          Transform a list of time in a single string to a array of int in ppq:
static int trkr2note(String note)
          Parse a note in tracker format to midi format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chords

public static Hashtable<String,int[]> chords
Chords definition to used with DublinHelper.chord(String chord). This hashtable contains the chords definition in a array of int; example: DublinHelper.chords.put("M", new int[] {0, 4, 7});

See http://www.looknohands.com/chordhouse/piano for chord name reference


scales

public static Hashtable<String,int[]> scales
Scales definitions to be used with chord progressions.

Constructor Detail

DublinHelper

public DublinHelper()
Method Detail

py2atom

public static Atom py2atom(PyObject obj)
Transform a python object into an atom.

Parameters:
obj - the python object
Returns:
the the atom representation

py2atoms

public static Atom[] py2atoms(PyObject obj)
Transform a python sequence into atoms.

Parameters:
obj - the python object
Returns:
the the atom[] representation

atom2py

public static PyObject atom2py(Atom atom)
Transform a atom to a python object.

Parameters:
atom - the atom to cast
Returns:
the python object encapsulation

atoms2py

public static PyObject atoms2py(Atom[] atoms)
Transform a list of atoms to a python sequence.

Parameters:
atoms - the atoms to cast
Returns:
the python sequence of atoms

tm2list

public static int[] tm2list(String list)
Transform a list of time in a single string to a array of int in ppq:
"1:1.5:2.1/2" -> [ 480, 720, 1200 ]

Parameters:
list - the list in string format
Returns:
array of int in ppq

tm2int

public static int tm2int(String tm)
Translate a time reference in string format into a int in ppq. Support float reference and numbers in fraction format; like 1, 1.5 or 2.1/2.

Parameters:
tm - reference in string format
Returns:
time value in ppq

trkr2note

public static int trkr2note(String note)
Parse a note in tracker format to midi format.
"C-1" -> 13, "C#1" -> 14, etc...

Parameters:
note - the tracker note in string
Returns:
the midi note value

note2trkr

public static String note2trkr(int midiValue)
Returns the string value (tracker format) of a midi note value
13 -> "C-1", 14 -> "C#1", etc...

Parameters:
midiValue - the midi note value note
Returns:
the tracker note in string

chord

public static int[] chord(String chord)
Build a chord definition from a string. The first argument is the note value in tracker format and the second is the chord name based on the static field chords in DublinHelper. The last optional one is the chord degre of inversion. the chord inversion is not tested on unsual chords.

Parameters:
chord - the chord name ex:E-2:M7<1 or G#3:M:-1
Returns:
the midi notes representing the chord

progInterval

public static int[] progInterval(String degree)
Returns the interval used based on a chord progression degree.

Parameters:
degree - the degree of the chord to returns
Returns:
the interval between notes based on the chord degree

prog

public static int[] prog(String def)
Build a chord definition based on the harmonic progression from a scale. The first argument is the root note and the type of scale. If you want a C Major, select 'C-5M'. For C minor, simply use 'C-5m'. The second argument is the chord degree in numeric value (we are not using the roman values to be easier to parse and understand). The last argument is the chord inversion if needed.

Example

DublinHelper.prog("C-5:5:-1") DublinHelper.prog("A-5m:3:1)

Parameters:
def - chord degree definition
Returns:
the midi notes to be played

rnd

public static float rnd()
Random number generator, returns something between 0.0 and 1.0. This is the same thing as java.util.Random.nextFloat except that you share a common instance of the java.util.Random object.

Returns:
a pseudorandom number between 0.0 and 1.0

choice

public static Object choice(Object[] obj)
Returns a random object from the list.

Returns:
a object within the list

range

public static float[] range(float start,
                            float end,
                            float step)
Returns a list containing an arithmetic progression of floats. Very useful with 'for' loops in jython.

Parameters:
start - where the range start
end - when the range should stop (and not putting this value)
step - to number of step between each iteration
Returns:
list of floats

prettyTm

public static String prettyTm(int tm,
                              int base)
Returns a string representation of the trail position in quarter note

Parameters:
tm - the position of the trail
base - denominator to divide the quarter note
Returns:
the quarter note position in string

prettyTm

public static String prettyTm(int tm)
Returns a string representation of the trail position in quarter note. The fraction will be automatically be reduced.

Parameters:
tm - the position of the trail
Returns:
the quarter note position in string