lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LilyLib: SuperCollider to Lilypond Translation


From: bbarros
Subject: LilyLib: SuperCollider to Lilypond Translation
Date: Mon, 14 Apr 2008 11:19:25 -0300

Hi,

I recently made a set of classes that try to translate data from
SuperCollider to the Lilypond format. Useful if you want to see this
data in a traditional notated score rapidly and use this in a
composition.

Since my experience with Lilypond is minimal,  I would appreciate very
much some criticism and help from you guys. Specially how I can make
this sequence look good in Lilypond :-)

For the rhythms I chose to work with rhythm trees, i.e. with a lists
of measures and a list of lists of the proportions inside each
measure.

Cheers!
Bernardo


- Examples:

* enter list of notes, list of measure sizes in eight-notes (can be
multiple of 0.5, like 4.5), proportions inside each measure (it
calculates the proper tuplet):

MakeLilySequence.quaterTones(notes, measures, proportions, tempo);

MakeLilySequence.quaterTones([60, 56.5, 56, 67, 65.5, 55.5, 54.5, 45,
56, 67], [4, 3, 5], [[1, 1, 1], [3, 1], [4, 1, 1, 1, 1]])

/time 4/8  /times 2/3 { c'8   gisih8   gis8   }  /time 3/8  /times 3/4
{  g'8.  fih'16 }  /time 5/8  /times 5/8 { gih4  fisih16   a,16
gis16  g'16  }

MidiLy.quaterToneArray([60, 60.5, 61, 61.5]);
[ c' , cih' , cis' , cisih'  ]

LilyOutput.makePdfMidi("File") // this create a pdf and a midi file
(command line) from a .ly file in the directory
../Music/LilypondFiles/File.ly

LilyOutput.viewPdf("File") // this open the PDF

LilyOutput.playMidi("File") // this play the midi with a program called qtplay

MakeLilyRhythm.new(4, [1, 1, 1, 1, 1])   // first input is the size of
the measure in Eight notes, and the array is the proportions inside
that measure
[ 4/8, [ 16, 16, 16, 16, 16 ], [ 5, 4 ] ]  // returns some values
usable for the lilypond notation, the third one is the Tuplet


- Classes:
(put in SuperCollider Extensions Folder


/////////////////////////////////////////////////////////////
//Translate Midi values and rhythm trees to Lilypond Format//
/////////////////////////////////////////////////////////////
///////////////////////////////////// bernardo barros 2008 //

/// feel free to comment, test, improve etc
/// send an email: bernardobarros #at& *$gmail$* $%dot&* com


MidiLy {

       *halfToneNote  { |midiNote|
var index, pitch, notes, octave, pitchList, octaveList, octaveIndex;
index = (midiNote % 12).round; // arredonda para quartos de tom
octaveIndex = (midiNote/12).floor;
pitchList = #[c,cis,d,dis,e,f,fis, g, gis,a, ais, b]; // para semitons
octaveList =  [",,,,",",,,",",,",",", " ","'","''","'''", "''''"];
pitch = pitchList[index];
octave = octaveList[octaveIndex];
^notes = (pitch ++ octave).asString;
               }

       *quaterToneNote  { |midiNote|
var index, pitch, notes, octave, pitchList, octaveList, octaveIndex;
index = (midiNote % 12).round(0.5); // arredonda para quartos de tom
octaveIndex = (midiNote/12).floor;
pitchList = #[c,cih,cis,cisih,d,dih,dis,eeh,e,eih,f,fih, fis,fisih, g,
gih, gis,gisih, a, aih, ais, beh, b, bih]; // para quartos de tom
octaveList =  [",,,,",",,,",",,",",", " ","'","''","'''", "''''"];
pitch = pitchList[index*2];
octave = octaveList[octaveIndex];
^notes = (pitch ++ octave).asString;  }

       *halfToneArray  { |midiNote|
var index, pitch, notes, octave, pitchList, octaveList, octaveIndex, noteList;
index = (midiNote % 12).round; // arredonda para quartos de tom
noteList = Array.new;
octaveIndex = (midiNote/12).floor;
pitchList = #[c,cis,d,dis,e,f,fis, g, gis,a, ais, b]; // para semitons
octaveList =  [",,,,",",,,",",,",",", " ","'","''","'''", "''''"];
pitch = pitchList[index];
octave = octaveList[octaveIndex];
notes = pitch.size.do({ arg i; noteList = noteList.add(pitch[i] ++
octave[i]) });
^noteList; }

       *quaterToneArray  { |midiNote|
var index, pitch, notes, octave, pitchList, octaveList, octaveIndex, noteList;
index = (midiNote % 12).round(0.5); // arredonda para quartos de tom
noteList = Array.new;
octaveIndex = (midiNote/12).floor;
pitchList = #[c,cih,cis,cisih,d,dih,dis,eeh,e,eih,f,fih, fis,fisih, g,
gih, gis,gisih, a, aih, ais, beh, b, bih]; // para quartos de tom
octaveList =  [",,,,",",,,",",,",",", " ","'","''","'''", "''''"];
pitch = pitchList[index*2];
octave = octaveList[octaveIndex];
notes = pitch.size.do({ arg i; noteList = noteList.add(pitch[i] ++
octave[i]) });
^noteList; }

    }


MakeLilyRhythm  {

       *new  { |measure, proportion|

var eightNomeScale, measureScaleLily, measureIndex, measuresOutputList;
var eightsSum;
var multipliedProportionSum, multipliedProportionFactor;
var noteDurationList, noteDurationScale, noteNotationScale,
noteDurationOutputList;
var noteDurationOutput;
var tuplet, m, n; // Tuplet calculation

//// converter a lista de compassos em notação Lilypond

eightNomeScale = (0.5, 1 .. 16);
measureScaleLily = #["1/16", "1/8", "3/16", "2/8", "5/16", "3/8",
"7/16", "4/8", "9/16", "5/8", "11/16", "6/8", "13/16", "7/8", "15/16",
"8/8", "17/16", "9/8", "19/16", "10/8", "21/16", "11/8", "25/16",
"12/8", "27/16", "13/8", "29/16", "14/8", "31/16", "15/8", "33/16",
"16/8"];
measureIndex = ((measure * 2 - 1)).round;
measuresOutputList = measureScaleLily[measureIndex];

//// multiplicar a proporção até que ela seja 1 grau maior que a
quantidade de colcheias total do compasso

multipliedProportionSum = proportion.asArray.sum;
multipliedProportionFactor = 1;

       while(  {       multipliedProportionSum < (measure*8) },

                       {       multipliedProportionSum =
multipliedProportionSum * 2;
                               multipliedProportionFactor =
multipliedProportionFactor * 2; });


//// Obter uma lista de valores ritmicos das notas

noteDurationList = proportion * multipliedProportionFactor; // os
valores das durações
noteNotationScale = #["128", "128.", "64" , "64." , "32" , "32." ,
"16" , "16." , "8" , "8." , "4" , "4." , "2" , "2." , "1"];
noteDurationScale = [1, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96];

noteDurationOutput = Array.new;

noteDurationList.do({ arg i;

               noteDurationOutput =
noteDurationOutput.add(noteNotationScale[noteDurationScale.indexIn(i)]);

                                                       });

//// Obter a quiáltera necessária para a notação
// noteDurationList = proportion * multipliedProportionFactor; // os
valores das durações
// measure * 8 = duração total do compasso

m =  noteDurationList.sum / (gcd((measure * 8), noteDurationList.sum));
n =  (measure * 8) / (gcd((measure * 8), noteDurationList.sum));

tuplet = [m,n];

// retorna: Compasso em notação Lilypond, Array de durações no formato
Lilypond e quiáltera

^[measuresOutputList, noteDurationOutput, tuplet];


       }

               }



MakeLilySequence        {

       *quaterTones  { arg notes = [60], measures = [2], proportions = [1],
tempo = 60;


var lilyNotes, lilyNotesIndex ;
var measuresIndex, proportionsIndex;
var materialOutputString;

lilyNotes = MidiLy.quaterToneArray(notes);
lilyNotesIndex = 0;

max(measures.size, proportions.size).do({ arg i;

               var measureRhythm;
               var measure, measureProportion, measureTuplet;
               var measureTupletString;
               var measureOutputString;
               var measureNoteString;

               measureRhythm = MakeLilyRhythm.new(measures[i],
proportions[i]); //
array com o tamanho do compasso e proporcoes

               measure = measureRhythm[0]; // este compasso

               measureProportion = measureRhythm[1] ;

               measureTuplet = measureRhythm[2];

               measureTupletString = measureTuplet[1].asString ++
"/".asString ++
measureTuplet[0].asString;

               measureNoteString = " ";

               measureProportion.do({ arg i;

                               measureNoteString = measureNoteString ++ (" " ++
lilyNotes[lilyNotesIndex] ++  i).asString;

                               lilyNotesIndex = lilyNotesIndex + 1;    });



       materialOutputString = materialOutputString ++ (47.asAscii ++ "time "
++  measure.asString ++ " " ++ 47.asAscii ++ "times " ++
measureTupletString ++  " { " ++ measureNoteString ++ " }");



       });



^materialOutputString;


       }

               }



/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////// Make a PDF and a MIDI File from a .ly file //////
/////////////////////////////////////////////////////////////
// need Lilypond and qtplay Installed in Applications Folder//
/////////////////////////////////////////////////////////////

// Lilypond: http://lilypond.org/web/
// QTPlay: http://rainbowflight.googlepages.com/#qtplay


LilyOutput {

       *makePdfMidi { arg fileName = "temp", folder =
"/Users/dranreb/Music/LilypondFiles/";
       ("/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o" ++
folder ++ fileName ++ " " ++ folder ++ fileName ++
".ly").asString.unixCmd

               }


       *viewPdf  { arg fileName = "temp", folder =
"/Users/dranreb/Music/LilypondFiles/";
       ("/Applications/Preview.app/Contents/MacOS/Preview " ++ folder ++
fileName ++ ".pdf").unixCmd

               }


       *playMidi  { arg fileName = "temp", folder =
"/Users/dranreb/Music/LilypondFiles/";
       ("/Applications/qtplay1.3.1/qtplay  " ++  folder ++ fileName ++
".midi").unixCmd;

               }



    }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]