Skip to content

Commit 85990be

Browse files
committed
melody as text
1 parent 8c463b8 commit 85990be

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

fieldeditors.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ namespace microcode {
232232
tempo: number
233233
}
234234

235+
export function melodyToNotes(melody: Melody) {
236+
const notes = melody.notes.split("")
237+
let result = ""
238+
for (const n of notes) {
239+
if (n == ".") result += "- "
240+
else result += noteNames[parseInt(n)] + " "
241+
}
242+
return result
243+
}
244+
235245
export const MELODY_LENGTH = 4
236246
export const NUM_NOTES = 5
237247

@@ -288,6 +298,12 @@ namespace microcode {
288298
}
289299
return { tempo, notes }
290300
}
301+
toText(melody: Melody): string {
302+
return melodyToNotes(melody)
303+
}
304+
fromText(txt: string): Melody {
305+
return undefined
306+
}
291307
}
292308

293309
export class MelodyEditor extends ModifierEditor {
@@ -316,16 +332,6 @@ namespace microcode {
316332
field ? field : this.fieldEditor.clone(this.field)
317333
)
318334
}
319-
// music.play(music.stringPlayable("C - E - G F E D ", 120), music.PlaybackMode.UntilDone)
320-
getNoteSequence() {
321-
const notes = this.field.notes.split("")
322-
let result = ""
323-
for (const n of notes) {
324-
if (n == ".") result += "- "
325-
else result += noteNames[parseInt(n)] + " "
326-
}
327-
return result
328-
}
329335
}
330336

331337
let iconEditorTile: ModifierEditor = undefined

interpreter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ namespace microcode {
316316
}
317317
case Tid.TID_ACTUATOR_MUSIC: {
318318
// TODO: get the whole sequence and do as one shot, to avoid burps
319-
const mod = this.rule.modifiers[this.modifierIndex]
320-
param = (mod as MelodyEditor).getNoteSequence()
319+
const mod = this.rule.modifiers[
320+
this.modifierIndex
321+
] as MelodyEditor
322+
param = melodyToNotes(mod.field)
321323
break
322324
}
323325
case Tid.TID_ACTUATOR_SPEAKER: {

tiles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ namespace microcode {
442442
return modEditor.getField()
443443
}
444444
case Tid.TID_ACTUATOR_MUSIC: {
445-
const mod = getEditor(Tid.TID_MODIFIER_MELODY_EDITOR)
446-
return (mod as MelodyEditor).getNoteSequence()
445+
const mod = getEditor(
446+
Tid.TID_MODIFIER_MELODY_EDITOR
447+
) as MelodyEditor
448+
return melodyToNotes(mod.field)
447449
}
448450
case Tid.TID_ACTUATOR_SHOW_NUMBER:
449451
case Tid.TID_ACTUATOR_CUP_X_ASSIGN:

0 commit comments

Comments
 (0)