Skip to content

Commit 2503291

Browse files
committed
Edit samplerate
1 parent 8d3a665 commit 2503291

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

src/audio/SongDocument.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,12 @@ export class SongDocument extends EventTarget {
507507
return wave;
508508
}
509509

510-
updateWave(wave: WaveDocument, name: string, note: number, selection: WaveRange, zoom: WaveRange) {
510+
updateWave(wave: WaveDocument, name: string, note: number, selection: WaveRange, zoom: WaveRange, sampleRate: number) {
511511
wave.name = name;
512512
wave.note = note;
513513
wave.selection = selection;
514514
wave.zoom = zoom;
515+
wave.sampleRate = sampleRate;
515516

516517
this.dispatchEvent(new CustomEvent("updateWave", { detail: wave }));
517518
}

src/commands/WaveEditor/CropCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export class CropCommand implements ICommand {
2525
waveEditor.clearSelection();
2626
waveEditor.clearZoom();
2727

28-
this.app.song.updateWave(wave, wave.name, wave.note, null, null);
28+
this.app.song.updateWave(wave, wave.name, wave.note, null, null, wave.sampleRate);
2929
}
3030
}

src/commands/WaveEditor/CutCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export class CutCommand implements ICommand {
2525

2626
wave.deleteRange(start, end);
2727
waveEditor.clearSelection();
28-
this.app.song.updateWave(wave, wave.name, wave.note, null, wave.zoom);
28+
this.app.song.updateWave(wave, wave.name, wave.note, null, wave.zoom, wave.sampleRate);
2929
}
3030
}

src/commands/WaveEditor/DeleteCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export class DeleteCommand implements ICommand {
2121
const wave = this.component.wave;
2222
wave.deleteRange(start, end);
2323
waveEditor.clearSelection();
24-
this.app.song.updateWave(wave, wave.name, wave.note, null, wave.zoom);
24+
this.app.song.updateWave(wave, wave.name, wave.note, null, wave.zoom, wave.sampleRate);
2525
}
2626
}

src/commands/WaveEditor/PasteCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class PasteCommand implements ICommand {
2929

3030
const wave = this.component.wave;
3131
wave.insertRange(offset, wavFile.channels);
32-
this.app.song.updateWave(wave, wave.name, wave.note, wave.selection, wave.zoom);
32+
this.app.song.updateWave(wave, wave.name, wave.note, wave.selection, wave.zoom, wave.sampleRate);
3333

3434
}
3535
}

src/components/WavePropertiesPanel.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ export class WavePropertiesPanel implements IComponent {
99

1010
nameInput: HTMLInputElement;
1111
noteSelect: HTMLSelectElement;
12+
sampleRateInput: HTMLInputElement;
1213

1314
name: string;
1415
note: number;
16+
sampleRate: number;
1517

16-
constructor(app: Appl, name: string, note: number) {
18+
constructor(app: Appl, name: string, note: number, sampleRate: number) {
19+
if (!sampleRate) {
20+
throw new Error("samplerate missing!")
21+
}
1722
this.app = app;
1823
this.name = name;
1924
this.note = note;
25+
this.sampleRate = sampleRate;
2026

2127
this.container = VInset(undefined, [ "flex-1", "gap-1" ]);
2228
this.container.tabIndex = -1;
@@ -40,10 +46,22 @@ export class WavePropertiesPanel implements IComponent {
4046

4147
const noteGroup = FormGroup("Note", this.noteSelect);
4248

49+
50+
this.sampleRateInput = document.createElement("input");
51+
this.sampleRateInput.type = "number";
52+
this.sampleRateInput.className = "w-full rounded-lg p-1 bg-neutral-800";
53+
this.sampleRateInput.value = this.sampleRate.toString();
54+
this.sampleRateInput.addEventListener("change", () => {
55+
this.sampleRate = parseInt(this.sampleRateInput.value);
56+
});
57+
58+
const sampleRateGroup = FormGroup("Sample Rate", this.sampleRateInput);
59+
4360
const modalButtonBar = new ModalButtonBar(this.app);
4461

4562
this.container.appendChild(nameGroup);
4663
this.container.appendChild(noteGroup);
64+
this.container.appendChild(sampleRateGroup);
4765
this.container.appendChild(modalButtonBar.getDomNode());
4866
}
4967

src/dialogs/WavePropertiesDialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { WaveDocument } from "../audio/SongDocument";
33
import { WavePropertiesPanel } from "../components/WavePropertiesPanel";
44

55
export async function showWavePropertiesDialog(app: Appl, wave: WaveDocument) {
6-
const wavePanel = new WavePropertiesPanel(app, wave.name, wave.note);
6+
const wavePanel = new WavePropertiesPanel(app, wave.name, wave.note, wave.sampleRate);
77
const result = await app.modalDialogContainer.showModal("Wave Properties", wavePanel);
88

99
if (!result) {
1010
return;
1111
}
1212

13-
app.song.updateWave(wave, wavePanel.name, wavePanel.note, wave.selection, wave.zoom);
13+
app.song.updateWave(wave, wavePanel.name, wavePanel.note, wave.selection, wave.zoom, wavePanel.sampleRate);
1414
}

0 commit comments

Comments
 (0)