Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/add-note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Add-note dialog: the small popover for typing a note's fret/pitch + sustain
// at a grid position (opened by a double-click on empty grid). showAddNote /
// hideAddNote are host hooks; the confirm handler commits an undoable AddNoteCmd.

import { _editBlipAt } from './audio.js';
import { AddNoteCmd } from './commands.js';
import { isKeysMode, midiToNote, noteToMidi } from './keys.js';
import { S } from './state.js';
import { host } from './host.js';

export let addNoteData = null;

export function showAddNote(cx, cy, time, string, fret) {
const isKeys = isKeysMode();
addNoteData = { time, string, fret, isKeys };
const dlg = document.getElementById('editor-add-note-dialog');
dlg.style.left = cx + 'px';
dlg.style.top = cy + 'px';
dlg.classList.remove('hidden');

document.getElementById('editor-add-fret-col').classList.toggle('hidden', isKeys);
document.getElementById('editor-add-pitch-col').classList.toggle('hidden', !isKeys);

if (isKeys) {
const midi = noteToMidi(string, fret);
document.getElementById('editor-add-pitch-label').textContent = midiToNote(midi);
const sus = document.getElementById('editor-add-sustain');
sus.focus();
sus.select();
} else {
const inp = document.getElementById('editor-add-fret');
inp.value = fret != null ? String(fret) : '0';
inp.focus();
inp.select();
}
}

export function hideAddNote() {
document.getElementById('editor-add-note-dialog').classList.add('hidden');
addNoteData = null;
}

export function editorConfirmAddNote() {
if (!addNoteData) return;
const fret = addNoteData.isKeys
? addNoteData.fret
: Math.max(0, Math.min(24, parseInt(document.getElementById('editor-add-fret').value) || 0));
const sustain = Math.max(0, parseFloat(document.getElementById('editor-add-sustain').value) || 0);
const note = {
time: addNoteData.time,
string: addNoteData.string,
fret,
sustain,
techniques: {},
};
S.history.exec(new AddNoteCmd(note));
_editBlipAt();
hideAddNote();
host.draw();
host.updateStatus();
};
64 changes: 9 additions & 55 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { _installModalKeyboard, setStatus } from './ui.js';
import { EditHistory } from './history.js';
import {
AddNoteCmd, _ROLL_REFUSE_REASONS,
_ROLL_REFUSE_REASONS,
_commitAddResolved } from './commands.js';
import {
editorApplyCreateResult, editorArtSearch,
Expand Down Expand Up @@ -101,6 +101,9 @@
_partsViewOnMouseDown, _refreshPartsViewButton
} from './parts-view.js';
import { drawWaveform } from './waveform.js';
import {
addNoteData, editorConfirmAddNote, hideAddNote, showAddNote
} from './add-note.js';
import { setHostHooks } from './host.js';
import {
MIN_MEASURE, TempoGridCmd, TempoMapCmd, _r3, _refreshTempoMapButton, _refreshTempoSyncInspector, _respaceWithLocksPure,
Expand Down Expand Up @@ -151,7 +154,7 @@
import {
KEYS_PATTERN, _partViewKeyPure, _rollLockNotice,
_rollMidiForNote, _rollPitchCtx, _rollReadOnly, _viewPrefs,
_viewPrefsSave, isKeysMode, midiToNote, noteToMidi, updatePianoRange, viewFor } from './keys.js';
_viewPrefsSave, isKeysMode, midiToNote, updatePianoRange, viewFor } from './keys.js';
import {
_restoreSuggestedMarks,
_saveSuggestedMarks, _suggestedCount, chords, notes
Expand Down Expand Up @@ -779,59 +782,6 @@
// Add note dialog
// ════════════════════════════════════════════════════════════════════

let addNoteData = null;

function showAddNote(cx, cy, time, string, fret) {
const isKeys = isKeysMode();
addNoteData = { time, string, fret, isKeys };
const dlg = document.getElementById('editor-add-note-dialog');
dlg.style.left = cx + 'px';
dlg.style.top = cy + 'px';
dlg.classList.remove('hidden');

document.getElementById('editor-add-fret-col').classList.toggle('hidden', isKeys);
document.getElementById('editor-add-pitch-col').classList.toggle('hidden', !isKeys);

if (isKeys) {
const midi = noteToMidi(string, fret);
document.getElementById('editor-add-pitch-label').textContent = midiToNote(midi);
const sus = document.getElementById('editor-add-sustain');
sus.focus();
sus.select();
} else {
const inp = document.getElementById('editor-add-fret');
inp.value = fret != null ? String(fret) : '0';
inp.focus();
inp.select();
}
}

function hideAddNote() {
document.getElementById('editor-add-note-dialog').classList.add('hidden');
addNoteData = null;
}

window.editorConfirmAddNote = function() {
if (!addNoteData) return;
const fret = addNoteData.isKeys
? addNoteData.fret
: Math.max(0, Math.min(24, parseInt(document.getElementById('editor-add-fret').value) || 0));
const sustain = Math.max(0, parseFloat(document.getElementById('editor-add-sustain').value) || 0);
const note = {
time: addNoteData.time,
string: addNoteData.string,
fret,
sustain,
techniques: {},
};
S.history.exec(new AddNoteCmd(note));
_editBlipAt();
hideAddNote();
draw();
updateStatus();
};

window.editorHideAddNote = hideAddNote;

/* @pure:boot-teardown:start */
// Tracked registry for document/window-level listeners. The host can
Expand Down Expand Up @@ -1796,7 +1746,7 @@
// the same save path as the Save button (in-place sloppak write, not the
// heavy create-mode build).
if (S.sessionId) {
try { await saveCDLC(); } catch (e) { /* surfaced via setStatus */ }

Check warning on line 1749 in src/main.js

View workflow job for this annotation

GitHub Actions / lint

'e' is defined but never used. Allowed unused caught errors must match /^_/u
}
// Capture where we are so the return trip lands on the same spot.
const returnCtx = {
Expand Down Expand Up @@ -2136,6 +2086,10 @@
// Parts overview toggle (parts-view.js owns the logic; HTML/toolbar call it).
window.editorTogglePartsView = _editorTogglePartsView;

// Add-note dialog (add-note.js owns the logic; HTML calls these by name).
window.editorConfirmAddNote = editorConfirmAddNote;
window.editorHideAddNote = hideAddNote;

// Strings (tuning) editor (strings.js owns the logic; HTML calls these by name).
window.editorShowStringsModal = editorShowStringsModal;
window.editorHideStringsModal = editorHideStringsModal;
Expand Down
Loading