Skip to content

Commit

Permalink
Makes stave centre property of stave
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Apr 23, 2024
1 parent 413c35a commit 9759b3f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 35 deletions.
31 changes: 31 additions & 0 deletions data/drum-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"events": [
[0, "meter", 4, 1],
[1, "A♭2", 0.25, 0.5],
[3, "A♭2", 0.25, 1],
[5, "A♭2", 0.25, 1],
[7, "A♭2", 0.25, 1],
[0, "B1", 0.3, 1],
[1.5, "B1", 0.3, 0.5],
[3, "B1", 0.3, 1],
[4.5, "B1", 0.3, 0.5],
[6, "B1", 0.3, 1],
[7, "B1", 0.3, 1],
[1, "D2", 0.3, 1],
[2.5, "D2", 0.3, 0.5],
[4, "D2", 0.3, 1],
[5.5, "D2", 0.3, 0.5],
[7, "D2", 0.3, 1],
[0, "F3", 0.25, 1],
[1, "F3", 0.25, 0.5],
[1.5, "F3", 0.25, 0.5],
[2, "F3", 0.25, 0.5],
[3, "F3", 0.25, 0.5],
[3.5, "F3", 0.25, 0.5],
[4, "F3", 0.25, 1],
[5, "F3", 0.25, 0.5],
[5.5, "F3", 0.25, 0.5],
[6, "F3", 0.25, 1],
[7, "F3", 0.25, 1]
]
}
6 changes: 3 additions & 3 deletions modules/create-symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function createSymbols(symbols, bar) {
}

// Up ledger lines
let ledgerrows = subtractStaveRows(bar.stave, 'G5', head.pitch);
let ledgerrows = subtractStaveRows(bar.stave, bar.stave.topPitch, head.pitch);

if (ledgerrows > 0) {
symbols.splice(n++, 0, assign({}, head, {
Expand All @@ -314,7 +314,7 @@ function createSymbols(symbols, bar) {

// Down ledger lines
else {
ledgerrows = subtractStaveRows(bar.stave, head.pitch, 'D4');
ledgerrows = subtractStaveRows(bar.stave, head.pitch, bar.stave.bottomPitch);
if (ledgerrows > 0) {
symbols.splice(n++, 0, assign({}, head, {
type: 'downledger',
Expand Down Expand Up @@ -511,7 +511,7 @@ function createBars(events, beatkeys, stave, keyscale, meter, transpose) {

const events0 = eventsAtBeat(events, 0);
meter = events0.find((event) => event[1] === 'meter') || meter ;
console.log(meter);

// First bar. Where meter is at beat 0, also inserts a time signature.
let bar = createBar(0, stave, keyscale, meter, tieheads);
bars.push(bar);
Expand Down
8 changes: 8 additions & 0 deletions modules/staves.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ export const chords = {

export const treble = {
clef: 'treble',
topPitch: 'G5',
centerPitch: 'B4',
bottomPitch: 'D4',
getSpelling: toSpelling
};

export const bass = {
clef: 'bass',
topPitch: 'B3',
centerPitch: 'D3',
bottomPitch: 'F2',
getSpelling: toSpelling
};

Expand All @@ -25,7 +29,9 @@ export const piano = {
getSpelling: toSpelling,

// TEMP
topPitch: 'G5',
centerPitch: 'B4',
bottomPitch: 'D4',

// TODO: there should be four parts available, soprano alto, tenor bass
getPart: function(pitch) {
Expand Down Expand Up @@ -145,7 +151,9 @@ export const percussion = {
clef: 'percussion',

// TEMP
topPitch: 'C4',
centerPitch: 'B4',
bottomPitch: 'A4',

getSpelling: (key, name, type, transpose) => {
if (type === 'chord') {
Expand Down
89 changes: 57 additions & 32 deletions scribe-script/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,21 @@ export default define(element('scribe-script', {
}
}
}, {
/**
clef="treble"
Choose the default clef to render. Not that if the rendered sequence
contains clef events, they override this choice. Possible clefs are
`"treble"`, `"bass"`, `"piano"`, `"drums"`, `"percussion"`, `"chord"`.
**/
clef: {
/**
clef="treble"
Choose the default clef to render. Not that if the rendered sequence
contains clef events, they override this choice. Possible clefs are
`"treble"`, `"bass"`, `"piano"`, `"drums"`, `"percussion"`, `"chord"`.
**/
attribute: function(value) { this.clef = value; },

/**
.clef = "treble"
Choose the default clef to render. Not that if the rendered sequence
contains clef events, they override this choice. Possible clefs are
`"treble"`, `"bass"`, `"piano"`, `"drums"`, `"percussion"`, `"chord"`.
**/
get: function() { return getInternals(this).clef.value; },
set: function(value) {
if (!staves[value]) {
Expand All @@ -227,12 +234,17 @@ export default define(element('scribe-script', {
}
},

/**
key="C"
Choose the default key to render.
**/
key: {
/**
key="C"
Choose the key signature.
**/
attribute: function(value) { this.key = value; },

/**
.key="C"
Choose the key signature.
**/
get: function() { return getInternals(this).key.value; },
set: function(value) {
const internals = getInternals(this);
Expand All @@ -248,28 +260,34 @@ export default define(element('scribe-script', {
}
},

/**
meter="4/4"
Sets the meter. Note that this is overridden by any `"meter"` event found at
beat `0` in the data.
**/
meter: {
/**
meter="4/4"
Sets the meter. Note that this is overridden by any `"meter"` event
found at beat `0` in the data.
**/
attribute: function(value) { this.meter = value; },

/**
.meter = "4/4"
Sets the meter. Note that this is overridden by any `"meter"` event
found at beat `0` in the data.
**/
get: function() { return getInternals(this).meter.value; },
set: function(value) { getInternals(this).meter.value = value; }
},

/**
transpose="0"
Sets transposition value for display of notation.
**/

/**
.transpose = 0
Sets transposition value for display of notation.
**/
transpose: {
/**
transpose="0"
Sets transposition value for display of notation.
**/
attribute: function(value) { this.transpose = value; },

/**
.transpose = 0
Sets transposition value for display of notation.
**/
get: function() { return getInternals(this).transpose.value; },
set: function(value) {
// Set integer from value
Expand All @@ -279,16 +297,23 @@ export default define(element('scribe-script', {
}
},

/**
type="application/json"
Mimetype or type of data to fetch. Possible mimetypes:
- `"text/x-abc"`
- `"text/plain"`
- `"application/json"`
**/

type: {
/**
type="application/json"
Mimetype or type of data to fetch. Possible mimetypes:
- `"text/x-abc"`
- `"text/plain"`
- `"application/json"`
**/
attribute: function(value) { this.type = value; },

/**
.type = "application/json"
Mimetype or type of data to fetch. Possible mimetypes:
- `"text/x-abc"`
- `"text/plain"`
- `"application/json"`
**/
writable: true
},

Expand Down

0 comments on commit 9759b3f

Please sign in to comment.