我希望能在网页中写音乐符号和和弦。
是否有可以做到这一点的库(像数学公式的Mathjax)可用? 如果没有,那么还有什么其他方法可以获得体面的结果?
我希望能在网页中写音乐符号和和弦。
是否有可以做到这一点的库(像数学公式的Mathjax)可用? 如果没有,那么还有什么其他方法可以获得体面的结果?
看一下这个使用 HTML5 canvas 创建乐谱的 JavaScript API。
http://www.vexflow.com/docs/tutorial.html
例子:
<canvas width=700 height=100"></canvas>
更新日期(2014年3月18日)
接着:
var canvas = $("div.three div.a canvas")[0];
var renderer = new Vex.Flow.Renderer(canvas,
Vex.Flow.Renderer.Backends.CANVAS);
var ctx = renderer.getContext();
var stave = new Vex.Flow.Stave(10, 0, 500);
// Add a treble clef
stave.addClef("treble");
stave.setContext(ctx).draw();
var notes = [
// Dotted eighth E##
new Vex.Flow.StaveNote({ keys: ["e##/5"], duration: "8d" }).
addAccidental(0, new Vex.Flow.Accidental("##")).addDotToAll(),
// Sixteenth Eb
new Vex.Flow.StaveNote({ keys: ["eb/5"], duration: "16" }).
addAccidental(0, new Vex.Flow.Accidental("b")),
// Half D
new Vex.Flow.StaveNote({ keys: ["d/5"], duration: "h" }),
// Quarter Cm#5
new Vex.Flow.StaveNote({ keys: ["c/5", "eb/5", "g#/5"], duration: "q" }).
addAccidental(1, new Vex.Flow.Accidental("b")).
addAccidental(2, new Vex.Flow.Accidental("#"))
];
// Helper function to justify and draw a 4/4 voice
Vex.Flow.Formatter.FormatAndDraw(ctx, stave, notes);
这会产生:
希望能帮到你!
我认为你可以尝试使用音乐字体,比如这两种:http://www.fontspace.com/david-rakowski/lassus或http://www.fontspace.com/robert-allgeyer/musiqwik(还可能有其他的,我进行了快速搜索...)
虽然不完美,但这可能会起到作用。您需要将字体集成到您的网站中,并使用适当的CSS规则使其正常工作...
我使用Lilypond作为音符语言,并编写了小型PHP脚本,从Markdown文档中解析出Lilypond脚本并用渲染后的PNG文件替换它们。
您可以查看这个WordPress插件的处理方式。
我之前使用了Lassus字体,正如其他答案中提到的那样。http://www.fonts2u.com/lassus.font - 下载@fontface版本,其中包括链接它的样式表和一个HTML文档作为示例。
我是这样使用的:
@font-face {font-family:"Lassus";
src:url("LASSUS.eot?") format("eot"),url("LASSUS.woff") format("woff"),url("LASSUS.ttf") format("truetype"),url("LASSUS.svg#Lassus") format("svg");
font-weight:normal;
font-style:normal;
}