fix: playhead at bar 0 when opening MIDI item in session mode

- Removed st.currentTime >= 0 check from playhead rendering
- handleEditMidiInTab: currentTime = -beatOff * beatSec so phBeat=0
- handleSwitchMidiItem: same logic for dropdown switches
- Playhead draws at x=0 (bar 0) when item opens, moves right during
  playback from the initial negative position
This commit is contained in:
2026-07-27 19:37:59 +07:00
parent ab4b91a158
commit 6ff2f72c58
2 changed files with 10 additions and 7 deletions
+7 -4
View File
@@ -4646,8 +4646,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, activeTracks, onClos
var trk = (activeTracks || []).find(function(t) { return t.id === match._trackId; });
var newBeatOff = (match.startTime / secondsPerBar) * timeSigNum;
var spb = 60.0 / (parseInt(bpm) || 120);
var deltaSec = (renderBeatOffset - newBeatOff) * spb;
var newTime = Math.max(0, (st.currentTime || 0) + deltaSec);
var newTime = -newBeatOff * spb;
setSubTabs(function(prev) {
return prev.map(function(s) {
if (s.id !== st.id) return s;
@@ -4986,7 +4985,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, activeTracks, onClos
}
// Draw playhead
if (st.currentTime !== undefined && st.currentTime !== null && st.currentTime >= 0) {
if (st.currentTime !== undefined && st.currentTime !== null) {
const phBeat = renderBeatOffset + st.currentTime / (60.0 / (parseInt(bpm) || 120));
const phX = phBeat * pixelsPerBeat;
if (phX >= 0 && phX <= viewWidth) {
@@ -8287,6 +8286,10 @@ const App = () => {
const tabLabel = `Piano Roll: ${midiItem.name || 'MIDI'}`;
const ctx = getAudioContext();
const silentBuffer = ctx.createBuffer(1, 128, ctx.sampleRate);
var bpmVal = parseInt(bpm) || 120;
var beatSec = 60.0 / bpmVal;
var secPerBar = beatSec * 4;
var beatOff = (midiItem.startTime / secPerBar) * 4;
const newTab = {
id: tabId,
label: tabLabel,
@@ -8299,7 +8302,7 @@ const App = () => {
buffer: silentBuffer,
instrumentProgram: track.instrumentProgram,
instrumentName: track.instrumentName,
currentTime: 0,
currentTime: -beatOff * beatSec,
isPlaying: false,
selectionStart: null,
selectionEnd: null,
File diff suppressed because one or more lines are too long