Skip to content

Instantly share code, notes, and snippets.

@adamf
Created February 21, 2011 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamf/837273 to your computer and use it in GitHub Desktop.
Save adamf/837273 to your computer and use it in GitHub Desktop.
Diff of vexflow for adding notation-only display, but note flags don't render
diff --git a/src/formatter.js b/src/formatter.js
index 71333b6..a21a7d2 100644
--- a/src/formatter.js
+++ b/src/formatter.js
@@ -31,12 +31,12 @@ Vex.Flow.Formatter.FormatAndDraw = function(ctx, stave, notes, width) {
// Helper function to format and draw a single voice
Vex.Flow.Formatter.FormatAndDrawTab = function(ctx,
tabstave, stave, tabnotes, notes, width) {
+
var tabvoice = new Vex.Flow.Voice(Vex.Flow.TIME4_4).setStrict(false);
tabvoice.addTickables(tabnotes);
var notevoice = new Vex.Flow.Voice(Vex.Flow.TIME4_4).setStrict(false);
notevoice.addTickables(notes);
-
var formatter = new Vex.Flow.Formatter().
joinVoices([tabvoice]).
joinVoices([notevoice]).
diff --git a/tabdiv/tabdiv.js b/tabdiv/tabdiv.js
index 6cd2e2f..cc5b34e 100644
--- a/tabdiv/tabdiv.js
+++ b/tabdiv/tabdiv.js
@@ -118,28 +118,32 @@ Vex.Flow.TabDiv.prototype.drawInternal = function() {
var notestave = staves[i].note;
var voice_tabnotes = tabnotes[i];
var voice_ties = ties[i];
+ var voice_notes = notes[i];
- // Draw stave
- tabstave.setWidth(this.width - 50);
- tabstave.setContext(this.ctx).draw();
+ if(tabstave) {
+ tabstave.setWidth(this.width - 50);
+ tabstave.setContext(this.ctx).draw();
+ }
- // Draw note stave (if available)
if (notestave) {
- var voice_notes = notes[i];
notestave.setWidth(this.width - 50);
notestave.setContext(this.ctx).draw();
+ }
- if (voice_tabnotes && voice_notes) {
- Vex.Flow.Formatter.FormatAndDrawTab(
- this.ctx,
- tabstave, notestave,
- voice_tabnotes, voice_notes,
- this.width - 100);
- }
- } else {
- // Draw notes and bends
+ if (notestave && tabstave) {
+ Vex.Flow.Formatter.FormatAndDrawTab(
+ this.ctx,
+ tabstave, notestave,
+ voice_tabnotes,
+ voice_notes,
+ this.width - 100);
+ } else if (tabstave) {
if (voice_tabnotes) Vex.Flow.Formatter.FormatAndDraw(
this.ctx, tabstave, voice_tabnotes, this.width - 100);
+ } else if (notestave) {
+ if (voice_notes) Vex.Flow.Formatter.FormatAndDraw(
+ this.ctx, notestave, voice_notes, this.width - 100);
+
}
// Draw ties
diff --git a/vextab/vextab.js b/vextab/vextab.js
index 7a15ab6..53c5dc8 100644
--- a/vextab/vextab.js
+++ b/vextab/vextab.js
@@ -84,6 +84,7 @@ Vex.Flow.VexTab.prototype.init = function() {
current_stave: -1,
current_duration: "8",
has_notation: false,
+ has_tab: true,
beam_start: null
};
@@ -208,6 +209,8 @@ Vex.Flow.VexTab.prototype.parseKeyValue = function(token) {
Vex.Flow.VexTab.prototype.parseTabStave = function(tokens) {
var has_standard_notation = false;
+ var has_tablature = true;
+ // XXX must make it so you can't have both has_tablature & has_notation false
for (var i = 1; i < tokens.length; ++i) {
var pair = this.parseKeyValue(tokens[i]);
if (pair.key.toLowerCase() == "notation") {
@@ -217,12 +220,19 @@ Vex.Flow.VexTab.prototype.parseTabStave = function(tokens) {
default: this.parseError(
'notation must be "true" or "false": ' + pair.value);
}
+ } else if (pair.key.toLowerCase() == "tablature") {
+ switch (pair.value.toLowerCase()) {
+ case "true": has_tablature = true; break;
+ case "false": has_tablature = false; break;
+ default: this.parseError(
+ 'tablature must be "true" or "false": ' + pair.value);
+ }
} else {
this.parseError("Invalid parameter for tabstave: " + pair.key)
}
}
- this.genTabStave({ notation: has_standard_notation });
+ this.genTabStave({ notation: has_standard_notation, tablature: has_tablature });
}
/**
@@ -979,23 +989,27 @@ Vex.Flow.VexTab.prototype.genElements = function() {
*/
Vex.Flow.VexTab.prototype.genTabStave = function(params) {
var notation = false;
+ var tablature = true;
if (params) notation = params.notation;
+ if (params) tablature = params.tablature;
var notestave = notation ?
new Vex.Flow.Stave(
20, this.height, 380).addTrebleGlyph().setNoteStartX(40) :
null;
- var tabstave = new Vex.Flow.TabStave(20,
+ var tabstave = tablature ?
+ new Vex.Flow.TabStave(20,
notation ? notestave.getHeight() + this.height : this.height, 380).
- addTabGlyph().setNoteStartX(40);
+ addTabGlyph().setNoteStartX(40) : null;
this.elements.staves.push({tab: tabstave, note: notestave});
- this.height += tabstave.getHeight() +
+ this.height += (tablature ? tabstave.getHeight() : null) +
(notation ? notestave.getHeight() : null);
this.state.current_stave++;
this.state.has_notation = notation;
+ this.state.has_tablature = tablature;
this.elements.tabnotes[this.state.current_stave] = [];
this.elements.notes[this.state.current_stave] = [];
this.elements.ties[this.state.current_stave] = [];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment