Skip to content

Commit

Permalink
parenthesised noteheads
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Jan 1, 2022
1 parent 9817b2c commit 62110d8
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/easyscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class EasyScoreGrammar implements Grammar {
return { token: '[0-9whq]+' };
}
TYPES(): Rule {
return { token: '[rRsSmMhHgG]' };
return { token: '[rRsSmMhHgGpP]' };
}
LPAREN(): Rule {
return { token: '[(]' };
Expand Down
24 changes: 24 additions & 0 deletions src/fonts/bravura_glyphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ export const BravuraFont = {
ha: 250,
o: 'm 451 -180 l 451 180 l 0 180 l 0 -180 z',
},
noteheadParenthesis: {
x_min: -73,
x_max: 368,
y_min: -180,
y_max: 182,
ha: 362,
o: 'm 52 -249 b -30 -144 3 -212 -14 -190 b -52 4 -45 -102 -52 -56 b 52 252 -52 118 -36 179 l 46 262 b -105 3 -49 197 -105 124 b 45 -259 -105 -109 -48 -200 z m 382 -259 b 530 3 474 -202 530 -108 b 379 262 530 122 474 200 l 373 252 b 478 4 462 180 478 118 b 456 -144 478 -56 471 -102 b 373 -249 439 -190 422 -212 z',
},
noteheadParenthesisRight: {
x_min: -36,
x_max: 73,
y_min: -181,
y_max: 181,
ha: 362,
o: 'm -43 -261 b 105 1 49 -203 105 -109 b -46 261 105 121 49 199 l -52 251 b 53 3 37 179 53 117 b 32 -145 53 -58 46 -104 b -52 -251 14 -192 -3 -213 z',
},
noteheadParenthesisLeft: {
x_min: 0,
x_max: 109,
y_min: -181,
y_max: 181,
ha: 362,
o: 'm 157 -251 b 75 -145 108 -213 91 -192 b 53 3 60 -104 53 -58 b 157 251 53 117 69 177 l 151 261 b 0 1 56 196 0 122 b 150 -261 0 -111 58 -202 z',
},
augmentationDot: {
x_min: 0,
x_max: 100,
Expand Down
24 changes: 24 additions & 0 deletions src/fonts/petaluma_glyphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ export const PetalumaFont = {
ha: 262.4340638216071,
o: 'm 217 190 b 439 186 304 190 372 190 b 467 180 448 184 458 183 b 492 145 484 176 492 167 b 490 -124 490 56 490 -33 b 488 -141 490 -130 488 -135 b 456 -170 488 -163 478 -168 b 118 -183 344 -176 230 -181 b 29 -184 89 -183 60 -192 b 0 -148 4 -180 0 -168 b 1 29 1 -89 1 -30 l 1 156 b 36 190 3 187 4 190 b 217 190 102 192 168 190 z',
},
noteheadParenthesis: {
x_min: -70.190112022022,
x_max: 329,
y_min: -196,
y_max: 201,
ha: 397,
o: 'm 344 -279 b 382 -262 361 -288 370 -272 b 405 -233 390 -255 399 -245 b 474 9 455 -158 468 -73 b 416 228 474 78 448 174 b 364 282 403 249 387 271 b 344 289 359 285 350 288 b 331 279 338 289 333 287 b 325 248 328 269 325 258 b 338 225 325 238 328 229 b 412 138 379 207 396 174 b 445 1 433 92 445 45 b 346 -217 445 -81 410 -154 b 336 -252 340 -223 336 -238 b 344 -279 336 -265 338 -276 z m 19 -274 b 35 -282 24 -279 30 -281 b 49 -265 42 -282 46 -275 b 52 -243 50 -256 52 -249 b 36 -210 52 -230 49 -220 b -60 -59 -16 -173 -35 -114 b -73 9 -69 -39 -73 -16 b 33 223 -73 92 -24 189 b 50 265 43 229 50 249 b 33 288 50 278 46 289 b 4 272 23 288 14 275 b -9 261 0 269 -4 265 b -101 23 -58 193 -105 124 b -37 -206 -104 -52 -75 -130 b 19 -274 -23 -232 -6 -255 z',
},
noteheadParenthesisRight: {
x_min: -30,
x_max: 82,
y_min: -199.08429092881173,
y_max: 206,
ha: 405.0842909288117,
o: 'm -17 -282 b 24 -264 -6 -297 12 -272 b 60 -219 40 -253 52 -236 b 117 1 96 -150 112 -75 b 118 16 118 6 118 12 b 109 73 118 36 112 55 b 4 279 99 154 68 226 b -23 297 -4 287 -13 297 b -37 289 -27 297 -32 294 b -43 266 -42 285 -43 276 b -32 225 -43 251 -37 229 b 84 -7 48 170 84 82 b 32 -184 84 -69 65 -132 b -10 -222 22 -200 4 -209 b -24 -258 -20 -232 -24 -245 b -17 -282 -24 -266 -22 -276 z',
},
noteheadParenthesisLeft: {
x_min: 0,
x_max: 106,
y_min: -197,
y_max: 197,
ha: 394,
o: 'm 134 -284 b 138 -281 135 -284 137 -284 b 145 -268 144 -278 145 -274 l 144 -253 b 107 -180 138 -225 121 -204 b 42 13 71 -120 42 -56 b 49 73 42 32 43 52 b 137 210 62 128 95 171 b 153 255 147 219 153 239 b 145 278 153 265 151 274 b 130 284 140 281 135 284 b 98 259 117 284 108 268 b 0 37 35 203 1 131 b 118 -268 9 -69 53 -173 b 134 -284 121 -274 127 -284 z',
},
augmentationDot: {
x_min: 0,
x_max: 96,
Expand Down
10 changes: 10 additions & 0 deletions src/notehead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ export class NoteHead extends Note {
if (this.noteType === 's') {
const staveSpace = this.checkStave().getSpacingBetweenLines();
drawSlashNoteHead(ctx, this.duration, head_x, y, stem_direction, staveSpace);
} else if (this.noteType === 'p') {
Glyph.renderGlyph(ctx, head_x, y, glyph_font_scale, this.glyph_code, {
category: this.custom_glyph ? `noteHead.custom.${categorySuffix}` : `noteHead.standard.${categorySuffix}`,
});
Glyph.renderGlyph(ctx, head_x - 4, y, glyph_font_scale, 'noteheadParenthesisLeft', {
category: `noteHead.standard.noteheadParenthesisLeft`,
});
Glyph.renderGlyph(ctx, head_x + this.width + 1, y, glyph_font_scale, 'noteheadParenthesisRight', {
category: `noteHead.standard.noteheadParenthesisRight`,
});
} else {
Glyph.renderGlyph(ctx, head_x, y, glyph_font_scale, this.glyph_code, {
category: this.custom_glyph ? `noteHead.custom.${categorySuffix}` : `noteHead.standard.${categorySuffix}`,
Expand Down
37 changes: 37 additions & 0 deletions src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const validNoteTypes: Record<string, { name: string }> = {
m: { name: 'muted' },
s: { name: 'slash' },
g: { name: 'ghost' },
p: { name: 'parenthesized' },
};

const customNoteHeads: Record<string, { code: string }> = {
Expand Down Expand Up @@ -941,6 +942,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadDoubleWhole',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadDoubleWhole',
},
},
},

Expand Down Expand Up @@ -998,6 +1003,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadWhole',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadWhole',
},
},
},

Expand Down Expand Up @@ -1056,6 +1065,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadHalf',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadHalf',
},
},
},

Expand Down Expand Up @@ -1115,6 +1128,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},

Expand Down Expand Up @@ -1179,6 +1196,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},

Expand Down Expand Up @@ -1243,6 +1264,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},

Expand Down Expand Up @@ -1307,6 +1332,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},

Expand Down Expand Up @@ -1371,6 +1400,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},

Expand Down Expand Up @@ -1435,6 +1468,10 @@ const durationCodes: Record<string, any> = {
// Ghostnote
code_head: 'noteheadBlack',
},
p: {
// Parenthesis drawn by notehead.draw()
code_head: 'noteheadBlack',
},
},
},
};
31 changes: 30 additions & 1 deletion tests/easyscore_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const EasyScoreTests = {
run('Draw Basic Slash', drawBasicSlashTest);
run('Draw Ghostnote Basic', drawGhostBasicTest);
run('Draw Ghostnote Dotted', drawGhostDottedTest);
run('Draw Parenthesised', drawParenthesisedTest);
run('Draw Accidentals', drawAccidentalsTest);
run('Draw Beams', drawBeamsTest);
run('Draw Tuplets', drawTupletsTest);
Expand Down Expand Up @@ -60,7 +61,7 @@ function createShortcuts(score: EasyScore) {
*/
function basic(): void {
const score = new EasyScore();
const mustPass = ['c4', 'c#4', 'c4/r', 'c#5', 'c3/m', 'c3//m', 'c3//h', 'c3/s', 'c3//s', 'c3/g', 'c3//g'];
const mustPass = ['c4', 'c#4', 'c4/r', 'c#5', 'c3/m', 'c3//m', 'c3//h', 'c3/s', 'c3//s', 'c3/g', 'c3//g, 'c3/p', 'c3//p'];
const mustFail = ['', '()', '7', '(c#4 e5 g6'];

mustPass.forEach((line) => equal(score.parse(line).success, true, line));
Expand Down Expand Up @@ -354,6 +355,34 @@ function drawGhostDottedTest(options: TestOptions): void {
expect(0);
}

function drawParenthesisedTest(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 600, 350);
const score = f.EasyScore();
const system = f.System();

const { voice, notes } = createShortcuts(score);

system
.addStave({
voices: [
voice(notes('(d4 e4 g4)/q/p, c4/q, c4/q/r, c4/q/p', { stem: 'down' })),
voice(notes('c#5/h/p., c5/q/p', { stem: 'up' })),
],
})
.addClef('treble');

system
.addStave({
voices: [voice(notes('c#3/q/p, cn3/q/p, bb3/q/p, d##3/q/p', { clef: 'bass' }))],
})
.addClef('bass');
system.addConnector().setType(StaveConnector.type.BRACKET);

f.draw();
expect(0);
}


function drawAccidentalsTest(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 600, 350);
const score = f.EasyScore();
Expand Down
3 changes: 3 additions & 0 deletions tools/fonts/config/valid_codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ module.exports = {
noteheadDiamondBlack: 'v22',
noteheadSquareWhite: 'vd3',
noteheadSquareBlack: 'vd2',
noteheadParenthesis: 'vxx',
noteheadParenthesisRight: 'vxx',
noteheadParenthesisLeft: 'vxx',
// noteshapeSquareWhite: 'vd5', // rectangular note head (not found in bravura)
// noteshapeSquareBlack: 'vd4', // rectangular note head (not found in bravura)

Expand Down

0 comments on commit 62110d8

Please sign in to comment.