Skip to content

Commit b38ff70

Browse files
committed
Merge branch 'master' of https://github.com/johnnesky/beepbox, and fix bugs with Midi export for custom chip and drumset instruments.
2 parents 57576b8 + 17c5e9f commit b38ff70

16 files changed

+618
-197
lines changed

editor/BeatsPerBarPrompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace beepbox {
9797
private _saveChanges = (): void => {
9898
window.localStorage.setItem("beatCountStrategy", this._conversionStrategySelect.value);
9999
this._doc.prompt = null;
100-
this._doc.record(new ChangeBeatsPerBar(this._doc, BeatsPerBarPrompt._validate(this._beatsStepper), this._conversionStrategySelect.value), "replace");
100+
this._doc.record(new ChangeBeatsPerBar(this._doc, BeatsPerBarPrompt._validate(this._beatsStepper), this._conversionStrategySelect.value), StateChangeType.replace);
101101
}
102102
}
103103
}

editor/ChannelSettingsPrompt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ namespace beepbox {
123123

124124
private static _validateNumber(event: Event): void {
125125
const input: HTMLInputElement = <HTMLInputElement>event.target;
126-
input.value = Math.floor(Math.max(Number(input.min), Math.min(Number(input.max), Number(input.value)))) + "";
126+
input.value = String(ChannelSettingsPrompt._validate(input));
127127
}
128128

129129
private static _validate(input: HTMLInputElement): number {
130-
return Math.floor(Number(input.value));
130+
return Math.floor(Math.max(Number(input.min), Math.min(Number(input.max), Number(input.value))));
131131
}
132132

133133
private _saveChanges = (): void => {
@@ -136,7 +136,7 @@ namespace beepbox {
136136
group.append(new ChangeInstrumentsPerChannel(this._doc, ChannelSettingsPrompt._validate(this._instrumentsStepper)));
137137
group.append(new ChangeChannelCount(this._doc, ChannelSettingsPrompt._validate(this._pitchChannelStepper), ChannelSettingsPrompt._validate(this._drumChannelStepper), ChannelSettingsPrompt._validate(this._modChannelStepper)));
138138
this._doc.prompt = null;
139-
this._doc.record(group, "replace");
139+
this._doc.record(group, StateChangeType.replace);
140140
}
141141
}
142142
}

editor/ExportPrompt.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ namespace beepbox {
226226
}
227227

228228
private _exportToWav(): void {
229-
230-
const synth: Synth = new Synth(this._doc.song)
229+
const synth: Synth = new Synth(this._doc.song);
231230
synth.loopRepeatCount = Number(this._loopDropDown.value) - 1;
232231
if (!this._enableIntro.checked) {
233232
for (let introIter: number = 0; introIter < this._doc.song.loopStart; introIter++) {
@@ -380,7 +379,7 @@ namespace beepbox {
380379
writeEventTime(0);
381380
writer.writeUint8(MidiEventType.meta);
382381
writer.writeMidi7Bits(MidiMetaEventMessage.text);
383-
writer.writeMidiAscii("Composed with beepbox.co");
382+
writer.writeMidiAscii("Composed with jummbus.bitbucket.io");
384383

385384
writeEventTime(0);
386385
writer.writeUint8(MidiEventType.meta);
@@ -487,6 +486,8 @@ namespace beepbox {
487486
instrumentProgram = instrumentDecays ? 0x19 : 81; // steel guitar : sawtooth
488487
} else if (instrument.type == InstrumentType.fm || instrument.type == InstrumentType.harmonics) {
489488
instrumentProgram = instrumentDecays ? 2 : 81; // electric grand : sawtooth
489+
} else if (instrument.type == InstrumentType.customChipWave) {
490+
instrumentProgram = instrumentDecays ? 0x19 : 81; // steel guitar : sawtooth
490491
} else {
491492
throw new Error("Unrecognized instrument type.");
492493
}
@@ -561,7 +562,7 @@ namespace beepbox {
561562
const prevPitches: number[] = [-1, -1, -1, -1];
562563
const nextPitches: number[] = [-1, -1, -1, -1];
563564
const toneCount: number = Math.min(polyphony, note.pitches.length);
564-
const velocity: number = isDrumset ? Math.max(1, Math.round(defaultNoteVelocity * note.pins[0].volume / 3)) : defaultNoteVelocity;
565+
const velocity: number = isDrumset ? Math.max(1, Math.round(defaultNoteVelocity * note.pins[0].volume / 6)) : defaultNoteVelocity;
565566

566567
// The maximum midi pitch bend range is +/- 24 semitones from the base pitch.
567568
// To make the most of this, choose a base pitch that is within 24 semitones from as much of the note as possible.

editor/ImportPrompt.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace beepbox {
5555
reader.addEventListener("load", (event: Event): void => {
5656
this._doc.prompt = null;
5757
this._doc.goBackToStart();
58-
this._doc.record(new ChangeSong(this._doc, <string>reader.result), "replace");
58+
this._doc.record(new ChangeSong(this._doc, <string>reader.result), StateChangeType.replace, true);
5959
});
6060
reader.readAsText(file);
6161
} else if (extension == "midi" || extension == "mid") {
@@ -367,9 +367,8 @@ namespace beepbox {
367367
}
368368

369369
// Now the MIDI file is fully parsed. Next, constuct BeepBox channels out of the data.
370-
371370
const microsecondsPerMinute: number = 60 * 1000 * 1000;
372-
const beatsPerMinute: number = microsecondsPerMinute / microsecondsPerBeat;
371+
const beatsPerMinute: number = Math.max(Config.tempoMin, Math.min(Config.tempoMax, Math.round(microsecondsPerMinute / microsecondsPerBeat)));
373372
const midiTicksPerPart: number = midiTicksPerBeat / Config.partsPerBeat;
374373
const partsPerBar: number = Config.partsPerBeat * beatsPerBar;
375374
const songTotalBars: number = Math.ceil(currentMidiTick / midiTicksPerPart / partsPerBar);
@@ -844,7 +843,7 @@ namespace beepbox {
844843
constructor(doc: SongDocument) {
845844
super();
846845
const song: Song = doc.song;
847-
song.tempo = Math.max(Config.tempoMin, Math.min(Config.tempoMax, beatsPerMinute));
846+
song.tempo = beatsPerMinute;
848847
song.beatsPerBar = beatsPerBar;
849848
song.key = key;
850849
song.scale = 11;
@@ -865,7 +864,7 @@ namespace beepbox {
865864
this._doc.goBackToStart();
866865
for (const channel of this._doc.song.channels) channel.muted = false;
867866
this._doc.prompt = null;
868-
this._doc.record(new ChangeImportMidi(this._doc), "replace");
867+
this._doc.record(new ChangeImportMidi(this._doc), StateChangeType.replace, true);
869868
}
870869
}
871870
}

editor/MoveNotesSidewaysPrompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace beepbox {
8383
private _saveChanges = (): void => {
8484
window.localStorage.setItem("moveNotesSidewaysStrategy", this._conversionStrategySelect.value);
8585
this._doc.prompt = null;
86-
this._doc.record(new ChangeMoveNotesSideways(this._doc, +this._beatsStepper.value, this._conversionStrategySelect.value), "replace");
86+
this._doc.record(new ChangeMoveNotesSideways(this._doc, +this._beatsStepper.value, this._conversionStrategySelect.value), StateChangeType.replace);
8787
}
8888
}
8989
}

editor/OctaveScrollBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ namespace beepbox {
174174
if (this._mouseY < this._barBottom - this._barHeight * 0.5) {
175175
if (currentOctave < this._doc.scrollableOctaves) {
176176
this._change = new ChangeOctave(this._doc, oldValue, currentOctave + 1);
177-
this._doc.record(this._change, canReplaceLastChange ? "replace" : "push");
177+
this._doc.record(this._change, canReplaceLastChange ? StateChangeType.replace : StateChangeType.push);
178178
}
179179
} else {
180180
if (currentOctave > 0) {
181181
this._change = new ChangeOctave(this._doc, oldValue, currentOctave - 1);
182-
this._doc.record(this._change, canReplaceLastChange ? "replace" : "push");
182+
this._doc.record(this._change, canReplaceLastChange ? StateChangeType.replace : StateChangeType.push);
183183
}
184184
}
185185
}

0 commit comments

Comments
 (0)