{
   "labels" : [
      "gui",
      "notation"
   ],
   "id" : "1-5ho",
   "is_private" : null,
   "code" : "// this code relies on the Fosc quark. Very capable, but mostly undocumented.\r\n// Here's the result of half a day of searching and grepping... :)\r\n(\r\nvar svg;\r\nvar img;\r\nvar options;\r\nvar window;\r\nvar score;\r\nvar chord;\r\nvar staff;\r\nvar chordview;\r\n\r\n// configure path to lilypond\r\nFosc.lilypondPath = \"/usr/bin/lilypond\";\r\n\r\n// make a chord\r\nchord = FoscChord(\"c' e' fs' gs' bf'\", 1); //or: chord = FoscChord([60, 67, 69], 1);\r\n// display the chord with easy heads (comment out for normal note heads)\r\nchord.attach(FoscLilyPondLiteral(\"\\\\easyHeadsOn\"));\r\n// embed the chord in a staff\r\nstaff = FoscStaff([\r\n\tFoscVoice([\r\n\t\tchord\r\n\t])\r\n]);\r\n// don't show time signature, clef and bar lines\r\nstaff.removeCommands.add('Time_signature_engraver');\r\nstaff.removeCommands.add('Clef_engraver');\r\nstaff.removeCommands.add('Bar_engraver');\r\n\r\n// make sure the produced svg file is cropped; use a large staff size for sufficient resolution\r\n// 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\r\nscore = FoscLilyPondFile([\"#(ly:set-option 'crop #t)\", staff], staffSize:40);\r\n// write chord.svg and also chord.cropped.svg\r\nsvg = score.writeSVG(path:PathName.tmp +/+ \"chord.svg\", clean:false);\r\n// open the cropped svg\r\nimg = Image.openSVG(PathName.tmp +/+ \"chord.cropped.svg\");\r\n\r\n// embed the generated svg in a window\r\nwindow = Window.new(\"test\", Rect(100,100,150,100)).front;\r\nwindow.view.background_(Color.new(153,255, 102));\r\nchordview = UserView(window);\r\nchordview.drawFunc = {\r\n\t|uview|\r\n\tvar viewwidth = uview.bounds.width;\r\n\tvar viewheight = uview.bounds.height;\r\n\tvar imgwidth = img.width;\r\n\tvar imgheight = img.height;\r\n\tvar left = (viewwidth - imgwidth)/2;\r\n\tvar top = (viewheight - imgheight)/2;\r\n\timg.drawAtPoint(left@top); // draw with fixed size centered in user view\r\n};\r\na = ({ Button(window) } ! 3) ++ chordview.minSize_(100@100) ++ ({ Button(window) } ! 3);\r\nwindow.layout = HLayout(*a);\r\n)",
   "author" : "56228375",
   "name" : "Show a chord in music notation in a sclang window",
   "ancestor_list" : [],
   "description" : "showing a chord in a supercollider window in music notation using the Fosc quark"
}
