// title: Show a chord in music notation in a sclang window // author: 56228375 // description: // showing a chord in a supercollider window in music notation using the Fosc quark // code: // this code relies on the Fosc quark. Very capable, but mostly undocumented. // Here's the result of half a day of searching and grepping... :) ( var svg; var img; var options; var window; var score; var chord; var staff; var chordview; // configure path to lilypond Fosc.lilypondPath = "/usr/bin/lilypond"; // make a chord chord = FoscChord("c' e' fs' gs' bf'", 1); //or: chord = FoscChord([60, 67, 69], 1); // display the chord with easy heads (comment out for normal note heads) chord.attach(FoscLilyPondLiteral("\\easyHeadsOn")); // embed the chord in a staff staff = FoscStaff([ FoscVoice([ chord ]) ]); // don't show time signature, clef and bar lines staff.removeCommands.add('Time_signature_engraver'); staff.removeCommands.add('Clef_engraver'); staff.removeCommands.add('Bar_engraver'); // make sure the produced svg file is cropped; use a large staff size for sufficient resolution // use a hack to make lilypond crop the svg file since Fosc doesn't expose lilypond command line arguments, and I didn't find another way to insert raw lilypond code score = FoscLilyPondFile(["#(ly:set-option 'crop #t)", staff], staffSize:40); // write chord.svg and also chord.cropped.svg svg = score.writeSVG(path:PathName.tmp +/+ "chord.svg", clean:false); // open the cropped svg img = Image.openSVG(PathName.tmp +/+ "chord.cropped.svg"); // embed the generated svg in a window window = Window.new("test", Rect(100,100,150,100)).front; window.view.background_(Color.new(153,255, 102)); chordview = UserView(window); chordview.drawFunc = { |uview| var viewwidth = uview.bounds.width; var viewheight = uview.bounds.height; var imgwidth = img.width; var imgheight = img.height; var left = (viewwidth - imgwidth)/2; var top = (viewheight - imgheight)/2; img.drawAtPoint(left@top); // draw with fixed size centered in user view }; a = ({ Button(window) } ! 3) ++ chordview.minSize_(100@100) ++ ({ Button(window) } ! 3); window.layout = HLayout(*a); )