From 3d0ca1c548c511b2fd23287fe45fe000692f79de Mon Sep 17 00:00:00 2001 From: d_m Date: Tue, 13 Aug 2024 23:49:45 -0400 Subject: [PATCH] basic timeline is working --- music.tal | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/music.tal b/music.tal index 9f5800b..5b5d0b0 100644 --- a/music.tal +++ b/music.tal @@ -36,8 +36,9 @@ |00 @ch $2 &start $2 &limit $2 &next-t $2 |0000 - @dur $2 ( dur: the lenght of the shortest possible note ) + @dur $2 ( dur: the length of the shortest possible note ) @time $2 ( the current timestamp, in milliseconds ) + @events $8 ( timeline: see .ch above ) @ch-1 $8 ( channel 1: see .ch above ) @ch-2 $8 ( channel 2: see .ch above ) @ch-3 $8 ( channel 3: see .ch above ) @@ -61,6 +62,7 @@ #011f ;noise #0200 #44 .Audio4 setup-audio ( set up the channel data structures ) + ;timeline ;track-1 setup-events ;track-1 ;track-2 .ch-1 setup-ch ;track-2 ;track-3 .ch-2 setup-ch ;track-3 ;track-4 .ch-3 setup-ch @@ -87,10 +89,10 @@ ( increment the channel's position, looping back if needed ) @inc-ch ( ch^ -> ) STHk LDZ2 INC2 INC2 ( pos+2* [ch^] ) - STHkr .ch/limit ADD LDZ2 ( pos+2 limit* [ch^] ) - OVR2 GTH2 ?&ready ( pos+2 [ch^] ; is limit > pos+2 ? ) + STHkr .ch/limit ADD LDZ2 ( pos+2* limit* [ch^] ) + OVR2 GTH2 ?&ready ( pos+2* [ch^] ; is limit > pos+2 ? ) POP2 STHkr .ch/start ADD LDZ2 ( start* [ch^] ) - &ready STHr STZ2 JMP2r ( ; ch<-pos+2 ) + &ready STHr STZ2 JMP2r ( ; ch<-inc-pos ) ( if ready, play the channel ) @play-ch ( ch^ -> ) @@ -101,6 +103,12 @@ STHkr ch-to-dev play-data ( [ch^] ; play note) STHr !inc-ch ( ; increment pos ) +@setup-events ( addr* limit* -> ) + SWP2 .events STZ2k ( limit* addr* t^ ; t<-addr ) + STHk INC INC STZ2 ( limit* addr* [t^] ; t/start<-addr ) + STHr .ch/limit ADD STZ2 ( [ch^] ; ch/limit<-limit ) + !advance-events + ( set up the channel, including playing its first note ) @setup-ch ( addr* limit* ch^ -> ) STH SWP2 STHkr STZ2k ( limit* addr* ch^ [ch^] ; ch<-addr ) @@ -116,6 +124,18 @@ STHr #08 ORA DEO2 ( ; <-adsr ) JMP2r +@change-pulse ( ms* -> ) + DUP2 .ch-1 update-ch-pulse + DUP2 .ch-2 update-ch-pulse + DUP2 .ch-3 update-ch-pulse + DUP2 .ch-4 update-ch-pulse + .dur STZ2 JMP2r + +@update-ch-pulse ( ms* ch^ -> ) + .ch/next-t ADD STHk LDZ2 ( ms* next-ms* [next-t^] ) + .dur LDZ2 DIV2 ( ms* next-p* [next-t^] ) + MUL2 STHr STZ2 JMP2r ( ) + @on-audio-1 .ch-1 !on-audio @on-audio-2 .ch-2 !on-audio @on-audio-3 .ch-3 !on-audio @@ -125,19 +145,42 @@ .ch/next-t ADD LDZ2 .time LDZ2 NEQ2k ?&neq POP2 POP2 BRK &neq POP2 .time STZ2 + advance-events .ch-1 play-ch .ch-2 play-ch .ch-3 play-ch .ch-4 play-ch BRK +@inc-events ( -> ) + .events ( t^ ) + STHk LDZ2 INC2 INC2 INC2 ( pos+3* [t^] ) + STHkr .ch/limit ADD LDZ2 ( pos+3* limit* [t^] ) + OVR2 GTH2 ?&ready ( pos+3* [t^] ; is limit > pos+2 ? ) + POP2 STHkr .ch/start ADD LDZ2 ( start* [ch^] ) + &ready STHr STZ2 JMP2r ( ; t<-inc-pos ) + +@advance-events ( -> ) + .events ( t^ ) + STHk .ch/next-t ADD LDZ2 .time LDZ2 GTH2 ?&skip ( [t^] ; t/next-t > time? ) + STHkr LDZ2 DUP2 LDA2 JSR2 ( addr* [t^] ) + INC2 INC2 LDA count-to-ms ( ms* [t^] ) + .time LDZ2 ADD2 ( time+ms* [t^] ) + STHr .ch/next-t ADD STZ2 ( ; t/next-t<-time+ms ) + !inc-events + &skip POPr JMP2r + ( this is the actual fun part: the note data for each track ) +@timeline =slowdown 08 @track-1 2401 2b02 3001 2402 2e01 3001 @track-2 0004 3c02 3e01 3f01 @track-3 4301 4301 4402 4301 4301 4401 4601 @track-4 1004 3004 0103 0101 3002 3001 3001 @track-end +@slowdown ( -> ) + .dur LDZ2 #0008 ADD2 !change-pulse + @saw ff ee dd cc bb aa 99 88 77 66 55 44 33 22 11 00 @triangle 80 ff 80 00