Skip to content

Fix Activity 3 bassline sourced from wrong part#155

Merged
hcientist merged 9 commits intoLab-Lab-Lab:mainfrom
espadonne:fix/activity3-bassline-source
Apr 1, 2026
Merged

Fix Activity 3 bassline sourced from wrong part#155
hcientist merged 9 commits intoLab-Lab-Lab:mainfrom
espadonne:fix/activity3-bassline-source

Conversation

@mfwolffe
Copy link
Copy Markdown
Collaborator

@mfwolffe mfwolffe commented Mar 27, 2026

Summary

  • Fix Activity 3 multitrack DAW: bassline loading, operation logging races, playback cursor
  • Improve error diagnostics in API layer
  • Backend CORS fix for /media/ URLs (separate backend change needed)

Changes

Bassline loading for Activity 3

The bassline sample was never appearing in the multitrack editor. Root causes:

  1. Wrong data source — original code hardcoded a nonexistent file path; first fix used preferredSample which is the Melody part's sample, not the Bassline
  2. Approach changed to Import Takes modal — instead of fragile initialTracks pre-population (which fights useState only reading on first mount), the bassline is now injected as a named sample take. Students see it in the "Import Takes" modal and import it themselves
  3. Take duration display — the modal now resolves actual audio duration via Audio.loadedmetadata for takes that report 0:00

Activity operation logging (Activities 1-2)

  • logOperation calls in CustomTimeline.jsx (handleCut, handleSplice, undo) are now awaited sequentially to prevent concurrent backend requests that caused database is locked (SQLite) or race conditions (stale step_completions overwrites)
  • Logging errors are caught separately from audio processing errors — a failed log no longer shows "Failed to cut region" or blocks subsequent operations

Multitrack playback cursor

  • The playhead was stuck at 0s because the transport's AudioContext was suspended (browsers block auto-created contexts). Added audioContext.resume() in the transport's play() method — the Play button click is a valid user gesture

Error diagnostics

  • assertResponse in api.js now includes the response body in thrown errors (e.g. 400: Bad Request — {"error":"database is locked"}) instead of just the status text

Files changed

File Change
pages/.../activity/[step].js Build sampleTakes from Bassline assignment, pass to DAW
components/audio/DAW/index.js Accept and forward sampleTakes prop
components/audio/DAW/Multitrack/MultitrackWithTakes.js Prepend sample takes to recording takes
components/audio/DAW/Multitrack/TakesImportModal.js Resolve durations via Audio metadata
components/audio/DAW/CustomWaveform/CustomTimeline.jsx Await logOperation, separate error handling
components/audio/DAW/Multitrack/AudioEngine.js Resume suspended AudioContext on play
api.js Include response body in error messages

The previous fix used preferredSample which resolves to the Melody part's
sample_audio (the student's assignment). The bassline needs to come from
the Bassline assignment for the same piece, found via activities Redux state.
Also fixes race condition where assignment being null on first render caused
the loading gate to pass through, mounting DAWProvider with empty tracks.
Replace the initialTracks pre-population approach (which had timing issues
with useState only reading on first mount) with sample takes injected into
the Import Takes modal. The bassline appears as a named take that students
import themselves, matching the activity instructions flow.
Edge-drag on clips now behaves like standard DAWs (trim, not stretch):
- resizeL: moves the in-point into the buffer, can't reveal past offset 0
- resizeR: extends the out-point, clamped to the source audio buffer length
- Clips store sourceDuration (total audio buffer length) for bounds checking
- sourceDuration set on all clip creation paths: import, recording, auto-init
- Split clips inherit sourceDuration from the parent via spread
@hcientist hcientist merged commit 9b98738 into Lab-Lab-Lab:main Apr 1, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants