2
2
// Author Taehoon Moon 2014
3
3
// MIT License
4
4
5
- import { Clef , ClefType } from './clef' ;
5
+ import { Clef , ClefAnnotatiomType , ClefType } from './clef' ;
6
6
import { Glyph } from './glyph' ;
7
7
import { Note } from './note' ;
8
- import { RenderContext } from './rendercontext' ;
9
8
import { Category } from './typeguard' ;
10
9
11
10
/** ClefNote implements clef annotations in measures. */
@@ -14,16 +13,19 @@ export class ClefNote extends Note {
14
13
return Category . ClefNote ;
15
14
}
16
15
17
- protected glyph : Glyph ;
18
- protected clef : Clef ;
16
+ protected clef : ClefType ;
17
+ protected annotation ?: ClefAnnotatiomType ;
19
18
protected type : string ;
19
+ protected size : string ;
20
20
21
21
constructor ( type : string , size ?: string , annotation ?: string ) {
22
22
super ( { duration : 'b' } ) ;
23
23
this . type = type ;
24
- this . clef = new Clef ( type , size , annotation ) ;
25
- this . glyph = new Glyph ( this . clef . clef . code , this . clef . clef . point ) ;
26
- this . setWidth ( this . glyph . getMetrics ( ) . width ) ;
24
+ const clef = new Clef ( type , size , annotation ) ;
25
+ this . clef = clef . clef ;
26
+ this . annotation = clef . annotation ;
27
+ this . size = size === undefined ? 'default' : size ;
28
+ this . setWidth ( Glyph . getWidth ( this . clef . code , this . clef . point , `clefNote_${ this . size } ` ) ) ;
27
29
28
30
// Note properties
29
31
this . ignore_ticks = true ;
@@ -32,22 +34,17 @@ export class ClefNote extends Note {
32
34
/** Set clef type, size and annotation. */
33
35
setType ( type : string , size : string , annotation : string ) : this {
34
36
this . type = type ;
35
- this . clef = new Clef ( type , size , annotation ) ;
36
- this . glyph = new Glyph ( this . clef . clef . code , this . clef . clef . point ) ;
37
- this . setWidth ( this . glyph . getMetrics ( ) . width ) ;
37
+ this . size = size ;
38
+ const clef = new Clef ( type , size , annotation ) ;
39
+ this . clef = clef . clef ;
40
+ this . annotation = clef . annotation ;
41
+ this . setWidth ( Glyph . getWidth ( this . clef . code , this . clef . point , `clefNote_${ this . size } ` ) ) ;
38
42
return this ;
39
43
}
40
44
41
45
/** Get associated clef. */
42
46
getClef ( ) : ClefType {
43
- return this . clef . clef ;
44
- }
45
-
46
- /** Set associated context. */
47
- setContext ( context : RenderContext ) : this {
48
- super . setContext ( context ) ;
49
- this . glyph . setContext ( this . getContext ( ) ) ;
50
- return this ;
47
+ return this . clef ;
51
48
}
52
49
53
50
preFormat ( ) : this {
@@ -58,26 +55,22 @@ export class ClefNote extends Note {
58
55
/** Render clef note. */
59
56
draw ( ) : void {
60
57
const stave = this . checkStave ( ) ;
61
- if ( ! this . glyph . getContext ( ) ) {
62
- this . glyph . setContext ( this . getContext ( ) ) ;
63
- }
58
+ const ctx = this . checkContext ( ) ;
64
59
65
60
this . setRendered ( ) ;
66
61
const abs_x = this . getAbsoluteX ( ) ;
67
62
68
- this . glyph . setStave ( stave ) ;
69
- this . glyph . setYShift ( stave . getYForLine ( this . clef . clef . line ?? 0 ) - stave . getYForGlyphs ( ) ) ;
70
- this . glyph . renderToStave ( abs_x ) ;
63
+ Glyph . renderGlyph ( ctx , abs_x , stave . getYForLine ( this . clef . line ) , this . clef . point , this . clef . code , {
64
+ category : `clefNote_ ${ this . size } ` ,
65
+ } ) ;
71
66
72
67
// If the Vex.Flow.Clef has an annotation, such as 8va, draw it.
73
- if ( this . clef . annotation !== undefined ) {
74
- const attachment = new Glyph ( this . clef . annotation . code , this . clef . annotation . point ) ;
75
- if ( ! attachment . getContext ( ) ) {
76
- attachment . setContext ( this . getContext ( ) ) ;
77
- }
68
+ if ( this . annotation !== undefined ) {
69
+ const attachment = new Glyph ( this . annotation . code , this . annotation . point ) ;
70
+ attachment . setContext ( ctx ) ;
78
71
attachment . setStave ( stave ) ;
79
- attachment . setYShift ( stave . getYForLine ( this . clef . annotation . line ) - stave . getYForGlyphs ( ) ) ;
80
- attachment . setXShift ( this . clef . annotation . x_shift ) ;
72
+ attachment . setYShift ( stave . getYForLine ( this . annotation . line ) - stave . getYForGlyphs ( ) ) ;
73
+ attachment . setXShift ( this . annotation . x_shift ) ;
81
74
attachment . renderToStave ( abs_x ) ;
82
75
}
83
76
}
0 commit comments