Working REBEAT.

This commit is contained in:
severak 2019-11-29 17:06:37 +01:00
parent 239af3a83f
commit 3ebad67209
1 changed files with 57 additions and 17 deletions

View File

@ -1,6 +1,16 @@
; REBEAT
;
; simple pedal-like looper
;
; code based on TabRecPlay example by Iain McCurdy
; (s) Severák 2019
; licensed with MIT license
<Cabbage>
form caption("REBEAT") size(200, 100), colour(58, 110, 182), pluginid("rebe")
button bounds(8, 4, 181, 87) text("REBEAT", "REBEAT") fontcolour(128, 128, 128, 255) channel("rebeat") identchannel("rebeatWidget")
form caption("REBEAT") size(300, 200), colour(58, 110, 182), pluginid("rebe")
button bounds(48, 164, 192, 27) text("REBEAT", "REBEAT") channel("rebeat") identchannel("rebeatWidget") fontcolour:0(128, 128, 128, 255)
gentable bounds(2, 6, 296, 131) identchannel("gentable") tablenumber(101.0)
label bounds(50, 144, 191, 16) text("waiting...") identchannel("statusbar")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
@ -29,36 +39,53 @@ gkSpeed init 1
gkOutGain init 1
instr 1
instr GUI
; 0 = stopped; 1 = recording; 2 = looping
kStatus init 0
kRebeat chnget "rebeat"
kTrig changed kRebeat
Scolor init ""
gitablelen = ftlen(gistorageL)
if kTrig==1 then
if changed:k(kRebeat)==1 then
if kStatus==0 then
Scolor = "fontcolor(128, 128, 128, 255)"
chnset "text(\"recording...\")", "statusbar"
Scolor strcatk "fontcolour:0(255, 0, 0, 255), fontcolour:1(255, 0, 0, 255)", ""
kStatus = 1
event "i","Record",0,3600
event "i", "Record", 0, 23
printks "recording...\n", 0
elseif kStatus==1 then
Scolor = "fontcolor(255, 0, 0, 255)"
chnset "text(\"playing...\")", "statusbar"
Scolor strcatk "fontcolour:0(0, 100, 0, 255), fontcolour:1(0, 100, 0, 255)", ""
kStatus = 2
printks "playing...\n", 0
gkPlayLoop = 1
event "i", "PlayLoop", 0, 3600
elseif kStatus==2 then
Scolor = "fontcolor(0, 100, 0, 255)"
chnset "text(\"waiting...\")", "statusbar"
Scolor strcatk "fontcolour:0(128,128,128,255),fontcolour:1(128,128,128,255)", ")"
kStatus = 0
gkPlayLoop = 0
printks "waiting...\n", 0
endif
;chnset Scolor, "rebeatWidget"
printks "Bum %s %d\n", 0, Scolor, kStatus
chnset Scolor, "rebeatWidget"
endif
endin
;instr setTable
; Stablenum sprintf "tablenumber(%d)", gistorageL
; printks "tablenumber(%d)", 0, gistorageL
; chnset Stablenum, "gentable"
;endin
instr Record
; if gkPause=1 goto SKIP_RECORD ;IF PAUSE BUTTON IS ACTIVATED TEMPORARILY SKIP RECORDING PROCESS
if gkPlayLoop == 1 then
turnoff
endif
if gkPause == 1 goto SKIP_RECORD ;IF PAUSE BUTTON IS ACTIVATED TEMPORARILY SKIP RECORDING PROCESS
;printks "rec...\n", 2
ainL,ainR ins ;READ AUDIO FROM LIVE INPUT CHANNEL 1
aRecNdx line 0,gitablelen/sr,1 ;CREATE A POINTER FOR WRITING TO TABLE - FREQUENCY OF POINTER IS DEPENDENT UPON TABLE LENGTH AND SAMPLE RATE
@ -66,10 +93,17 @@ instr Record
gkRecDur downsamp aRecNdx ;CREATE A K-RATE GLOBAL VARIABLE THAT WILL BE USED BY THE 'PLAYBACK' INSTRUMENT TO DETERMINE THE LENGTH OF RECORDED DATA
tablew ainL*gkInGain, aRecNdx, gistorageL;WRITE AUDIO TO AUDIO STORAGE TABLE
tablew ainR*gkInGain, aRecNdx, gistorageR;WRITE AUDIO TO AUDIO STORAGE TABLE
; scruber
Sscruber sprintfk "scrubberposition(%d, %d), tablenumber(%d)", k(aRecNdx), k(gistorageL), k(gistorageL)
chnset Sscruber, "gentable"
if gkRecDur>=gitablelen then ;IF MAXIMUM RECORD TIME IS REACHED...
kRecord=0
kRecord=0
printks "limit reached!\n", 0
turnoff
endif ;END OF CONDITIONAL BRANCH
;SKIP_RECORD:
SKIP_RECORD:
endin
instr PlayLoop
@ -91,6 +125,11 @@ instr PlayLoop
aLoopLen interp abs(kLoopLen)
aLoopBeg interp kLoopBeg
aPlayNdx = (aPlayNdx*aLoopLen) + aLoopBeg ;RESCALE INDEX POINTER ACCORDING TO LOOP LENGTH AND LOOP BEGINING
; scruber
Sscruber sprintfk "scrubberposition(%d, %d), tablenumber(%d)", k(aPlayNdx), k(gistorageL), k(gistorageL)
chnset Sscruber, "gentable"
aL tablei aPlayNdx, gistorageL ;READ AUDIO FROM AUDIO STORAGE FUNCTION TABLE
aR tablei aPlayNdx, gistorageR ;READ AUDIO FROM AUDIO STORAGE FUNCTION TABLE
outs aL*gkOutGain,aR*gkOutGain ;SEND AUDIO TO OUTPUTS
@ -103,6 +142,7 @@ endin
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7]
i "GUI" 0 z
;i "setTable" 0 1
</CsScore>
</CsoundSynthesizer>