Improsculpt

classic Classic list List threaded Threaded
36 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Improsculpt

Patrick.Pagano~
Hello

I am trying to get Improsculpt working again for a friend after several dormant years.
Is someone in contact with Oeyvind?


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Oeyvind Brandtsegg-2
Hi Patrick,
I'm here. Good to hear you're reviving it. There are probably some parser changes since Improsculpt last ran. Haven't looked into the details, as I'm in the process of moving from San Diego back to Trondheim. If you have more info I'll try to help as best I can.
Oeyvind

On Jun 30, 2017 6:37 AM, "Patrick.Pagano~" <[hidden email]> wrote:
Hello

I am trying to get Improsculpt working again for a friend after several
dormant years.
Is someone in contact with Oeyvind?






--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
Hello!

Looks like the last tiem w egot it working was in 2008, gosh time flies

when i try to run the one that worked in 2008 i get this

defining argument `EfxSend``A as...#BasSyn#
defining argument `EfxSend``B as...#20#
defining argument `EfxSend``C as...#320#
defining argument `EfxSend``D as...#0.5#
defining argument `EfxSend``E as...#0#
defining argument `EfxSend``F as...#0#
defining argument `EfxSend``G as...#0#
defining argument `EfxSend``H as...#0#
defining argument `EfxSend``I as...#0.15#
defining argument `EfxSend``J as...#0#
defining argument `EfxSend``K as...#0#
defining argument `EfxSend``L Missing argument terminator
0.03)

                FLsetAlign 2, ihPbox1
                FLsetAlign 2, ihPbox2
                FLsetAlign 2, ihPa1
                FLsetAlign 2, ihPa2
cannot compile orchestra

thanks!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
What is the call to. EfxSend ?

Could be another version of the bracket problem but I need the code.

Sent from TypeApp
On 30 Jun 2017, at 18:16, "Patrick.Pagano~" <[hidden email]> wrote:
Hello!

Looks like the last tiem w egot it working was in 2008, gosh time flies

when i try to run the one that worked in 2008 i get this

defining argument `EfxSend``A as...#BasSyn#
defining argument `EfxSend``B as...#20#
defining argument `EfxSend``C as...#320#
defining argument `EfxSend``D as...#0.5#
defining argument `EfxSend``E as...#0#
defining argument `EfxSend``F as...#0#
defining argument `EfxSend``G as...#0#
defining argument `EfxSend``H as...#0#
defining argument `EfxSend``I as...#0.15#
defining argument `EfxSend``J as...#0#
defining argument `EfxSend``K as...#0#
defining argument `EfxSend``L Missing argument terminator
0.03)

FLsetAlign 2, ihPbox1
FLsetAlign 2, ihPbox2
FLsetAlign 2, ihPa1
FLsetAlign 2, ihPa2
cannot compile orchestra

thanks!





--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5756962.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Oeyvind Brandtsegg-2
Hi. I'm not in front of my machine, so only guessing, but it looks like a macro termination thing. Earlier, the parser tolerated macro names without termination, but now need to terminate with a dot.
Perhaps look for $EfxSend in the code and replace with $EfxSend. 
?
Again, pardon me for just guessing wildly....

On Jun 30, 2017 12:20 PM, "John ff" <[hidden email]> wrote:
What is the call to. EfxSend ?

Could be another version of the bracket problem but I need the code.

Sent from TypeApp
On 30 Jun 2017, at 18:16, "Patrick.Pagano~" <[hidden email]> wrote:
Hello!

Looks like the last tiem w egot it working was in 2008, gosh time flies

when i try to run the one that worked in 2008 i get this

defining argument `EfxSend``A as...#BasSyn#
defining argument `EfxSend``B as...#20#
defining argument `EfxSend``C as...#320#
defining argument `EfxSend``D as...#0.5#
defining argument `EfxSend``E as...#0#
defining argument `EfxSend``F as...#0#
defining argument `EfxSend``G as...#0#
defining argument `EfxSend``H as...#0#
defining argument `EfxSend``I as...#0.15#
defining argument `EfxSend``J as...#0#
defining argument `EfxSend``K as...#0#
defining argument `EfxSend``L Missing argument terminator
0.03)

FLsetAlign 2, ihPbox1
FLsetAlign 2, ihPbox2
FLsetAlign 2, ihPa1
FLsetAlign 2, ihPa2
cannot compile orchestra

thanks!





--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5756962.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~

As i recall we did something similar and i am wondering if we discussed  this and i had forgot the addition of the . @ the end of $EfxSend.

i'll step through it again
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
The error said no termination so I suspect a # or ) problem.  Where is the source?

Sent from TypeApp
On 2 Jul 2017, at 16:45, "Patrick.Pagano~" <[hidden email]> wrote:
As i recall we did something similar and i am wondering if we discussed 
this and i had forgot the addition of the . @ the end of $EfxSend.

i'll step through it again




--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5756987.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
CsoundSynthesizer>
; notes:
; see the ImproSculptReadme.htm file
; Copyright (C) 2002 Oeyvind Brandtsegg
; mailto:obrandts@online.no
; ImproSculpt version 2.1

;    This program is free software; you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation; either version 2 of the License, or
;    (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program; if not, write to the Free Software
;    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


<CsOptions>

;CsoundAV command line, edit to suit your platform and choice of Csound
;-+X -+C -b2048 -+O -m0  -+*

;command line for use with Istvan Varga Csound 4.23.4 under windows
;-i adc -o dac

;command line for Linux, thanks to Dave Phillips
;CsoundFLTK command line for Linux + ALSA, edit for your hardware
;--sched --pcm-output-device=hw:0 --pcm-input-device=hw:0 -i adc -o dac -

</CsOptions>

<CsInstruments>

        sr = 44100  
        kr = 441
        ksmps = 100
        nchnls = 2


       

        zakinit 24,10

        gkt5 init 0
        gkout_tim1 init 1
        gktrig init 0
        gktrig2 init 0
        gktrig3 init 0
        gkbtpo_cps init 0
        gitime_old init 0
        gktemp init 60
        gkbeatcps init 1
        gkbeatcps2 init 1
        gkbeatcps3 init 1
        gktrig_phr init 1
        gktrig_phr2 init 1
        gktrig_phr3 init 1
        gk_endflag init 1
        gk_endflag2 init 1
        gk_endflag3 init 1
        gkbeats init 4
        gktimesign1 init 201
        gknumevents init 7
        gknumevents2 init 7
        gknumevents3 init 7
        gkdrmoff init 0
        gkptrnoff init 0
        gkbend2midi init 1
        gkctrl2midi init 0
        gkveloc init 1
        gkout_amp2 init 1 ; velocity for R.Play module 1
        gkout_amp22 init 1 ; velocity for R.Play module 2

        gkminpause1 init 0
        gkminpause2 init 0
        gkminpause3 init 0
        gkmaxpause1 init 4
        gkmaxpause2 init 4
        gkmaxpause3 init 4

        gks1bypas init 0 ; bypass random selection of sounds, instr 312
        gks1fno init 1
        gks2bypas init 0 ; bypass random selection of sounds, instr 314
        gks2fno init 1
; gk_maxRMS1 init 0 ; maximum rms value for each sound stored

        gktime304 init 0 ; length of last stored sound, updated while writing audio
        gk304active init 0 ; for testing if instr 304 is active
        gkcount304 init 0 ; index number of last stored sound
        gk304off init 0 ; turnoff trigger inducator, for release time envelope on recording

        gktime305 init 0 ; length of last stored sound, updated while writing audio
        gk305active init 0 ; for testing if instr 304 is active
        gkcount305 init 0 ; index number of last stored sound
        gk305off init 0 ; turnoff trigger inducator, for release time envelope on recording

        gkGrn1form_mc init 1
        gk61oct_mc init 0
       
        gkRAGphs init 0.1
        gkRAGdur init 0.1

        gkPtrkTrig init 0

        gi_snc_delay init 0.13 ; sync delay, delays metro/drumloop to sync with live-recorded ftables
        giampdiv init 1/32768 ; 1/32768 calculated once for frequent lookup (instr 335, 336, 337)


;****************************************************************
; GUI widgets instrument
;****************************************************************
        instr 1

gkupdate1 metro 6 ; GUI update frequency, higher values -> smoother update, but its CPU hungry !

;******************************************************************


igfxknobsize = 40

#define EfxSend(A'B'C'D'E'F'G'H'I'J'K'L) #
; arguments: Name, upper left X pos, upper left Y pos, init params (args D-L)
ihfxbox$A FLbox "Effect Sends", 5, 1 , 11, 424, 17, $B, $C
                        FLlabel   10, 1, 2, 0, 0, 0

i$Afxknoby1 = $C + 25
i$Afxvaly1 = i$Afxknoby1 + 55
i$Afxknobx1 = $B
i$Afxknobx2 = i$Afxknobx1 + 48
i$Afxknobx3 = i$Afxknobx2 + 48
i$Afxknobx4 = i$Afxknobx3 + 48
i$Afxknobx5 = i$Afxknobx4 + 48
i$Afxknobx6 = i$Afxknobx5 + 48
i$Afxknobx7 = i$Afxknobx6 + 48
i$Afxknobx8 = i$Afxknobx7 + 48
i$Afxknobx9 = i$Afxknobx8 + 48

ih$A_cleanV FLvalue " ", 40, 17, i$Afxknobx1, i$Afxvaly1
ih$A_rmV FLvalue " ", 40, 17, i$Afxknobx2, i$Afxvaly1
ih$A_fmV FLvalue " ", 40, 17, i$Afxknobx3, i$Afxvaly1
ih$A_filt1V FLvalue " ", 40, 17, i$Afxknobx4, i$Afxvaly1
ih$A_distV FLvalue " ", 40, 17, i$Afxknobx5, i$Afxvaly1
ih$A_filt2V FLvalue " ", 40, 17, i$Afxknobx6, i$Afxvaly1
ih$A_del1V FLvalue " ", 40, 17, i$Afxknobx7, i$Afxvaly1
ih$A_del2V FLvalue " ", 40, 17, i$Afxknobx8, i$Afxvaly1
ih$A_revbV FLvalue " ", 40, 17, i$Afxknobx9, i$Afxvaly1

gk$A_clean,ih$A_clean FLknob "Dry ",    0, 1, 0, 1, ih$A_cleanV, igfxknobsize, i$Afxknobx1, i$Afxknoby1
gk$A_rm,ih$A_rm FLknob "RingMod ",    0, 1, 0, 1, ih$A_rmV,    igfxknobsize, i$Afxknobx2, i$Afxknoby1
gk$A_fm,ih$A_fm FLknob "FreqMod ",    0, 1, 0, 1, ih$A_fmV,    igfxknobsize, i$Afxknobx3, i$Afxknoby1
gk$A_filt1,ih$A_filt1 FLknob "Filter1",    0, 1, 0, 1, ih$A_filt1V, igfxknobsize, i$Afxknobx4, i$Afxknoby1
gk$A_dist,ih$A_dist FLknob "Distortion",    0, 1, 0, 1, ih$A_distV,   igfxknobsize, i$Afxknobx5, i$Afxknoby1
gk$A_filt2,ih$A_filt2 FLknob "Filter2",    0, 1, 0, 1, ih$A_filt2V, igfxknobsize, i$Afxknobx6, i$Afxknoby1
gk$A_del1,ih$A_del1 FLknob "Delay1",    0, 1, 0, 1, ih$A_del1V,  igfxknobsize, i$Afxknobx7, i$Afxknoby1
gk$A_del2,ih$A_del2 FLknob "Delay2",    0, 1, 0, 1, ih$A_del2V,  igfxknobsize, i$Afxknobx8, i$Afxknoby1
gk$A_revb,ih$A_revb FLknob "Reverb1",    0, 1, 0, 1, ih$A_revbV,  igfxknobsize, i$Afxknobx9, i$Afxknoby1

                        FLsetVal_i $D, ih$A_clean
                        FLsetVal_i $E, ih$A_rm
                        FLsetVal_i $F, ih$A_fm
                        FLsetVal_i $G, ih$A_filt1
                        FLsetVal_i $H, ih$A_dist
                        FLsetVal_i $I, ih$A_filt2
                        FLsetVal_i $J, ih$A_del1
                        FLsetVal_i $K, ih$A_del2
                        FLsetVal_i $L, ih$A_revb
#

;******************************************************************

        FLpanel         "Pitch Tracker",680,430,100,100 ;***** start of container

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0

ihPbox1 FLbox "Recording", 5, 1, 11, 650, 55,  15,  20
gkPSmpl,ihP01 FLbutton "Sample Pitch",  1, 0, 2, 120, 20,  30,  40, -105 , 2, 0, -1
gkPn1,ihPn1 FLcount "Pitch mel. no", 1, 3, 1, 2, 1, 90, 20, 460,  40, -1, -1

ihPbox2 FLbox "Playback", 5, 1, 11, 650,175,  15, 100

gkPGrFrq,ihP02 FLbutton "Grain2Freq",     1, 0, 2, 80, 20,  30, 120, -105 , 2, 0, -1
ihPbox3 FLbox "Freq Multi", 1, 1, 10, 100, 15, 120, 110
gkPmul1,ihPmul1 FLbutBank 2, 4, 1, 100, 15, 120, 125, -105, -1
gkPmul1 init 2
gkPmulti1 table gkPmul1, 185; freq multiply factor
gktPAmp1,ihP03 FLbutton "Amp enable",    1, 0, 2, 80, 20, 240, 120, -105 , 2, 0, -1
gkPa1,ihPa1 FLtext "Amp amount", 0, 4, 0.1, 1, 50, 20, 340, 120
gkPa2,ihPa2 FLtext "Amp thresh", 0, 2, 0.1, 1, 50, 20, 400, 120
gkPn2,ihPn2 FLcount "Pitch mel. no", 1, 4, 1, 2, 1, 90, 20, 460, 120, -1, -1
gkPtrg1,ihPtrg1 FLcount "retrig measure", 0, 8, 1, 2, 1, 90, 20, 550, 120, -1, -1

gkPGrTsp,ihP04 FLbutton "Grain2Transp",   1, 0, 2, 80, 20,  30, 160, -105 , 2, 0, -1
ihPbox4 FLbox "Freq Multi", 1, 1, 10, 100, 15, 120, 150
gkPmul2,ihPmul2 FLbutBank 2, 4, 1, 100, 15, 120, 165, -105, -1
gkPmul2 init 2
gkPmulti2 table gkPmul2, 185; freq multiply factor
gktPAmp2,ihP05 FLbutton "Amp enable",    1, 0, 2, 80, 20, 240, 160, -105 , 2, 0, -1
gkPa3,ihPa3 FLtext "Amp amount", 0, 4, 0.1, 1, 50, 20, 340, 160
gkPa4,ihPa4 FLtext "Amp thresh", 0, 2, 0.1, 1, 50, 20, 400, 160
gkPn3,ihPn3 FLcount "Pitch mel. no", 1, 4, 1, 2, 1, 90, 20, 460, 160, -1, -1
gkPtrg2,ihPtrg2 FLcount "retrig measure", 0, 8, 1, 2, 1, 90, 20, 550, 160, -1, -1

gkPFMFrq,ihP06 FLbutton "FM Freq",       1, 0, 2, 80, 20,  30, 200, -105 , 2, 0, -1
ihPbox4 FLbox "Freq Multi", 1, 1, 10, 100, 15, 120, 190
gkPmul3,ihPmul3 FLbutBank 2, 4, 1, 100, 15, 120, 205, -105, -1
gkPmul3 init 2
gkPmulti3 table gkPmul3, 185; freq multiply factor
gkPn4,ihPn4 FLcount "Pitch mel. no", 1, 4, 1, 2, 1, 90, 20, 460, 200, -1, -1
gkPtrg3,ihPtrg3 FLcount "retrig measure", 0, 8, 1, 2, 1, 90, 20, 550, 200, -1, -1

gkPRMFrq,ihP07 FLbutton "RM Freq",       1, 0, 2, 80, 20,  30, 240, -105 , 2, 0, -1
ihPbox5 FLbox "Freq Multi", 1, 1, 10, 100, 15, 120, 230
gkPmul4,ihPmul4 FLbutBank 2, 4, 1, 100, 15, 120, 245, -105, -1
gkPmul4 init 2
gkPmulti4 table gkPmul4, 185; freq multiply factor
gkPn5,ihPn5 FLcount "Pitch mel. no", 1, 4, 1, 2, 1, 90, 20, 460, 240, -1, -1
gkPtrg4,ihPtrg4 FLcount "retrig measure", 0, 8, 1, 2, 1, 90, 20, 550, 240, -1, -1

gkPBasSyn,ihP08 FLbutton "BasSynth",     1, 0, 2, 80, 20,  30, 285, -105 , 2, 0, -1
ihPbox6 FLbox "Freq Multi", 1, 1, 10, 100, 15, 120, 275
gkPmul5,ihPmul5 FLbutBank 2, 4, 1, 100, 15, 120, 290, -105, -1
gkPmul5 init 2
gkPmulti5 table gkPmul5, 185; freq multiply factor
gkBasSynAmp, ihBasSynAmp FLtext "Out Amp", 0, 2, 0.05, 1, 60, 20, 240, 285
gkPa5,ihPa5 FLtext "Amp follow", 0, 4, 0.1, 1, 50, 20, 340, 285
gkPn6,ihPn6 FLcount "Pitch mel. no", 1, 4, 1, 2, 1, 90, 20, 460, 285, -1, -1
gkPtrg5,ihPtrg5 FLcount "retrig measure", 0, 8, 1, 2, 1, 90, 20, 550, 285, -1, -1

        $EfxSend.(BasSyn'20'320'0.5'0'0'0'0'0.15'0'0'0.03)

                FLsetAlign 2, ihPbox1
                FLsetAlign 2, ihPbox2
                FLsetAlign 2, ihPa1
                FLsetAlign 2, ihPa2
                FLsetAlign 2, ihPa3
                FLsetAlign 2, ihPa4
                FLsetAlign 2, ihPn1
                FLsetAlign 2, ihPn2
                FLsetAlign 2, ihPn3
                FLsetAlign 2, ihPn4
                FLsetAlign 2, ihPn5
                FLsetVal_i 1, ihPn1
                FLsetVal_i 1, ihPn2
                FLsetVal_i 1, ihPn3
                FLsetVal_i 1, ihPn4
                FLsetVal_i 1, ihPn5
                FLsetVal_i 1, ihPn6
                FLsetVal_i 2, ihPa1
                FLsetVal_i 0, ihPa2
                FLsetVal_i 2, ihPa3
                FLsetVal_i 0, ihPa4
                FLsetVal_i 1, ihPa5
                FLsetVal_i 1, ihBasSynAmp

        FLpanelEnd     ;***** end of container

                        FLpanel         "Pattern Sequencer",700,535,120,40 ;***** start of container
                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0

# define Pattern(A) #
iptrn$AX1 = iptrn$AX + 100
iptrn$AX2 = iptrn$AX + 200
iptrn$AX3 = iptrn$AX2  + 30
iptrn$AX4 = iptrn$AX3  + 30
iptrn$AX5 = iptrn$AX4  + 30
iptrn$AX6 = iptrn$AX5  + 30
iptrn$AX7 = iptrn$AX6  + 30
iptrn$AX8 = iptrn$AX7  + 30
iptrn$AX9 = iptrn$AX8  + 30
iptrn$AX10 = iptrn$AX9  + 30
iptrn$AX11 = iptrn$AX10 + 30
iptrn$AX12 = iptrn$AX11 + 30
iptrn$AX13 = iptrn$AX12 + 30
iptrn$AX14 = iptrn$AX13 + 30
iptrn$AX15 = iptrn$AX14 + 30
iptrn$AX16 = iptrn$AX15 + 30
iptrn$AX17 = iptrn$AX16 + 30

iptrn$AY1 = iptrn$AY + 35
iptrn$AY2 = iptrn$AY1 + 25
iptrn$AY3 = iptrn$AY2 + 25
iptrn$AY4 = iptrn$AY3 + 35

iptrn$Aheight = (iptrn$AY4 + 40) - iptrn$AY
iptrn$Awidth = (iptrn$AX17 + 50) - iptrn$AX

                FLlabel   -1
                FLlabel   10, 1, 3, 0, 0, 0

ihptrn$Abox FLbox "pattern$A", 5, 1, 11, iptrn$Awidth, iptrn$Aheight, iptrn$AX-10, iptrn$AY-10
                        FLsetAlign 2, ihptrn$Abox
       
gkpt$Afno1,ihptrn$Afno FLcount "sample no.", 1, 14, 1, 2, 1,  90, 20, iptrn$AX,  iptrn$AY, -1, -1
                        FLsetVal_i $A, ihptrn$Afno
gkptrn$Asht,ihptrn$Asht FLbutton "shortest",   1, 0, 2,       70, 20, iptrn$AX1, iptrn$AY, -105 , 2, 0, -1
k$Ashort table gkpt$Afno1, 111 ; point to shortest sounds table,
gkpt$Afno = (gkptrn$Asht == 1 ? k$Ashort : gkpt$Afno1) ; select amongst the sortest sounds

gkp$Afmfrq, ihp$Afmfrq FLtext "fm freq", 0, 4000, 10, 1,  50, 20, iptrn$AX,  iptrn$AY1
gkp$Afmindx,ihp$Afmindx FLtext "fm index", 0, 5,    0.1, 1, 50, 20, iptrn$AX1, iptrn$AY1
gkp$AfltQ, ihp$AfltQ FLtext "filter Q", 1, 40,    1, 1, 50, 20, iptrn$AX,  iptrn$AY2
gkp$Afltfrq,ihp$Afltfrq FLtext "cutoff", 0, 7000, 10, 1,  50, 20, iptrn$AX1, iptrn$AY2
gkp$Afdin, ihp$Afdin FLtext "fade in", 0, 1, 0.05, 1, 50, 20, iptrn$AX,  iptrn$AY3
gkp$Afdout, ihp$Afdout FLtext "fade out", 0.1, 1, 0.05, 1, 50, 20, iptrn$AX1, iptrn$AY3

                        FLsetVal_i 400, ihp$Afmfrq
                        FLsetVal_i 0.7, ihp$Afmindx
                        FLsetVal_i 5000, ihp$Afltfrq
                        FLsetVal_i 2, ihp$AfltQ
                        FLsetVal_i 0.1, ihp$Afdout
                        FLsetAlign 5, ihp$Afmfrq
                        FLsetAlign 5, ihp$Afmindx
                        FLsetAlign 5, ihp$AfltQ
                        FLsetAlign 5, ihp$Afltfrq
                        FLsetAlign 5, ihp$Afdin
                        FLsetAlign 5, ihp$Afdout

gkptrn$A_1,ihptrn$A_01 FLbutton "1",     1, 0, 2,         30, 20, iptrn$AX2,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_2,ihptrn$A_02 FLbutton "2",     1, 0, 2,         30, 20, iptrn$AX3,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_3,ihptrn$A_03 FLbutton "3",     1, 0, 2,         30, 20, iptrn$AX4,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_4,ihptrn$A_04 FLbutton "4",     1, 0, 2,         30, 20, iptrn$AX5,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_5,ihptrn$A_05 FLbutton "5",     1, 0, 2,         30, 20, iptrn$AX6,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_6,ihptrn$A_06 FLbutton "6",     1, 0, 2,         30, 20, iptrn$AX7,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_7,ihptrn$A_07 FLbutton "7",     1, 0, 2,         30, 20, iptrn$AX8,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_8,ihptrn$A_08 FLbutton "8",     1, 0, 2,         30, 20, iptrn$AX9,  iptrn$AY, -105 , 2, 0, -1
gkptrn$A_9,ihptrn$A_09 FLbutton "9",     1, 0, 2,         30, 20, iptrn$AX10, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_10,ihptrn$A_10 FLbutton "10",     1, 0, 2,         30, 20, iptrn$AX11, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_11,ihptrn$A_11 FLbutton "11",     1, 0, 2,         30, 20, iptrn$AX12, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_12,ihptrn$A_12 FLbutton "12",     1, 0, 2,         30, 20, iptrn$AX13, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_13,ihptrn$A_13 FLbutton "13",     1, 0, 2,         30, 20, iptrn$AX14, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_14,ihptrn$A_14 FLbutton "14",     1, 0, 2,         30, 20, iptrn$AX15, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_15,ihptrn$A_15 FLbutton "15",     1, 0, 2,         30, 20, iptrn$AX16, iptrn$AY, -105 , 2, 0, -1
gkptrn$A_16,ihptrn$A_16 FLbutton "16",     1, 0, 2,         30, 20, iptrn$AX17, iptrn$AY, -105 , 2, 0, -1

gkp$A_1fm, ihp$A_01fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX2,  iptrn$AY1
gkp$A_2fm, ihp$A_02fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX3,  iptrn$AY1
gkp$A_3fm, ihp$A_03fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX4,  iptrn$AY1
gkp$A_4fm, ihp$A_04fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX5,  iptrn$AY1
gkp$A_5fm, ihp$A_05fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX6,  iptrn$AY1
gkp$A_6fm, ihp$A_06fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX7,  iptrn$AY1
gkp$A_7fm, ihp$A_07fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX8,  iptrn$AY1
gkp$A_8fm, ihp$A_08fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX9,  iptrn$AY1
gkp$A_9fm, ihp$A_09fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX10, iptrn$AY1
gkp$A_10fm, ihp$A_10fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX11, iptrn$AY1
gkp$A_11fm, ihp$A_11fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX12, iptrn$AY1
gkp$A_12fm, ihp$A_12fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX13, iptrn$AY1
gkp$A_13fm, ihp$A_13fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX14, iptrn$AY1
gkp$A_14fm, ihp$A_14fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX15, iptrn$AY1
gkp$A_15fm, ihp$A_15fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX16, iptrn$AY1
gkp$A_16fm, ihp$A_16fm FLtext " ", 0, 2, 0.1, 1, 30, 20, iptrn$AX17, iptrn$AY1

gkp$A_1flt, ihp$A_01flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX2,  iptrn$AY2
gkp$A_2flt, ihp$A_02flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX3,  iptrn$AY2
gkp$A_3flt, ihp$A_03flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX4,  iptrn$AY2
gkp$A_4flt, ihp$A_04flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX5,  iptrn$AY2
gkp$A_5flt, ihp$A_05flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX6,  iptrn$AY2
gkp$A_6flt, ihp$A_06flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX7,  iptrn$AY2
gkp$A_7flt, ihp$A_07flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX8,  iptrn$AY2
gkp$A_8flt, ihp$A_08flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX9,  iptrn$AY2
gkp$A_9flt, ihp$A_09flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX10, iptrn$AY2
gkp$A_10flt,ihp$A_10flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX11, iptrn$AY2
gkp$A_11flt,ihp$A_11flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX12, iptrn$AY2
gkp$A_12flt,ihp$A_12flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX13, iptrn$AY2
gkp$A_13flt,ihp$A_13flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX14, iptrn$AY2
gkp$A_14flt,ihp$A_14flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX15, iptrn$AY2
gkp$A_15flt,ihp$A_15flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX16, iptrn$AY2
gkp$A_16flt,ihp$A_16flt FLtext " ", 0.1, 2, 0.1, 1, 30, 20, iptrn$AX17, iptrn$AY2

                        FLsetVal_i 1, ihp$A_01flt
                        FLsetVal_i 1, ihp$A_02flt
                        FLsetVal_i 1, ihp$A_03flt
                        FLsetVal_i 1, ihp$A_04flt
                        FLsetVal_i 1, ihp$A_05flt
                        FLsetVal_i 1, ihp$A_06flt
                        FLsetVal_i 1, ihp$A_07flt
                        FLsetVal_i 1, ihp$A_08flt
                        FLsetVal_i 1, ihp$A_09flt
                        FLsetVal_i 1, ihp$A_10flt
                        FLsetVal_i 1, ihp$A_11flt
                        FLsetVal_i 1, ihp$A_12flt
                        FLsetVal_i 1, ihp$A_13flt
                        FLsetVal_i 1, ihp$A_14flt
                        FLsetVal_i 1, ihp$A_15flt
                        FLsetVal_i 1, ihp$A_16flt

gkp$A_1dur, ikp$A_01dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX2,  iptrn$AY3
gkp$A_2dur, ikp$A_02dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX3,  iptrn$AY3
gkp$A_3dur, ikp$A_03dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX4,  iptrn$AY3
gkp$A_4dur, ikp$A_04dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX5,  iptrn$AY3
gkp$A_5dur, ikp$A_05dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX6,  iptrn$AY3
gkp$A_6dur, ikp$A_06dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX7,  iptrn$AY3
gkp$A_7dur, ikp$A_07dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX8,  iptrn$AY3
gkp$A_8dur, ikp$A_08dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX9,  iptrn$AY3
gkp$A_9dur, ikp$A_09dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX10, iptrn$AY3
gkp$A_10dur,ikp$A_10dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX11, iptrn$AY3
gkp$A_11dur,ikp$A_11dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX12, iptrn$AY3
gkp$A_12dur,ikp$A_12dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX13, iptrn$AY3
gkp$A_13dur,ikp$A_13dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX14, iptrn$AY3
gkp$A_14dur,ikp$A_14dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX15, iptrn$AY3
gkp$A_15dur,ikp$A_15dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX16, iptrn$AY3
gkp$A_16dur,ikp$A_16dur FLtext " ", 0.3, 1, 0.1, 1, 30, 20, iptrn$AX17, iptrn$AY3

                        FLsetVal_i 1, ikp$A_01dur
                        FLsetVal_i 1, ikp$A_02dur
                        FLsetVal_i 1, ikp$A_03dur
                        FLsetVal_i 1, ikp$A_04dur
                        FLsetVal_i 1, ikp$A_05dur
                        FLsetVal_i 1, ikp$A_06dur
                        FLsetVal_i 1, ikp$A_07dur
                        FLsetVal_i 1, ikp$A_08dur
                        FLsetVal_i 1, ikp$A_09dur
                        FLsetVal_i 1, ikp$A_10dur
                        FLsetVal_i 1, ikp$A_11dur
                        FLsetVal_i 1, ikp$A_12dur
                        FLsetVal_i 1, ikp$A_13dur
                        FLsetVal_i 1, ikp$A_14dur
                        FLsetVal_i 1, ikp$A_15dur
                        FLsetVal_i 1, ikp$A_16dur

ihP7$A51 FLbox "Effect Sends", 5, 1 , 11, 190, 20, 10, iptrn$AY4
                FLlabel   -1
                FLlabel   10, 1, 2, 0, 0, 0

gkPtn$A_clean,ihFP$A11 FLtext "Dry ",    0, 1, 0.05, 1, 44, 20, iptrn$AX2,     iptrn$AY4
gkPtn$A_pan,ihFP$A11p FLtext "Pan ",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+49,  iptrn$AY4
gkPtn$A_rm,ihFP$A12 FLtext "RingMod ",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+98, iptrn$AY4
gkPtn$A_fm,ihFP$A13 FLtext "FreqMod ",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+147, iptrn$AY4
gkPtn$A_filt1,ihFP$A14 FLtext "Filter1",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+196, iptrn$AY4
gkPtn$A_dist,ihFP$A15 FLtext "Distortion",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+245, iptrn$AY4
gkPtn$A_filt2,ihFP$A16 FLtext "Filter2",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+294, iptrn$AY4
gkPtn$A_del1,ihFP$A17 FLtext "Delay1",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+343, iptrn$AY4
gkPtn$A_del2,ihFP$A18 FLtext "Delay2",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+392, iptrn$AY4
gkPtn$A_revb,ihFP$A19 FLtext "Reverb1",    0, 1, 0.05, 1, 44, 20, iptrn$AX2+441, iptrn$AY4

                        FLsetVal_i 1, ihFP$A11
                        FLsetVal_i 0.5, ihFP$A11p
                        FLsetVal_i 0, ihFP$A12
                        FLsetVal_i 0, ihFP$A13
                        FLsetVal_i 0, ihFP$A14
                        FLsetVal_i 0, ihFP$A15
                        FLsetVal_i 0, ihFP$A16
                        FLsetVal_i 0, ihFP$A17
                        FLsetVal_i 0, ihFP$A18
                        FLsetVal_i 0, ihFP$A19
#

iptrn1X = 10 ; upper left corner of pattern 1 section
iptrn1Y = 25 ; adjusting these two nmumbers moves the whole GUI block
$Pattern.(1)
iptrn2X = 10 ; upper left corner of pattern 2 section
iptrn2Y = 205 ; adjusting these two nmumbers moves the whole GUI block
$Pattern.(2)
iptrn3X = 10 ; upper left corner of pattern 3 section
iptrn3Y = 385 ; adjusting these two nmumbers moves the whole GUI block
$Pattern.(3)

                        FLpanelEnd
;******************************************************************
;******************************************************************
                        FLpanel "ImproSculpt",1010,710,5,20

;***************************************
ihbxInputs FLbox "Inputs", 5, 1, 12, 310, 340,   5,  20
                        FLsetAlign 2, ihbxInputs
                        FLlabel   10, 1, 3, 0, 0, 0

inpwidth = 147
inpt1X1 = 15
inpt1X1a = inpt1X1 + 20
inpt1X2 = inpt1X1a + 45
inpt1X3 = inpt1X1a + 60

inpt2X1 = inpt1X1 + inpwidth + 5
inpt2X1a = inpt2X1 + 15
inpt2X2 = inpt2X1a + 45
inpt2X3 = inpt2X1a + 60

inpt1Y0 = 50
inpt1Y1 = inpt1Y0 + 35
inpt1Y2 = inpt1Y1 + 35
inpt1Y3 = inpt1Y2 + 35
inpt1Y4 = inpt1Y3 + 35
inpt1Y5 = inpt1Y4 + 35
inpt1Y6 = inpt1Y5 + 35
inpt1Y7 = inpt1Y6 + 35
inpt1Y8 = inpt1Y7 + 35

ih199 FLbox "Input 1", 5, 1 , 11, inpwidth, 315, 10, 40
                        FLsetAlign 2, ih199
;level display
gkInAmp1,gihInAmp1 FLslider        " ", 0, 30000, 0, 2 , -1,      10, 280, inpt1X1, inpt1Y0
                        FLsetColor 80, 150, 50,  gihInAmp1
                        FLsetColor2 230, 50,  30,  gihInAmp1

gkinputmix,ihinputmix FLbutton "Mix inputs to 1",      1, 0, 2,     115, 20, inpt1X1a, inpt1Y0, -105 , 2, 0, -1
                        FLsetAlign 1, ihinputmix

gkt2,ih101 FLbutton "Auto Sampling",     1, 0, 2,        115, 25, inpt1X1a, inpt1Y1, -105 , 2, 0, -1
gk_manual1,ih101m FLbutton "Manual",       1, 0, 2,         60, 20, inpt1X1a, inpt1Y2, -105 , 2, 0, -1
gk_mantrig1,ih101t FLbutton "Trig",       1, 0, 2,         55, 20, inpt1X3, inpt1Y2, -105 , 2, 0, -1
gk_next1,ih101n FLbutton "Auto Cycle Slot" ,  1, 0, 2,        115, 20, inpt1X1a, inpt1Y3, -105 , 2, 0, -1
gih102 FLvalue "Current Slot",      40, 20, inpt1X1a, inpt1Y4
gk_v1_minfno,ih103 FLcount "First slot",        1, 14, 1, 2, 1, 115, 20, inpt1X1a, inpt1Y5, -1, -1
gk_v1_maxfno,ih104 FLcount "Last slot",         1, 14, 1, 2, 1, 115, 20, inpt1X1a, inpt1Y6, -1, -1
ih110 FLvalue "auto threshold",        70, 20, inpt1X2, inpt1Y7+10
gk_sampthresh1,ih109 FLknob " ",    1, 10000, -1, 1, ih110, 40, inpt1X1a, inpt1Y7

                        FLsetBox 2, ih101
                        FLsetBox 2, ih101m
                        FLsetBox 2, ih101t
                        FLsetBox 2, ih101n

                        FLsetAlign 1, ih101
                        FLsetAlign 1, ih101m
                        FLsetAlign 1, ih101t
                        FLsetAlign 1, ih101n
                        FLsetAlign 5, gih102
                        FLsetVal_i 1, ih103
                        FLsetAlign 3, ih103
                        FLsetVal_i 7, ih104
                        FLsetAlign 3, ih104
                        FLsetVal_i 500, ih109

ih198 FLbox "Input 2", 5, 1 , 11, inpwidth, 315, inpwidth+15, 40
                        FLsetAlign 2, ih198
;level display
gkInAmp2,gihInAmp2 FLslider        " ", 0, 30000, 0, 2 , -1,      10, 280, inpt2X1, inpt1Y0
                        FLsetColor 80, 150, 50,  gihInAmp2
                        FLsetColor2 230, 50,  30,  gihInAmp2

gkt22,ih105 FLbutton "Auto Sampling",     1, 0, 2,        115, 25,  inpt2X1a, inpt1Y1, -105 , 2, 0, -1
gk_manual2,ih105m FLbutton "Manual",            1, 0, 2,         60, 20,  inpt2X1a, inpt1Y2, -105 , 2, 0, -1
gk_mantrig2,ih105t FLbutton "Trig",              1, 0, 2,         55, 20,  inpt2X3, inpt1Y2, -105 , 2, 0, -1
gk_next2,ih105n FLbutton "Auto Cycle Slot",   1, 0, 2,        115, 20,  inpt2X1a, inpt1Y3, -105 , 2, 0, -1
gih106 FLvalue "Current Slot",      40, 20,  inpt2X1a, inpt1Y4
gk_v2_minfno,ih107 FLcount "First slot",        1, 14, 1, 2, 1, 115, 20,  inpt2X1a, inpt1Y5, -1, -1
gk_v2_maxfno,ih108 FLcount "Last slot",         1, 14, 1, 2, 1, 115, 20,  inpt2X1a, inpt1Y6, -1, -1
ih112 FLvalue "auto threshold",        70, 20,  inpt2X2, inpt1Y7+10
gk_sampthresh2,ih111 FLknob " ",    1, 10000, -1, 1, ih112, 40, inpt2X1a, inpt1Y7

                        FLsetBox 2, ih105
                        FLsetBox 2, ih105m
                        FLsetBox 2, ih105t
                        FLsetBox 2, ih105n

                        FLsetAlign 1, ih105
                        FLsetAlign 1, ih105m
                        FLsetAlign 1, ih105t
                        FLsetAlign 1, ih105n
                        FLsetAlign 5, gih106
                        FLsetVal_i 8, ih107
                        FLsetAlign 3, ih107
                        FLsetVal_i 14,ih108
                        FLsetAlign 3, ih108
                        FLsetVal_i 500, ih111


;***************************************
ihbxRythm FLbox "Rhythm", 5, 1, 12, 210, 355, 320,  20
                        FLsetAlign 2, ihbxRythm

iRy1X1 = 352
iRy1X2 = iRy1X1 + 45
iRy1X3 = iRy1X2 + 40

iRy1Y1 = 30
iRy1Y2 = iRy1Y1 + 87
iRy1Y3 = iRy1Y2 + 117

gktR,ihtRythm FLbutton "Rhythm On" ,    1, 0, 12, 146, 22,  iRy1X1, iRy1Y1, -105 , 4, 0, -1
                        FLsetAlign 1, ihtRythm

                        FLtabs 206, 313, 322, 60
                        FLgroup "Master", 206, 298, 322, 75
                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

ihBoxTm1 FLbox "Tempo", 5, 1, 10, 145, 17, iRy1X1, iRy1Y2-25
gihCurTpo FLvalue "result", 60, 20, iRy1X3, iRy1Y2-5
                        FLsetAlign 3, gihCurTpo
gktmpo1,ihtmpo1 FLbutBank 2, 1, 5, 40, 80, iRy1X1, iRy1Y2, -105, -1
gktmpo1 init 2
gktmpo1a table gktmpo1, 185
gktaptemp, ihtaptemp FLbutton "taptempo" ,    1, 0, 11, 60, 20, iRy1X3, iRy1Y2+25, 105 , 19, 0, 0.1
gkbtpoT, ihbtpoT FLtext "Adjust", 30, 240, 1, 1, 60, 20, iRy1X3, iRy1Y2+50
                        FLsetVal_i 60, ihbtpoT
                        FLsetAlign 3, ihbtpoT
gkbtpoTemp = gkbtpoT * gktmpo1a
;gkbtpo = gkbtpoT * gktmpo1a
; update tempo parameter only if GUI has been used this k-cycle, otherwise let old value pass thru
; this is useful when using other processes as e.g. taptempo to change parameters,
; without it, the GUI would always overrule the midi ctrl,
; because of the table lookup in the transpose parameter

gkbtpoC1 init 0
gkbtpo init 60
gkbtpo = (gkbtpoC1 == gkbtpoTemp ? gkbtpo : gkbtpoTemp )
gkbtpoC1 = gkbtpoTemp

; FLsetVal gkupdate1, gkbtpo, gihCurTpo



                        FLlabel   -1
                        FLlabel   10, 1, 4, 0, 0, 0
ihRytextTm1 FLbox "0.25", 1, 1, 10, 30, 20, iRy1X2, iRy1Y2
ihRytextTm2 FLbox "0.5",  1, 1, 10, 30, 20, iRy1X2, iRy1Y2 + 16
ihRytextTm3 FLbox "1",   1, 1, 10, 30, 20, iRy1X2, iRy1Y2 + 32
ihRytextTm4 FLbox "2",   1, 1, 10, 30, 20, iRy1X2, iRy1Y2 + 48
ihRytextTm5 FLbox "4",   1, 1, 10, 30, 20, iRy1X2, iRy1Y2 + 64

                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0
ihBoxTs1 FLbox "Time Signature", 5, 1, 10, 145, 17, iRy1X1, iRy1Y3-25
gkTimSig,ihTimSig FLbutBank 2, 1, 8, 40, 128, iRy1X1, iRy1Y3, -105, -1
gktimesign = gkTimSig+201 ; time signature, points to ftable no

                        FLlabel   -1
                        FLlabel   10, 1, 4, 0, 0, 0
ihRytextTs1 FLbox "4/4",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3
ihRytextTs2 FLbox "5/4",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 16
ihRytextTs3 FLbox "3/4 ",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 32
ihRytextTs4 FLbox "3/8",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 48
ihRytextTs5 FLbox "5/8",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 64
ihRytextTs6 FLbox "7/8",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 80
ihRytextTs7 FLbox "3/16",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 96
ihRytextTs8 FLbox "5/16",   1, 1, 10, 30, 20, iRy1X2, iRy1Y3 + 112

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0

gkmetro_on,ihmtro_on FLbutton "Metro" ,     1, 0, 2,        60, 22,  iRy1X3, iRy1Y3+17, -105 , 4, 0, -1
;gkmetro_onM,ihmtro_onM FLbutton "MetroMidi" ,   1, 0, 2,        60, 22,  iRy1X3, iRy1Y3+68, -105 , 4, 0, -1

                        FLgroupEnd


                        FLgroup "Phrases", 206, 298, 322, 75
                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

iRy2X1 = iRy1X1 - 3
iRy2X2 = iRy2X1 + 60
iRy2X3 = iRy2X2 + 60

iRy2Y1 = iRy1Y1
iRy2Y2 = iRy2Y1 + 62
iRy2Y3 = iRy2Y2 + 140

ihphrasetxt1 FLbox "Rplay1", 1, 1, 10,   50, 15, iRy2X1, iRy2Y2
gk_forcetrig1,ihphr1f FLbutton "force", 1, 0, 1,   50, 17, iRy2X1, iRy2Y2+15,     -105 , 4, 0, -1
gkloop_phr1,ihphr1l FLbutton "loop",   1, 0, 2,   50, 17, iRy2X1, iRy2Y2+32,  -105 , 4, 0, -1
gkphrasetick,ihphr1t FLbutton "Tick" ,     1, 0, 2,         50, 17, iRy2X1, iRy2Y2+49, -105 , 4, 0, -1
ihpausetxt1 FLbox "Phrase Pause", 1, 1, 10,   165, 15, iRy2X1, iRy2Y2+72
gkminpause1,ihphr1min FLtext "min", 0, 16, 1, 1, 50, 20, iRy2X1, iRy2Y2+87
gkmaxpause1,ihphr1max FLtext "max", 0, 16, 1, 1, 50, 20, iRy2X1, iRy2Y2+107

                        FLsetAlign 1, ihphr1f
                        FLsetAlign 1, ihphr1l
                        FLsetAlign 1, ihphr1t
                        FLsetAlign 4, ihphr1min
                        FLsetAlign 4, ihphr1max
                        FLsetVal_i 0, ihphr1min
                        FLsetVal_i 2, ihphr1max

ihphrasetxt2 FLbox "Rplay2", 1, 1, 10,   50, 15, iRy2X2, iRy2Y2
gk_forcetrig2,ihphr2f FLbutton "force", 1, 0, 1,   50, 17, iRy2X2, iRy2Y2+15,     -105 , 4, 0, -1
gkloop_phr2,ihphr2l FLbutton "loop",   1, 0, 2,   50, 17, iRy2X2, iRy2Y2+32,  -105 , 4, 0, -1
gkphrasetick2,ihphr2t FLbutton "Tick" ,     1, 0, 2,         50, 17, iRy2X2, iRy2Y2+49, -105 , 4, 0, -1
gkminpause2,ihphr2min FLtext " ", 0, 16, 1, 1, 50, 20, iRy2X2, iRy2Y2+87
gkmaxpause2,ihphr2max FLtext " ", 0, 16, 1, 1, 50, 20, iRy2X2, iRy2Y2+107
                        FLsetAlign 1, ihphr2f
                        FLsetAlign 1, ihphr2l
                        FLsetAlign 1, ihphr2t
                        FLsetAlign 4, ihphr2min
                        FLsetAlign 4, ihphr2max
                        FLsetVal_i 0, ihphr2min
                        FLsetVal_i 2, ihphr2max

ihphrasetxt3 FLbox "RAG",   1, 1, 10,   50, 15, iRy2X3, iRy2Y2
gk_forcetrig3,ihphr3f FLbutton "force", 1, 0, 1,   50, 17, iRy2X3, iRy2Y2+15,     -105 , 4, 0, -1
gkloop_phr3,ihphr3l FLbutton "loop",   1, 0, 2,   50, 17, iRy2X3, iRy2Y2+32,  -105 , 4, 0, -1
gkphrasetick3,ihphr3t FLbutton "Tick" ,     1, 0, 2,         50, 17, iRy2X3, iRy2Y2+49, -105 , 4, 0, -1
gkminpause3,ihphr3min FLtext " ", 0, 16, 1, 1, 50, 20, iRy2X3, iRy2Y2+87
gkmaxpause3,ihphr3max FLtext " ", 0, 16, 1, 1, 50, 20, iRy2X3, iRy2Y2+107
                        FLsetAlign 1, ihphr3f
                        FLsetAlign 1, ihphr3l
                        FLsetAlign 1, ihphr3t
                        FLsetAlign 4, ihphr3min
                        FLsetAlign 4, ihphr3max
                        FLsetVal_i 0, ihphr3min
                        FLsetVal_i 0, ihphr3max

ihphrselBx FLbox "Phrase Selector", 1, 1, 10,   165,  15, iRy2X1, iRy2Y3
gkphr1N,ihphr1N FLtext " ", 0, 7, 1, 1, 50,  20, iRy2X1, iRy2Y3+15
gkphr2N,ihphr2N FLtext " ", 0, 7, 1, 1, 50,  20, iRy2X2, iRy2Y3+15
gkphr3N,ihphr3N FLtext " ", 0, 7, 1, 1, 50,  20, iRy2X3, iRy2Y3+15
                        FLsetVal_i 5, ihphr1N
                        FLsetVal_i 4, ihphr2N
                        FLsetVal_i 6, ihphr3N
gk_ryt_phrase = gkphr1N+301 ; rhythmic phrase select/init, points to ftable no
gk_ryt_phrase2 = gkphr2N+301 ; rhythmic phrase select/init, points to ftable no
gk_ryt_phrase3 = gkphr3N+301 ; rhythmic phrase select/init, points to ftable no

ihphr1Tpo FLbox "Phrase Tempo", 1, 1, 10, 165,  15, iRy2X1, iRy2Y3+45
gkphr1Tpo,ihphr1Tpo FLbutBank 2, 1, 4, 50,  64, iRy2X1, iRy2Y3+60, -105, -1
gkphr2Tpo,ihphr2Tpo FLbutBank 2, 1, 4, 50,  64, iRy2X2, iRy2Y3+60, -105, -1
gkphr3Tpo,ihphr3Tpo FLbutBank 2, 1, 4, 50,  64, iRy2X3, iRy2Y3+60, -105, -1
gkphr1Tpo init 1
gkphr2Tpo init 1
gkphr3Tpo init 2
gk_ryt_fact1 table gkphr1Tpo, 181 ; phrase tempo factor
gk_ryt_fact2 table gkphr2Tpo, 181 ; phrase tempo factor
gk_ryt_fact3 table gkphr3Tpo, 181 ; phrase tempo factor

ihphrasetpotxt1 FLbox "x0.5", 1, 1, 10,   26, 15, iRy2X1-26, iRy2Y3+60
ihphrasetpotxt2 FLbox "x1", 1, 1, 10,   26, 15, iRy2X1-26, iRy2Y3+76
ihphrasetpotxt3 FLbox "x2", 1, 1, 10,   26, 15, iRy2X1-26, iRy2Y3+92
ihphrasetpotxt4 FLbox "x4", 1, 1, 10,   26, 15, iRy2X1-26, iRy2Y3+108

                        FLgroupEnd

                        FLtabsEnd

;***************************************
ihbModules FLbox "Modules", 5, 1, 12, 470, 460, 535,  20
                        FLsetAlign 2, ihbModules

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0

                        FLtabs 466, 456, 537,  22

iGr1_knobsize = 40
iGr1_knoby1 =  60
iGr1_valy1 = iGr1_knoby1 + 55
iGr1_banky1 = iGr1_valy1 + 40
iGr1_knoby2 = iGr1_banky1 + 40
iGr1_valy2 = iGr1_knoby2 + 55
iGr1_slidy1 = iGr1_valy2 + 40
iGr1_slidy2 = iGr1_slidy1 + 30
iGr1_knoby3 = iGr1_knoby2 + 140

;iGr1_fxy = iGr1_valy2 + 90

iGr1_knobx1 =  540 + 17
iGr1_knobx2 =  iGr1_knobx1 + 48
iGr1_knobx3 =  iGr1_knobx2 + 48
iGr1_knobx4 =  iGr1_knobx3 + 48
iGr1_knobx5 =  iGr1_knobx4 + 48
iGr1_knobx6 =  iGr1_knobx5 + 48
iGr1_knobx7 =  iGr1_knobx6 + 48
iGr1_knobx8 =  iGr1_knobx7 + 48
iGr1_knobx9 =  iGr1_knobx8 + 48

#define RplayModule(A'B'C'D'E'F'G'H'I'J'K'L'M) #
;argument : module number, firstsound, lastsound, FM indx, FM freq, fm params (args F - M )

ihRpl$AtrspV FLvalue " ", 40, 15, iGr1_knobx1, iGr1_valy1
kRpl$Atrsp,ihRpl$Atrsp FLknob "Transp",  0, 2,     0, 1, ihRpl$AtrspV,  iGr1_knobsize, iGr1_knobx1,    iGr1_knoby1
                        FLsetVal_i 1, ihRpl$Atrsp
gkRpl$Ainv,ihRpl$Ainv FLbutton "inv",   1, 0,  2,   30, 15,       iGr1_knobx1+37, iGr1_knoby1, -1, -1
                        FLsetAlign 3, ihRpl$Ainv
gkRpl$Ainv init 2
gkRpl$Atrsp = kRpl$Atrsp * (abs((gkRpl$Ainv*2)-2)-1) ; invert transposition factor, play sound backwards


gkRpl$Afno1,ihRpl$Afno1 FLcount "First Sound", 1, 14,  1, 2, 1,         90, 20, iGr1_knobx1+96, iGr1_knoby1+20, -1, -1
gkRpl$Afno2,ihRpl$Afno2 FLcount "Last Sound", 1, 14,  1, 2, 1,         90, 20, iGr1_knobx1+215, iGr1_knoby1+20, -1, -1
gkRpl$Apoly,ihRpl$Apoly FLcount "Polyphony", 1, 20,  1, 2, 1,         90, 20, iGr1_knobx1+334, iGr1_knoby1+20, -1, -1
                        FLsetAlign 2, ihRpl$Afno1
                        FLsetAlign 2, ihRpl$Afno2
                        FLsetAlign 2, ihRpl$Apoly

gks$Abypas = 0 ; bypass off random selection of sounds, instr 312 pp.
ihRpl$Atext1 FLbox "selection of the", 1, 1, 10,  120, 20, iGr1_knobx1+96,  iGr1_valy1
gkRpl$Ashrt,ihRpl$Ashrt FLbutton "shortest",   1, 0,  2,   70, 20, iGr1_knobx1+215, iGr1_valy1, -1, -1
ihRpl$Atext2 FLbox "sounds", 1, 1, 10,   50, 20, iGr1_knobx1+290, iGr1_valy1
                        FLsetAlign 1, ihRpl$Ashrt
                        FLsetBox 2, ihRpl$Ashrt

                        FLsetVal_i $B, ihRpl$Afno1
                        FLsetVal_i $C, ihRpl$Afno2
                        FLsetVal_i 4, ihRpl$Apoly

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0

ihRpl$AtextTr FLbox "semitone transpose", 1, 1, 10, 100, 15, iGr1_knobx1, iGr1_banky1-15
gkRpl$Abtsp,ihRpl$Abtsp FLbutBank 2, 15, 1, 424, 10, iGr1_knobx1, iGr1_banky1, -105, -1
gkRpl$Abtsp init 7 ; init to transposition factor 1
kRpl$Apitch table gkRpl$Abtsp + 5, 150
gkRpl$Atrspo = gkRpl$Atrsp*kRpl$Apitch ; playback ratio, transposition factor

                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0
iRpFMknoby = iGr1_knoby2-11
kRpl$Amwav,ihRpl$Amwav FLbutBank 2, 1, 4,   40, 76, iGr1_knobx1, iRpFMknoby+23, -105, -1
gkRpl$Amwav = kRpl$Amwav+91 ; wave select for FM
gkRpl$Amwav = (gkRpl$Amwav == 0 ? 93 : gkRpl$Amwav) ; set to 93 (sine) if not set otherwise

                        FLlabel   -1
                        FLlabel   10, 1, 4, 0, 0, 0
ihRpl$Atext3 FLbox "Mod Wave",   1, 1, 10, 60, 20, iGr1_knobx1,    iRpFMknoby
ihRpl$Atext4 FLbox "saw",   1, 1, 10, 30, 20, iGr1_knobx1+40, iRpFMknoby+23
ihRpl$Atext5 FLbox "tri ",   1, 1, 10, 30, 20, iGr1_knobx1+40, iRpFMknoby+42
ihRpl$Atext6 FLbox "sin",   1, 1, 10, 30, 20, iGr1_knobx1+40, iRpFMknoby+61
ihRpl$Atext7 FLbox "sqr",   1, 1, 10, 30, 20, iGr1_knobx1+40, iRpFMknoby+80
       
                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0
gkRpl$Afm,ihRpl$Afm FLbutton "FM on/off",     1, 0, 2, 170, 20, iGr1_knobx1, iRpFMknoby+110, -105
                        FLsetAlign 1, ihRpl$Afm
                        FLsetBox 2, ihRpl$Afm

ihRpl$AmdxV FLvalue " ", 40, 15, iGr1_knobx1+130,    iRpFMknoby+30
ihRpl$AmfqV FLvalue " ", 40, 15, iGr1_knobx1+130,    iRpFMknoby+82
kRpl$Amdx,ihRpl$Amdx FLknob "FM index", 0.01, 2,    -1, 1, ihRpl$AmdxV,  40, iGr1_knobx1+90, iRpFMknoby+15
gkRpl$Amdx = (kRpl$Amdx-0.01) ; FM index, the -0.01 is to allow for the knob to have an exponential behaviour, and still have a minimum value of 0
gkRpl$Amfq,ihRpl$Amfq FLknob "Mod Freq", 0.01, 6000, -1, 1, ihRpl$AmfqV,  40, iGr1_knobx1+90, iRpFMknoby+67
                        FLsetVal_i $D, ihRpl$Amdx
                        FLsetVal_i $E, ihRpl$Amfq
                        FLsetAlign 6, ihRpl$Amdx
                        FLsetAlign 6, ihRpl$Amfq

gkRpl$AmdxS,ihRpl$AmdxS FLtext "Indx_start_x", 0, 5, 0.1, 1,       50, 20, iGr1_knobx1+200,    iRpFMknoby+15
gkRpl$AmdxT,ihRpl$AmdxT FLtext "Indx_thru_x", 0, 5, 0.1, 1,       50, 20, iGr1_knobx1+287,    iRpFMknoby+15
gkRpl$AmdxE,ihRpl$AmdxE FLtext "Indx_end_x", 0, 5, 0.1, 1,       50, 20, iGr1_knobx1+374,    iRpFMknoby+15
gkRpl$AmdxP,ihRpl$AmdxP FLslider        "Thru point", 0, 1, 0, 1, -1,    224, 15, iGr1_knobx1+200,    iRpFMknoby+50

gkRpl$AmfqS,ihRpl$AmfqS FLtext "Freq_start_x", 0, 5, 0.1, 1,       50, 20, iGr1_knobx1+200,    iRpFMknoby+82
gkRpl$AmfqT,ihRpl$AmfqT FLtext "Freq_thru_x",  0, 5, 0.1, 1,       50, 20, iGr1_knobx1+287,    iRpFMknoby+82
gkRpl$AmfqE,ihRpl$AmfqE FLtext "Freq_end_x", 0, 5, 0.1, 1,       50, 20, iGr1_knobx1+374,    iRpFMknoby+82
gkRpl$AmfqP,ihRpl$AmfqP FLslider        "Thru point", 0, 1, 0, 1, -1,    224, 15, iGr1_knobx1+200,    iRpFMknoby+117

                        FLsetVal_i $F, ihRpl$AmdxS
                        FLsetVal_i $G, ihRpl$AmdxT
                        FLsetVal_i $H, ihRpl$AmdxE
                        FLsetVal_i $I, ihRpl$AmdxP
                        FLsetVal_i $J, ihRpl$AmfqS
                        FLsetVal_i $K, ihRpl$AmfqT
                        FLsetVal_i $L, ihRpl$AmfqE
                        FLsetVal_i $M, ihRpl$AmfqP
                        FLsetAlign 2, ihRpl$AmdxS
                        FLsetAlign 2, ihRpl$AmdxT
                        FLsetAlign 2, ihRpl$AmdxE
                        FLsetAlign 2, ihRpl$AmdxP
                        FLsetAlign 2, ihRpl$AmfqS
                        FLsetAlign 2, ihRpl$AmfqT
                        FLsetAlign 2, ihRpl$AmfqE
                        FLsetAlign 2, ihRpl$AmfqP

; SV filter
ihRpl$ASvTxt FLbox "SV Filter", 1, 1, 10,  70, 20, iGr1_knobx1, iGr1_knoby3
gkRpl$ASvMd,ihRpl$ASvMd FLbutBank 2, 4, 1, 160, 18, iGr1_knobx1+90, iGr1_knoby3, -105, -1
ihRpl$ASvTxt2 FLbox "bypass", 1, 1, 10,  40, 15, iGr1_knobx1+90, iGr1_knoby3+18
ihRpl$ASvTxt2 FLbox "lo", 1, 1, 10,  40, 15, iGr1_knobx1+130, iGr1_knoby3+18
ihRpl$ASvTxt2 FLbox "band", 1, 1, 10,  40, 15, iGr1_knobx1+170, iGr1_knoby3+18
ihRpl$ASvTxt2 FLbox "hi", 1, 1, 10,  40, 15, iGr1_knobx1+210, iGr1_knoby3+18
gkRpl$ASvCf,ihRpl$ASvCf FLtext "Cutoff", 20, 6000, 20, 1,  50, 20, iGr1_knobx1+290, iGr1_knoby3
gkRpl$ASvQ,ihRpl$ASvQ FLtext "Q", 4, 100, 1, 1,     50, 20, iGr1_knobx1+374, iGr1_knoby3
;gkRpl$ASvQ = gkRpl$ASvQ1 * gkRpl$ASvCf * 0.1
                        FLsetVal_i 1000, ihRpl$ASvCf
                        FLsetVal_i 5, ihRpl$ASvQ
                        FLsetAlign 2, ihRpl$ASvMd
                        FLsetAlign 4, ihRpl$ASvCf
                        FLsetAlign 4, ihRpl$ASvQ

#

#define GrainModule(A) #
;argument : module number
ihGrn$AgrfqV FLvalue " ", 40, 17, iGr1_knobx3, iGr1_valy1
ihGrn$AoctV FLvalue " ", 40, 17, iGr1_knobx5-20, iGr1_valy1
ihGrn$AtrspV FLvalue " ", 40, 17, iGr1_knobx7-20, iGr1_valy1
ihGrn$AgliV FLvalue " ", 40, 17, iGr1_knobx9-20, iGr1_valy1

gkGrn$Asel,ihGrn$Asel FLcount "input sound no.", 0, 14, 1, 2,   1, 80, 20, iGr1_knobx1, iGr1_valy1-35, -1, -1
gkGrn$Agrfq,ihGrn$Agrfq FLknob "GrainFreq",      1, 1500, -1, 1, ihGrn$AgrfqV,  iGr1_knobsize, iGr1_knobx3, iGr1_knoby1
gkGrn$Aoct,ihGrn$Aoct FLknob "Octaviation",    0,    5, 0, 1, ihGrn$AoctV,   iGr1_knobsize, iGr1_knobx5-20, iGr1_knoby1

kGrn$Atrsp,ihGrn$Atrsp FLknob "Transp",    0,   2, 0, 1, ihGrn$AtrspV,  iGr1_knobsize, iGr1_knobx7-20, iGr1_knoby1
gkGrn$Ainv,ihGrn$Ainv FLbutton "inv",   1, 0,  2,    30, 15,        iGr1_knobx7+17, iGr1_knoby1, -1, -1
gkGrn$Ainv init 2
gkGrn$Atrsp = kGrn$Atrsp * (abs((gkGrn$Ainv*2)-2)-1) ; invert transposition factor, play sound backwards

kGrn$Agli,ihGrn$Agli FLknob "Gliss",    0,   2, 0, 1, ihGrn$AgliV,   iGr1_knobsize, iGr1_knobx9-20, iGr1_knoby1
gkGrn$Aginv,ihGrn$Aginv FLbutton "inv",   1, 0,  2,    30, 15,       iGr1_knobx9+17, iGr1_knoby1, -1, -1
gkGrn$Aginv init 2
gkGrn$Agli = kGrn$Agli * (abs((gkGrn$Aginv*2)-2)-1) ; invert transposition factor, play sound backwards

                        FLsetVal_i $A, ihGrn$Asel
                        FLsetVal_i 33, ihGrn$Agrfq
                        FLsetVal_i 0, ihGrn$Aoct
                        FLsetVal_i 1, ihGrn$Atrsp
                        FLsetVal_i 0, ihGrn$Agli
                        FLsetAlign 3, ihGrn$Ainv
                        FLsetAlign 3, ihGrn$Aginv

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0
ihGrn$AtextTr FLbox "semitone transpose", 1, 1, 10, 100, 15, iGr1_knobx1, iGr1_banky1-15
gkGrn$Abtsp,ihGrn$Abtsp FLbutBank 2, 15, 1,  424, 10, iGr1_knobx1, iGr1_banky1, -105, -1
gkGrn$Abtsp init 7 ; init to transposition factor 1
kGrn$Abtsp table gkGrn$Abtsp + 5, 150
gkGrn$AformT = gkGrn$Atrsp*kGrn$Abtsp ; playback ratio, transposition factor

; update transpose parameter only if GUI has been used this k-cycle, otherwise let old value pass thru
; this is useful when using an external midi faderbox to change parameters,
; without it, the GUI would always overrule the midi ctrl,
; because of the table lookup in the transpose parameter
gkGrn$Aform init 1
gkGrn$AformC1 init 0.1
gkGrn$Aform = (gkGrn$AformC1 == gkGrn$AformT ? gkGrn$Aform : gkGrn$AformT )
gkGrn$AformC1 = gkGrn$AformT

ihGrn$AbwV FLvalue " ", 40, 17, iGr1_knobx1, iGr1_valy2
ihGrn$ArisV FLvalue " ", 40, 17, iGr1_knobx2, iGr1_valy2
ihGrn$AdurV FLvalue " ", 40, 17, iGr1_knobx3, iGr1_valy2
ihGrn$AdecV FLvalue " ", 40, 17, iGr1_knobx4, iGr1_valy2

gkGrn$Abw,ihGrn$Abw FLknob "Bandwidth",      0.001, 1, -1, 1, ihGrn$AbwV,   iGr1_knobsize, iGr1_knobx1, iGr1_knoby2
gkGrn$Aris,ihGrn$Aris FLknob "Rise",    0.001, 1, -1, 1, ihGrn$ArisV,  iGr1_knobsize, iGr1_knobx2, iGr1_knoby2
gkGrn$Adur,ihGrn$Adur FLknob "Duration",    0.001, 8, -1, 1, ihGrn$AdurV,  iGr1_knobsize, iGr1_knobx3, iGr1_knoby2
gkGrn$Adec,ihGrn$Adec FLknob "Dec",    0.001, 1, -1, 1, ihGrn$AdecV,  iGr1_knobsize, iGr1_knobx4, iGr1_knoby2

                        FLsetVal_i 0.01, ihGrn$Abw
                        FLsetVal_i 0.2, ihGrn$Aris
                        FLsetVal_i 6.5, ihGrn$Adur
                        FLsetVal_i 0.2, ihGrn$Adec

gkGrn$AmTim,ihGrn$AmTim FLbutton "Man. TimPoint", 1, 0, 2,   90, 20, iGr1_knobx1, iGr1_slidy1, -105 , 4, 0, -1
ihGrn$AmPhsV FLvalue " ",   40, 15, iGr1_knobx1 + 384, iGr1_slidy1
gkGrn$AmPhs,ihGrn$AmPhs FLslider        "Man. Time pointer",   0, 1, 0, 1, ihGrn$AmPhsV, 280, 15, iGr1_knobx1 + 100, iGr1_slidy1

ihGrn$AlfqV FLvalue " ", 40, 17, iGr1_knobx6, iGr1_valy2
ihGrn$AlfaV FLvalue " ", 40, 17, iGr1_knobx7, iGr1_valy2
ihGrn$ArndaV FLvalue " ", 40, 17, iGr1_knobx8, iGr1_valy2
ihGrn$AtratV FLvalue " ", 40, 17, iGr1_knobx9, iGr1_valy2

gkGrn$Alfq,ihGrn$Alfq FLknob "Lfo Frq",      0.001, 10, -1, 1, ihGrn$AlfqV,  iGr1_knobsize, iGr1_knobx6, iGr1_knoby2
kGrn$AlfA,ihGrn$Alfa FLknob "Lfo Amt",    0.001, 3,  -1, 1, ihGrn$AlfaV,  iGr1_knobsize, iGr1_knobx7, iGr1_knoby2
kGrn$ArndA,ihGrn$Arnda FLknob "RndAmt",    0.001, 3,  -1, 1, ihGrn$ArndaV,  iGr1_knobsize, iGr1_knobx8, iGr1_knoby2
gkGrn$Atrat,ihGrn$Atrat FLknob "TimRatio",    -3, 3, 0, 1, ihGrn$AtratV,  iGr1_knobsize, iGr1_knobx9, iGr1_knoby2
gkGrn$AlfA = kGrn$AlfA * 0.1
gkGrn$ArndA = (kGrn$ArndA-0.001) * 0.1

                        FLsetVal_i 0.15, ihGrn$Alfq
                        FLsetVal_i 0.08, ihGrn$Alfa
                        FLsetVal_i 0.001, ihGrn$Arnda
                        FLsetVal_i 1, ihGrn$Atrat
#


                        FLgroup "Rplay1   ",  455, 440, 540,  45
        $RplayModule.(1'1'4'0.15'250'1'0.1'0.3'0.2'1'1'0.5'0.5)
        $EfxSend.(Rplay1'557'370'1'0'0'0'0'0'0.2'0'0)
                        FLgroupEnd
                        FLgroup "Rplay2   ",  455, 440, 540,  45
        $RplayModule.(2'5'7'0.30'850'0'1'0.3'0.6'1'1'0.5'0.5)
        $EfxSend.(Rplay2'557'370'1'0'0'0.15'0'0'0'0'0.3)
                        FLgroupEnd
                        FLgroup "Grain1   ",  455, 440, 540,  45
        $GrainModule.(1)
        $EfxSend.(Grain1'557'370'1'0'0'0'0'0'0'0.45'0)
                        FLgroupEnd
                        FLgroup "Grain2   ",  455, 440, 540,  45
        $GrainModule.(2)
        $EfxSend.(Grain2'557'370'1'0'0'0'0'0'0'0.4'0.4)
                        FLgroupEnd
                        FLgroup "Grain3   ",  455, 440, 540,  45
        $GrainModule.(3)
        $EfxSend.(Grain3'557'370'1'0'0'0'0.1'0'0'0'0.20)
                        FLgroupEnd
                        FLgroup "Grain4   ",  455, 440, 540,  45
        $GrainModule.(4)
        $EfxSend.(Grain4'557'370'1'0'0'0'0'0'0'0'0.15)
                        FLgroupEnd

                        FLgroup "RAGrain",  455, 440, 540,  45
ihRAGtrspV FLvalue " ", 40, 17, iGr1_knobx5, iGr1_valy1
ihRAGrpchV FLvalue " ", 40, 17, iGr1_knobx7, iGr1_valy1

gkRAGsel,ihRAGsel FLcount "input sound no.",  1, 14, 1, 2,   1, 80, 20, iGr1_knobx1, iGr1_valy1-35, -1, -1
kRAGtrsp,ihRAGtrsp FLknob "Transp",    0,   2, 0, 1, ihRAGtrspV,  iGr1_knobsize, iGr1_knobx5, iGr1_knoby1
gkRAGinv,ihRAGinv FLbutton "inv",   1, 0,  2,    30, 15,     iGr1_knobx5+37, iGr1_knoby1, -1, -1
gkRAGinv init 2
gkRAGtrsp = kRAGtrsp * (abs((gkRAGinv*2)-2)-1) ; invert transposition factor, play sound backwards

kRAGrpch,ihRAGrpch FLknob "R.pitch",    0,   1, 0, 1, ihRAGrpchV,  iGr1_knobsize, iGr1_knobx7, iGr1_knoby1
gkRAGrpinv,ihRAGrpinv FLbutton "inv",   1, 0,  2,    30, 15,     iGr1_knobx7+37, iGr1_knoby1, -1, -1
gkRAGrpinv init 2
gkRAGrpch = kRAGrpch * (abs((gkRAGrpinv*2)-2)-1) ; invert transposition factor, play sound backwards

                        FLsetVal_i 1, ihRAGsel
                        FLsetVal_i 1, ihRAGtrsp
                        FLsetVal_i 0, ihRAGrpch
                        FLsetAlign 3, ihRAGinv
                        FLsetAlign 3, ihRAGrpinv

                        FLlabel   -1
                        FLlabel   10, 1, 3, 0, 0, 0
ihRAGtextTr FLbox "semitone transpose", 1, 1, 10, 100, 15, iGr1_knobx1, iGr1_banky1-15
gkRAGbtsp,ihRAGbtsp FLbutBank 2, 15, 1, 424, 10, iGr1_knobx1, iGr1_banky1, -105, -1
gkRAGbtsp init 7 ; init to transposition factor 1
kRAGbtsp table gkRAGbtsp + 5, 150
gkRAGtrspo = gkRAGtrsp*kRAGbtsp ; playback ratio, transposition factor

ihRAGrisV FLvalue " ", 40, 17, iGr1_knobx1, iGr1_valy2+15
ihRAGdurV FLvalue " ", 40, 17, iGr1_knobx2, iGr1_valy2+15
ihRAGdecV FLvalue " ", 40, 17, iGr1_knobx3, iGr1_valy2+15
ihRAGrdurV FLvalue " ", 40, 17, iGr1_knobx4, iGr1_valy2+15

ihRAGtextEnv FLbox "Duration / Envelope", 5, 1, 10, 190, 15, iGr1_knobx1, iGr1_knoby2
gkRAGris,ihRAGris FLknob "Rise",    0.01, 1, -1, 1, ihRAGrisV,  iGr1_knobsize, iGr1_knobx1, iGr1_knoby2+15
gkRAGdur,ihRAGdur FLknob "Duration",    0.1, 5, -1, 1, ihRAGdurV,  iGr1_knobsize, iGr1_knobx2, iGr1_knoby2+15
gkRAGdec,ihRAGdec FLknob "Dec",    0.01, 1, -1, 1, ihRAGdecV,  iGr1_knobsize, iGr1_knobx3, iGr1_knoby2+15
gkRAGrdur,ihRAGrdur FLknob "R.dur",    0.001, 1, -1, 1, ihRAGrdurV, iGr1_knobsize, iGr1_knobx4, iGr1_knoby2+15

                        FLsetVal_i 0.2, ihRAGris
                        FLsetVal_i 0.2, ihRAGdur
                        FLsetVal_i 0.35, ihRAGdec
                        FLsetVal_i 0.001, ihRAGrdur

gkRAGmTim,ihRAGmTim FLbutton "Man. TimPoint", 1, 0, 2, 90, 20, iGr1_knobx1, iGr1_slidy1+15, -105 , 4, 0, -1
ihRAGmPhsV FLvalue " ", 40, 15, iGr1_knobx1 + 384, iGr1_slidy1+15
gkRAGmPhs,ihRAGmPhs FLslider        "Man. Time pointer",   0, 1, 0, 1, ihRAGmPhsV, 280, 15, iGr1_knobx1 + 100, iGr1_slidy1+15

ihRAGlfqV FLvalue " ", 40, 17, iGr1_knobx6, iGr1_valy2+15
ihRAGlfaV FLvalue " ", 40, 17, iGr1_knobx7, iGr1_valy2+15
ihRAGrphsV FLvalue " ", 40, 17, iGr1_knobx8, iGr1_valy2+15
ihRAGtratV FLvalue " ", 40, 17, iGr1_knobx9, iGr1_valy2+15

ihRAGtextEnv FLbox "StartPoint / Phase", 5, 1, 10, 190, 15, iGr1_knobx6, iGr1_knoby2
gkRAGlfq,ihRAGlfq FLknob "Lfo Frq",      0.001, 10, -1, 1, ihRAGlfqV,  iGr1_knobsize, iGr1_knobx6, iGr1_knoby2+15
gkRAGlfA,ihRAGlfa FLknob "Lfo Amt",    0.001, 3,  -1, 1, ihRAGlfaV,  iGr1_knobsize, iGr1_knobx7, iGr1_knoby2+15
gkRAGrphs,ihRAGrphs FLknob "RndAmt",    0.001, 3,  -1, 1, ihRAGrphsV, iGr1_knobsize, iGr1_knobx8, iGr1_knoby2+15
gkRAGtrat,ihRAGtrat FLknob "TimRatio",    -3, 3, 0, 1, ihRAGtratV, iGr1_knobsize, iGr1_knobx9, iGr1_knoby2+15

                        FLsetVal_i 0.2, ihRAGlfq
                        FLsetVal_i 0.1, ihRAGlfa
                        FLsetVal_i 0.001, ihRAGrphs
                        FLsetVal_i 1, ihRAGtrat

        $EfxSend.(RAG'557'370'1'0'0'0'0'0'0'0'0.15)
                        FLgroupEnd


                        FLgroup "Pad ",  455, 440, 540,  45
                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

gkt701,ih701 FLbutton "E'",     1, 0, 2,        50, 20, iGr1_knobx1,     iGr1_knoby2, -105 , 2, 0, -1
gkt702,ih702 FLbutton "E",     1, 0, 2,        50, 20, iGr1_knobx1+50,  iGr1_knoby2, -105 , 2, 0, -1
gkt703,ih703 FLbutton "e",     1, 0, 2,        50, 20, iGr1_knobx1+100, iGr1_knoby2, -105 , 2, 0, -1
gkt704,ih704 FLbutton "f#",     1, 0, 2,        50, 20, iGr1_knobx1+150, iGr1_knoby2, -105 , 2, 0, -1
gkt705,ih705 FLbutton "g#",     1, 0, 2,        50, 20, iGr1_knobx1+200, iGr1_knoby2, -105 , 2, 0, -1
gkt706,ih706 FLbutton "a#",     1, 0, 2,        50, 20, iGr1_knobx1+250, iGr1_knoby2, -105 , 2, 0, -1
gkt707,ih707 FLbutton "h",     1, 0, 2,        50, 20, iGr1_knobx1+300, iGr1_knoby2, -105 , 2, 0, -1

        $EfxSend.(Pad'557'370'1'0'0'0.2'0'0'0.2'0'0.2)
                        FLgroupEnd
                        FLgroup "DrumLoop",  455, 440, 540,  45
                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

gkDrmLopN,ihDrmLopN FLcount "Loop no", 1, 4, 1, 2, 1, 120, 20,     iGr1_knobx1, iGr1_knoby1, -1, -1
                        FLsetVal_i 1, ihDrmLopN
                        FLsetAlign 5, ihDrmLopN

ihDrmLopTpoBx FLbox "pitch/tempo", 1, 1, 10, 60, 15,     iGr1_knobx1, iGr1_valy1-25
gkDrmLopTpo,ihDrmLopTpo FLbutBank 2, 1, 5, 50, 80,     iGr1_knobx1, iGr1_valy1-10, -105, -1
gkDrmLopTpo init 2 ; drumloop speed factor initialize
gkdrumlop_ptch table gkDrmLopTpo, 180 ; drumloop speed/transposition factor

ihDLbbcutbox FLbox "BBCut parameters", 1, 1, 10, 120, 20,    iGr1_knobx6, iGr1_knoby1
gkDLsubdiv,ihDLsubdiv FLcount "subdiv", 1, 16,  1, 4,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+20, -1, -1
gkDLbarlen,ihDLbarlen FLcount "barlength", 1, 16,  1, 4,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+40, -1, -1
gkDLphrbar,ihDLphrbar FLcount "phrasebar", 1, 16,  1, 4,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+60, -1, -1
gkDLnumrep,ihDLnumrep FLcount "num rep", 1, 16,  1, 4,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+80, -1, -1
gkDLstuspd,ihDLstuspd FLcount "stutr speed", 1, 16,  1, 4,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+100, -1, -1
gkDLsturnd,ihDLsturnd FLcount "stutr chance", 0, 100, 1, 10, 1, 120, 20,  iGr1_knobx6, iGr1_knoby1+120, -1, -1
gkDLenv,ihenv FLcount "envelope", 0, 1,   1, 1,  1, 120, 20,  iGr1_knobx6, iGr1_knoby1+140, -1, -1

                        FLsetVal_i 8, ihDLsubdiv
                        FLsetVal_i 4, ihDLbarlen
                        FLsetVal_i 2, ihDLphrbar
                        FLsetVal_i 2, ihDLnumrep
                        FLsetVal_i 4, ihDLstuspd
                        FLsetVal_i 50, ihDLsturnd
                        FLsetVal_i 1, ihenv

                        FLsetAlign 4, ihDLsubdiv
                        FLsetAlign 4, ihDLbarlen
                        FLsetAlign 4, ihDLphrbar
                        FLsetAlign 4, ihDLnumrep
                        FLsetAlign 4, ihDLstuspd
                        FLsetAlign 4, ihDLsturnd
                        FLsetAlign 4, ihenv


ihDLbbmixV FLvalue " ", 40, 15, iGr1_knobx1+300, iGr1_slidy1-45
gkDLbbmix,ihDLbbmix FLslider        "Clean/BBCut balance", 0, 1, 0, 1, ihDLbbmixV, 290, 15, iGr1_knobx1, iGr1_slidy1-45
                        FLsetVal_i 0, ihDLbbmix
                        FLsetAlign 3, ihDLbbmix


ihDrmLopAmV FLvalue " ", 40, 15, iGr1_knobx1+300, iGr1_slidy1
gkDrmLopAm,ihDrmLopAm FLslider        "DrumLoop Amplitude", 0, 4, 0, 1, ihDrmLopAmV, 290, 15, iGr1_knobx1, iGr1_slidy1
                        FLsetVal_i 1, ihDrmLopAm
                        FLsetAlign 3, ihDrmLopAm

;ihBasLopAmV FLvalue " ",   40, 15, iGr1_knobx1+300,  iGr1_slidy2
;gkBasLopAm,ihBasLopAm FLslider        "BassLoop Amplitude", 0,  4, 0, 1, ihBasLopAmV, 290, 15, iGr1_knobx1, iGr1_slidy2
; FLsetVal_i 0, ihBasLopAm
; FLsetAlign 3, ihBasLopAm

        $EfxSend.(Loop'557'370'1'0'0'0'0'0'0'0'0)
                        FLgroupEnd
                        FLtabsEnd

;***************************************
ihbxSoundList FLbox "Sound List", 5, 1, 12, 500, 205, 503, 500
                        FLsetAlign 2, ihbxSoundList
                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

isndlstX1 = 517
isndlstX2 = isndlstX1 + 34
isndlstX3 = isndlstX2 + 34
isndlstX4 = isndlstX3 + 34
isndlstX5 = isndlstX4 + 34
isndlstX6 = isndlstX5 + 34
isndlstX7 = isndlstX6 + 34
isndlstX8 = isndlstX7 + 34
isndlstX9 = isndlstX8 + 34
isndlstX10 = isndlstX9 + 34
isndlstX11 = isndlstX10 + 34
isndlstX12 = isndlstX11 + 34
isndlstX13 = isndlstX12 + 34
isndlstX14 = isndlstX13 + 34

isndlstY1 = 520
isndlstY2 = isndlstY1 + 42
isndlstY3 = isndlstY2 + 40
isndlstY4 = isndlstY3 + 42
isndlstY5 = isndlstY4 + 42


ihsndlstxt1 FLbox "Sound Length", 1, 1, 10, 476, 20, isndlstX1, isndlstY1-19
gihsnd1 FLvalue " ", 32, 20, isndlstX1, isndlstY1
gihsnd2 FLvalue " ", 32, 20, isndlstX2, isndlstY1
gihsnd3 FLvalue " ", 32, 20, isndlstX3, isndlstY1
gihsnd4 FLvalue " ", 32, 20, isndlstX4, isndlstY1
gihsnd5 FLvalue " ", 32, 20, isndlstX5, isndlstY1
gihsnd6 FLvalue " ", 32, 20, isndlstX6, isndlstY1
gihsnd7 FLvalue " ", 32, 20, isndlstX7, isndlstY1
gihsnd8 FLvalue " ", 32, 20, isndlstX8, isndlstY1
gihsnd9 FLvalue " ", 32, 20, isndlstX9, isndlstY1
gihsnd10 FLvalue " ", 32, 20, isndlstX10, isndlstY1
gihsnd11 FLvalue " ", 32, 20, isndlstX11, isndlstY1
gihsnd12 FLvalue " ", 32, 20, isndlstX12, isndlstY1
gihsnd13 FLvalue " ", 32, 20, isndlstX13, isndlstY1
gihsnd14 FLvalue " ", 32, 20, isndlstX14, isndlstY1


ihsndlstxt2 FLbox "Test Play Sounds", 1, 1, 10, 476, 20, isndlstX1, isndlstY2-19
gkply1,ihply1 FLbutton "1",     1, 0, 11,        32, 17,  isndlstX1, isndlstY2, 105 , 311, 0, 5.944, 1
gkply2,ihply2 FLbutton "2",     1, 0, 11,        32, 17,  isndlstX2, isndlstY2, 105 , 311, 0, 5.944, 2
gkply3,ihply3 FLbutton "3",     1, 0, 11,        32, 17,  isndlstX3, isndlstY2, 105 , 311, 0, 5.944, 3
gkply4,ihply4 FLbutton "4",     1, 0, 11,        32, 17,  isndlstX4, isndlstY2, 105 , 311, 0, 5.944, 4
gkply5,ihply5 FLbutton "5",     1, 0, 11,        32, 17,  isndlstX5, isndlstY2, 105 , 311, 0, 5.944, 5
gkply6,ihply6 FLbutton "6",     1, 0, 11,        32, 17,  isndlstX6, isndlstY2, 105 , 311, 0, 5.944, 6
gkply7,ihply7 FLbutton "7",     1, 0, 11,        32, 17,  isndlstX7, isndlstY2, 105 , 311, 0, 5.944, 7
gkply8,ihply8 FLbutton "8",     1, 0, 11,        32, 17,  isndlstX8, isndlstY2, 105 , 311, 0, 5.944, 8
gkply9,ihply9 FLbutton "9",     1, 0, 11,        32, 17,  isndlstX9, isndlstY2, 105 , 311, 0, 5.944, 9
gkply10,ihply10 FLbutton "10",    1, 0, 11,        32, 17,  isndlstX10, isndlstY2, 105 , 311, 0, 5.944, 10
gkply11,ihply11 FLbutton "11",    1, 0, 11,        32, 17,  isndlstX11, isndlstY2, 105 , 311, 0, 5.944, 11
gkply12,ihply12 FLbutton "12",    1, 0, 11,        32, 17,  isndlstX12, isndlstY2, 105 , 311, 0, 5.944, 12
gkply13,ihply13 FLbutton "13",    1, 0, 11,        32, 17,  isndlstX13, isndlstY2, 105 , 311, 0, 5.944, 13
gkply14,ihply14 FLbutton "14",    1, 0, 11,        32, 17,  isndlstX14, isndlstY2, 105 , 311, 0, 5.944, 14

ihsndlstxt3 FLbox "Save Sounds (record protect)", 1, 1, 10, 476, 20, isndlstX1, isndlstY3-19
gksav1,ihsav1 FLbutton "1",      1, 0, 2,       32, 20, isndlstX1, isndlstY3, -105 , 2, 0, -1
gksav2,ihsav2 FLbutton "2",      2, 0, 2,       32, 20, isndlstX2, isndlstY3, -105 , 2, 0, -1
gksav3,ihsav3 FLbutton "3",      3, 0, 2,       32, 20, isndlstX3, isndlstY3, -105 , 2, 0, -1
gksav4,ihsav4 FLbutton "4",      4, 0, 2,       32, 20, isndlstX4, isndlstY3, -105 , 2, 0, -1
gksav5,ihsav5 FLbutton "5",      5, 0, 2,       32, 20, isndlstX5, isndlstY3, -105 , 2, 0, -1
gksav6,ihsav6 FLbutton "6",      6, 0, 2,       32, 20, isndlstX6, isndlstY3, -105 , 2, 0, -1
gksav7,ihsav7 FLbutton "7",      7, 0, 2,       32, 20, isndlstX7, isndlstY3, -105 , 2, 0, -1
gksav8,ihsav8 FLbutton "8",      8, 0, 2,       32, 20, isndlstX8, isndlstY3, -105 , 2, 0, -1
gksav9,ihsav9 FLbutton "9",      9, 0, 2,       32, 20, isndlstX9, isndlstY3, -105 , 2, 0, -1
gksav10,ihsav10 FLbutton "10",    10, 0, 2,       32, 20, isndlstX10, isndlstY3, -105 , 2, 0, -1
gksav11,ihsav11 FLbutton "11",    11, 0, 2,       32, 20, isndlstX11, isndlstY3, -105 , 2, 0, -1
gksav12,ihsav12 FLbutton "12",    12, 0, 2,       32, 20, isndlstX12, isndlstY3, -105 , 2, 0, -1
gksav13,ihsav13 FLbutton "13",    13, 0, 2,       32, 20, isndlstX13, isndlstY3, -105 , 2, 0, -1
gksav14,ihsav14 FLbutton "14",    14, 0, 2,       32, 20, isndlstX14, isndlstY3, -105 , 2, 0, -1

ihsndlstxt4 FLbox "Hide Sounds (don't use)", 1, 1, 10, 476, 20, isndlstX1, isndlstY4-19
gkhide1,ihhide1 FLbutton "1",    1, 0, 2,       32, 20, isndlstX1, isndlstY4, -105 , 2, 0, -1
gkhide2,ihhide2 FLbutton "2",    2, 0, 2,       32, 20, isndlstX2, isndlstY4, -105 , 2, 0, -1
gkhide3,ihhide3 FLbutton "3",    3, 0, 2,       32, 20, isndlstX3, isndlstY4, -105 , 2, 0, -1
gkhide4,ihhide4 FLbutton "4",    4, 0, 2,       32, 20, isndlstX4, isndlstY4, -105 , 2, 0, -1
gkhide5,ihhide5 FLbutton "5",    5, 0, 2,       32, 20, isndlstX5, isndlstY4, -105 , 2, 0, -1
gkhide6,ihhide6 FLbutton "6",    6, 0, 2,       32, 20, isndlstX6, isndlstY4, -105 , 2, 0, -1
gkhide7,ihhide7 FLbutton "7",    7, 0, 2,       32, 20, isndlstX7, isndlstY4, -105 , 2, 0, -1
gkhide8,ihhide8 FLbutton "8",    8, 0, 2,       32, 20, isndlstX8, isndlstY4, -105 , 2, 0, -1
gkhide9,ihhide9 FLbutton "9",    9, 0, 2,       32, 20, isndlstX9, isndlstY4, -105 , 2, 0, -1
gkhide10,ihhide10 FLbutton "10",  10, 0, 2,       32, 20, isndlstX10, isndlstY4, -105 , 2, 0, -1
gkhide11,ihhide11 FLbutton "11",  11, 0, 2,       32, 20, isndlstX11, isndlstY4, -105 , 2, 0, -1
gkhide12,ihhide12 FLbutton "12",  12, 0, 2,       32, 20, isndlstX12, isndlstY4, -105 , 2, 0, -1
gkhide13,ihhide13 FLbutton "13",  13, 0, 2,       32, 20, isndlstX13, isndlstY4, -105 , 2, 0, -1
gkhide14,ihhide14 FLbutton "14",  14, 0, 2,       32, 20, isndlstX14, isndlstY4, -105 , 2, 0, -1

ihsndlstxt5 FLbox "Clear Sounds", 1, 1, 10, 476, 20, isndlstX1, isndlstY5-19
gkclear1,ihclear1 FLbutton "1",     1, 0, 11,        32, 17,  isndlstX1, isndlstY5, 105 , 201, 0, 0.1, 1
gkclear2,ihclear2 FLbutton "2",     1, 0, 11,        32, 17,  isndlstX2, isndlstY5, 105 , 201, 0, 0.1, 2
gkclear3,ihclear3 FLbutton "3",     1, 0, 11,        32, 17,  isndlstX3, isndlstY5, 105 , 201, 0, 0.1, 3
gkclear4,ihclear4 FLbutton "4",     1, 0, 11,        32, 17,  isndlstX4, isndlstY5, 105 , 201, 0, 0.1, 4
gkclear5,ihclear5 FLbutton "5",     1, 0, 11,        32, 17,  isndlstX5, isndlstY5, 105 , 201, 0, 0.1, 5
gkclear6,ihclear6 FLbutton "6",     1, 0, 11,        32, 17,  isndlstX6, isndlstY5, 105 , 201, 0, 0.1, 6
gkclear7,ihclear7 FLbutton "7",     1, 0, 11,        32, 17,  isndlstX7, isndlstY5, 105 , 201, 0, 0.1, 7
gkclear8,ihclear8 FLbutton "8",     1, 0, 11,        32, 17,  isndlstX8, isndlstY5, 105 , 201, 0, 0.1, 8
gkclear9,ihclear9 FLbutton "9",     1, 0, 11,        32, 17,  isndlstX9, isndlstY5, 105 , 201, 0, 0.1, 9
gkclear10,ihclear10 FLbutton "10",    1, 0, 11,        32, 17,  isndlstX10, isndlstY5, 105 , 201, 0, 0.1, 10
gkclear11,ihclear11 FLbutton "11",    1, 0, 11,        32, 17,  isndlstX11, isndlstY5, 105 , 201, 0, 0.1, 11
gkclear12,ihclear12 FLbutton "12",    1, 0, 11,        32, 17,  isndlstX12, isndlstY5, 105 , 201, 0, 0.1, 12
gkclear13,ihclear13 FLbutton "13",    1, 0, 11,        32, 17,  isndlstX13, isndlstY5, 105 , 201, 0, 0.1, 13
gkclear14,ihclear14 FLbutton "14",    1, 0, 11,        32, 17,  isndlstX14, isndlstY5, 105 , 201, 0, 0.1, 14


;***************************************
                        FLlabel -1
                        FLlabel   10, 1, 6, 0, 0, 0
ihbxMixer FLbox "Mixer", 5, 1, 12, 490, 325,   5, 380
                        FLsetAlign 2, ihbxMixer

                        FLtabs 486, 321,   7, 382

#define MixFader(A'B'C'D) #
imX$Aoffset = ($A > 5 ? 80*($A-6) : 80*($A-1) ) ; two rows of mixer modules, 5 in each row
imX$A =  12 + imX$Aoffset
imY$A = 420 + $B
ihbx$Cmix FLbox "$C", 5, 1, 10, 74, 130,  imX$A,    imY$A
                        FLsetAlign 2, ihbx$Cmix
gkbt$COn,ihbt$COn FLbutton "On", 1, 0, 2, 42,  20,  imX$A+9,  imY$A+4, -1, -1
                        FLsetAlign 1, ihbt$COn
gk$C_pan,ih$C_pan FLknob "Pan", 0, 1, 0, 3, -1, 20,       imX$A+20, imY$A+30
ihval$Camp FLvalue " ", 38,  15,  imX$A+11,  imY$A+110
gks$Camp,ihs$Camp FLknob          " ", 0, 2, 0, 1, ihval$Camp, 42,   imX$A+9,  imY$A+63
gks$CampD,gihs$CampD FLslider        " ", 0, 30000, 0, 2 , -1, 10, 121,  imX$A+55, imY$A+4
                        FLsetColor 80, 150, 50,  gihs$CampD
                        FLsetColor2 230, 50,  30,  gihs$CampD
                       
                        FLsetVal_i $D, ih$C_pan
                        FLsetVal_i 1, ihs$Camp
k_$Aoff = (gkbt$COn = 0 ? 1 : 0)
                        FLsetVal gkupdate1*k_$Aoff, 0, gihs$CampD ; reset VU when unit is turned off
#

                        FLgroup "Levels ",  475, 305, 10,  400

$MixFader.(1'0'Rplay1'0.35)
$MixFader.(2'0'Rplay2'0.75)
$MixFader.(3'0'Grain1'0.20)
$MixFader.(4'0'Grain2'0.80)
$MixFader.(5'0'Grain3'0.15)
$MixFader.(6'150'Grain4'0.85)
$MixFader.(7'150'RAG'0.3)
$MixFader.(8'150'Pad'0.6)
$MixFader.(9'150'PtSeq'0.5)
$MixFader.(10'150'Loop'0.5)

;Master Volume and VU:
iMstX = 412
iMstY = 570
ihbxMastermix FLbox "Master", 5, 1, 10, 74,  15,  iMstX,    iMstY-15
ihvalMasteramp FLvalue " ", 35,  15,  iMstX+3,  iMstY+110
gksMastamp,gihsMastamp FLknob        " ", 0, 2, 0, 2, ihvalMasteramp, 35,   iMstX+3,  iMstY+65
gksMLampD,gihsMLampD FLslider        " ", 0, 30000, 0, 2 , -1, 10, 121,  iMstX+42, iMstY+4
gksMRampD,gihsMRampD FLslider        " ", 0, 30000, 0, 2 , -1, 10, 121,  iMstX+55, iMstY+4
                        FLsetColor 80, 150, 50,   gihsMLampD
                        FLsetColor 80, 150, 50,   gihsMRampD
                        FLsetColor2 230, 50,  30,   gihsMLampD
                        FLsetColor2 230, 50,  30,   gihsMRampD
                        FLsetColor2 80, 20,  20,   gihsMastamp
                        FLsetVal_i 1, gihsMastamp

                        FLlabel -1
                        FLlabel   10, 1, 1, 0, 0, 0

iPreX = 417
iPreY = 420
gkPresN,ihPresN FLcount "Preset", 0, 50, 1, 2, 1,  70, 20, iPreX, iPreY,     -1, -1
                        FLsetAlign 2, ihPresN
gkPreStor,ihPreStor FLbutton "Store", 11, 0, 11,        70, 20, iPreX, iPreY+30,  0 , 270, 0, 0
gkPreRead,ihPreRead FLbutton "Recall", 11, 0, 11,        70, 20, iPreX, iPreY+50,  0 , 271, 0, 0
gkPreSav,ihPreSav FLbutton "SaveSet", 11, 0, 11,        70, 20, iPreX, iPreY+80,  0 , 272, 0, 0
gkPreOpn,ihPreOpn FLbutton "OpenSet", 11, 0, 11,        70, 20, iPreX, iPreY+100, 0 , 273, 0, 0

                        FLgroupEnd

; *************************
#define EfxFader(A'B) #
imX1 = 12
imY1 = 600
ihbx$Amix FLbox "$A", 5, 1, 10, 74, 100,  imX1,    imY1
                        FLsetAlign 2, ihbx$Amix
gkpan$A,ihpan$A FLknob "Pan", 0, 1, 0, 3, -1, 20,       imX1+20, imY1+4
ihval$Amix FLvalue " ", 38,  15,  imX1+11, imY1+80
gks$Aamp,ihs$Aamp FLknob          " ", 0, 2, 0, 1, ihval$Amix, 42,     imX1+9,  imY1+35
gks$AampD,gihs$AampD FLslider        " ", 0, 30000, 0, 2, -1, 10, 91,  imX1+55, imY1+4
                        FLsetColor 80, 150, 50,  gihs$AampD
                        FLsetColor2 230, 50,  30,  gihs$AampD
                        FLsetVal_i $B, ihpan$A
                        FLsetVal_i 1, ihs$Aamp
#

;four buttons side by side
iefxX1 = 92
iefxX2_4 = iefxX1 + 98
iefxX3_4 = iefxX2_4 + 98
iefxX4_4 = iefxX3_4 + 98

;five buttons side by side
iefxX2_5 = iefxX1 + 79
iefxX3_5 = iefxX2_5 + 79
iefxX4_5 = iefxX3_5 + 79
iefxX5_5 = iefxX4_5 + 79

;six buttons side by side
iefxX2_6 = iefxX1 + 66
iefxX3_6 = iefxX2_6 + 66
iefxX4_6 = iefxX3_6 + 66
iefxX5_6 = iefxX4_6 + 66
iefxX6_6 = iefxX5_6 + 66

;eight buttons side by side
iefxX2_8 = iefxX1 + 50
iefxX3_8 = iefxX2_8 + 50
iefxX4_8 = iefxX3_8 + 50
iefxX5_8 = iefxX4_8 + 50
iefxX6_8 = iefxX5_8 + 50
iefxX7_8 = iefxX6_8 + 50
iefxX8_8 = iefxX7_8 + 50

; Y - rows of buttons
iefxY1 = 420
iefxY1V = iefxY1 + 45
iefxY2 = iefxY1 + 90
iefxY2V = iefxY2 + 45

;efx send buttons
ifxknobsize = 40
ifxvaly1 = 680
ifxknoby1 = 625

                        FLgroup "RingMod",  475, 305, 10, 400
                        FLlabel   10, 1, 2, 0, 0, 0

$EfxFader.(RngMod'0.35)
ih1101 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1102 FLvalue " ", 40, 15, iefxX2_5, iefxY1V
ih1103 FLvalue " ", 40, 15, iefxX3_5, iefxY1V
ih1104 FLvalue " ", 40, 15, iefxX4_5, iefxY1V
ih1105 FLvalue " ", 40, 15, iefxX5_5, iefxY1V

gkfx_rm_mfrq,ih1151 FLknob "Mod Freq",    1, 5000, -1, 1, ih1101, 40, iefxX1,   iefxY1
gkfx_rm_mndx,ih1152 FLknob "Mod indx",    0, 1,     0, 1, ih1102, 40, iefxX2_5, iefxY1
gkfx_rm_lfrq,ih1153 FLknob "LFO Freq",    0.01, 20,-1, 1, ih1103, 40, iefxX3_5, iefxY1
gkfx_rm_lamt,ih1154 FLknob "LFO amt",    0, 2,     0, 1, ih1104, 40, iefxX4_5, iefxY1
gkfx_rm_afrq,ih1155 FLknob "Amp -> Freq",   -1, 3,     0, 1, ih1105, 40, iefxX5_5, iefxY1

                        FLsetAlign 2, ih1151
                        FLsetAlign 2, ih1152
                        FLsetAlign 2, ih1153
                        FLsetAlign 2, ih1154
                        FLsetAlign 2, ih1155
                        FLsetVal_i 20, ih1151
                        FLsetVal_i 1, ih1152
                        FLsetVal_i 1, ih1153
                        FLsetVal_i 0, ih1154
                        FLsetVal_i 0, ih1155


ihF1141 FLbox "Effect Sends", 5, 1 , 11, 392, 17, iefxX1, ifxknoby1-25

ihF1101 FLvalue " ", 40, 17, iefxX1,   ifxvaly1
ihF1103 FLvalue " ", 40, 17, iefxX2_8, ifxvaly1
ihF1104 FLvalue " ", 40, 17, iefxX3_8, ifxvaly1
ihF1105 FLvalue " ", 40, 17, iefxX4_8, ifxvaly1
ihF1106 FLvalue " ", 40, 17, iefxX5_8, ifxvaly1
ihF1107 FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihF1108 FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihF1109 FLvalue " ", 40, 17, iefxX8_8, ifxvaly1

gkfx_rm_dry,ihF1111 FLknob "Dry",      0, 1, 0, 1, ihF1101, ifxknobsize, iefxX1,   ifxknoby1
gkfx_rm_fm,ihF1113 FLknob "FreqMod",    0, 1, 0, 1, ihF1103, ifxknobsize, iefxX2_8, ifxknoby1
gkfx_rm_flt1,ihF1114 FLknob "Filter1",    0, 1, 0, 1, ihF1104, ifxknobsize, iefxX3_8, ifxknoby1
gkfx_rm_dist,ihF1115 FLknob "Distortion",    0, 1, 0, 1, ihF1105, ifxknobsize, iefxX4_8, ifxknoby1
gkfx_rm_flt2,ihF1116 FLknob "Filter2",    0, 1, 0, 1, ihF1106, ifxknobsize, iefxX5_8, ifxknoby1
gkfx_rm_dly1,ihF1117 FLknob "Delay1",    0, 1, 0, 1, ihF1107, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_rm_dly2,ihF1118 FLknob "Delay2",    0, 1, 0, 1, ihF1108, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_rm_rvb,ihF1119 FLknob "Reverb",    0, 1, 0, 1, ihF1109, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 1, ihF1111
                        FLsetVal_i 0, ihF1113
                        FLsetVal_i 0, ihF1114
                        FLsetVal_i 0.1, ihF1115
                        FLsetVal_i 0, ihF1116
                        FLsetVal_i 0, ihF1117
                        FLsetVal_i 0, ihF1118

                FLgroupEnd
; *************************
                        FLgroup "FreqMod",  475, 305, 10, 400

$EfxFader.(FrqMod'0.70)
ih1201 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1202 FLvalue " ", 40, 15, iefxX2_5, iefxY1V
ih1203 FLvalue " ", 40, 15, iefxX3_5, iefxY1V
ih1204 FLvalue " ", 40, 15, iefxX4_5, iefxY1V
ih1205 FLvalue " ", 40, 15, iefxX5_5, iefxY1V

gkfx_fm_mfrq,ih1251 FLknob "Mod Freq",    1, 5000, -1, 1, ih1201, 40, iefxX1,   iefxY1
gkfx_fm_mndx,ih1252 FLknob "Mod indx", 0.01, 0.4,  -1, 1, ih1202, 40, iefxX2_5, iefxY1
gkfx_fm_lfrq,ih1253 FLknob "LFO Freq",    0.01, 20,-1, 1, ih1203, 40, iefxX3_5, iefxY1
gkfx_fm_lamt,ih1254 FLknob "LFO amt",    0, 2,     0, 1, ih1204, 40, iefxX4_5, iefxY1
gkfx_fm_afrq,ih1255 FLknob "Amp -> Freq",   -1, 3,     0, 1, ih1205, 40, iefxX5_5, iefxY1

                        FLsetAlign   2, ih1251
                        FLsetAlign   2, ih1252
                        FLsetAlign   2, ih1253
                        FLsetAlign   2, ih1254
                        FLsetAlign   2, ih1255
                        FLsetVal_i 400, ih1251
                        FLsetVal_i 0.03, ih1252
                        FLsetVal_i   1, ih1253
                        FLsetVal_i   0, ih1254
                        FLsetVal_i   3, ih1255

ihF1241 FLbox "Effect Sends", 5, 1 , 11, 392, 17, iefxX1, ifxknoby1-25

ihF1201 FLvalue " ", 40, 17, iefxX1,   ifxvaly1
ihF1203 FLvalue " ", 40, 17, iefxX3_8, ifxvaly1
ihF1204 FLvalue " ", 40, 17, iefxX4_8, ifxvaly1
ihF1205 FLvalue " ", 40, 17, iefxX5_8, ifxvaly1
ihF1206 FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihF1207 FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihF1208 FLvalue " ", 40, 17, iefxX8_8, ifxvaly1


gkfx_fm_dry,ihF1211 FLknob "Dry",      0, 1, 0, 1, ihF1201, ifxknobsize, iefxX1,   ifxknoby1
gkfx_fm_flt1,ihF1213 FLknob "Filter1",    0, 1, 0, 1, ihF1203, ifxknobsize, iefxX3_8, ifxknoby1
gkfx_fm_dist,ihF1214 FLknob "Distortion",    0, 1, 0, 1, ihF1204, ifxknobsize, iefxX4_8, ifxknoby1
gkfx_fm_flt2,ihF1215 FLknob "Filter2",    0, 1, 0, 1, ihF1205, ifxknobsize, iefxX5_8, ifxknoby1
gkfx_fm_dly1,ihF1216 FLknob "Delay1",    0, 1, 0, 1, ihF1206, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_fm_dly2,ihF1217 FLknob "Delay2",    0, 1, 0, 1, ihF1207, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_fm_rvb,ihF1218 FLknob "Reverb",    0, 1, 0, 1, ihF1208, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 0.3, ihF1211
                        FLsetVal_i 0, ihF1213
                        FLsetVal_i 0, ihF1214
                        FLsetVal_i 0, ihF1215
                        FLsetVal_i 0, ihF1216
                        FLsetVal_i 0, ihF1217
                        FLsetVal_i 0.25, ihF1218

                FLgroupEnd
; *************************
                        FLgroup "Filter 1", 475, 305, 10, 400

$EfxFader.(Filt1'0.40)
ih1301 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1302 FLvalue " ", 40, 15, iefxX2_5, iefxY1V
ih1303 FLvalue " ", 40, 15, iefxX3_5, iefxY1V
ih1304 FLvalue " ", 40, 15, iefxX4_5, iefxY1V
ih1305 FLvalue " ", 40, 15, iefxX5_5, iefxY1V

gkfx_f1_cfrq,ih1351 FLknob "Cutoff Freq",    10, 8000,-1, 1, ih1301, 40, iefxX1,   iefxY1
gkfx_f1_q,ih1352 FLknob "Filter Q",  0.01, 1,   -1, 1, ih1302, 40, iefxX2_5, iefxY1
gkfx_f1_lp,ih1353 FLknob "Amp LP",  0.01, 1,    0, 1, ih1303, 40, iefxX3_5, iefxY1
gkfx_f1_bp,ih1354 FLknob "Amp BP",  0.01, 1,    0, 1, ih1304, 40, iefxX4_5, iefxY1
gkfx_f1_hp,ih1355 FLknob "Amp HP",  0.01, 1,    0, 1, ih1305, 40, iefxX5_5, iefxY1

                        FLsetAlign 2, ih1351
                        FLsetAlign 2, ih1352
                        FLsetAlign 2, ih1353
                        FLsetAlign 2, ih1354
                        FLsetAlign 2, ih1355
                        FLsetVal_i 500, ih1351
                        FLsetVal_i 0.03, ih1352
                        FLsetVal_i 0, ih1353
                        FLsetVal_i 1, ih1354
                        FLsetVal_i 0.7, ih1355

ih1306 FLvalue " ", 40, 15, iefxX1,   iefxY2V
ih1307 FLvalue " ", 40, 15, iefxX2_5, iefxY2V
ih1308 FLvalue " ", 40, 15, iefxX3_5, iefxY2V

gkfx_f1_lfrq,ih1356 FLknob "LFO Freq",    0.01, 20,-1, 1, ih1306, 40, iefxX1,   iefxY2
gkfx_f1_lamt,ih1357 FLknob "LFO amt",    0, 2,     0, 1, ih1307, 40, iefxX2_5, iefxY2
gkfx_f1_afrq,ih1358 FLknob "Amp -> Freq",   -1, 3,     0, 1, ih1308, 40, iefxX3_5, iefxY2

                        FLsetAlign 2, ih1356
                        FLsetAlign 2, ih1357
                        FLsetAlign 2, ih1358
                        FLsetVal_i 0.2, ih1356
                        FLsetVal_i 0.3, ih1357
                        FLsetVal_i 3, ih1358

ihF1341 FLbox "Effect Sends", 5, 1 , 11, 392, 17, iefxX1, ifxknoby1-25

ihF1301 FLvalue " ", 40, 17, iefxX1,   ifxvaly1
ihF1304 FLvalue " ", 40, 17, iefxX4_8, ifxvaly1
ihF1305 FLvalue " ", 40, 17, iefxX5_8, ifxvaly1
ihF1306 FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihF1307 FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihF1308 FLvalue " ", 40, 17, iefxX8_8, ifxvaly1

gkfx_f1_dry,ihF1311 FLknob "Dry",      0, 1, 0, 1, ihF1301, ifxknobsize, iefxX1,   ifxknoby1
gkfx_f1_dist,ihF1314 FLknob "Distortion",    0, 1, 0, 1, ihF1304, ifxknobsize, iefxX4_8, ifxknoby1
gkfx_f1_flt2,ihF1315 FLknob "Filter2",    0, 1, 0, 1, ihF1305, ifxknobsize, iefxX5_8, ifxknoby1
gkfx_f1_dly1,ihF1316 FLknob "Delay1",    0, 1, 0, 1, ihF1306, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_f1_dly2,ihF1317 FLknob "Delay2",    0, 1, 0, 1, ihF1307, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_f1_rvb,ihF1318 FLknob "Reverb",    0, 1, 0, 1, ihF1308, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 1, ihF1311
                        FLsetVal_i 0, ihF1314
                        FLsetVal_i 0, ihF1315
                        FLsetVal_i 0, ihF1316
                        FLsetVal_i 0.6, ihF1317
                        FLsetVal_i 0, ihF1318

                FLgroupEnd
; *************************

                        FLgroup "Distortion", 475, 305, 10, 400

$EfxFader.(Dist'0.40)
ih1401 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1402 FLvalue " ", 40, 15, iefxX2_5, iefxY1V
ih1403 FLvalue " ", 40, 15, iefxX3_5, iefxY1V
ih1404 FLvalue " ", 40, 15, iefxX4_5, iefxY1V

gkfx_ds_drv,ih1451 FLknob "Dist Drive",    1, 50,   -1, 1, ih1401, 40, iefxX1,   iefxY1
gkfx_ds_shp,ih1452 FLknob "Dist Shape",    0, 2,     0, 1, ih1402, 40, iefxX2_5, iefxY1
gkfx_ds_pflt,ih1453 FLknob "Post Filter",   20, 16000, 0, 1, ih1403, 40, iefxX3_5, iefxY1
gkfx_ds_adrv,ih1454 FLknob "Amp -> Drive",    -20, 20,   0, 1, ih1404, 40, iefxX4_5, iefxY1

                        FLsetAlign 2, ih1451
                        FLsetAlign 2, ih1452
                        FLsetAlign 2, ih1453
                        FLsetAlign 2, ih1454
                        FLsetVal_i 5, ih1451
                        FLsetVal_i 0.14, ih1452
                        FLsetVal_i 9000, ih1453
                        FLsetVal_i 10, ih1454

ihF1441 FLbox "Effect Sends", 5, 1 , 11, 392, 17, iefxX1, ifxknoby1-25

ihF1401 FLvalue " ", 40, 17, iefxX1,   ifxvaly1
ihF1405 FLvalue " ", 40, 17, iefxX5_8, ifxvaly1
ihF1406 FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihF1407 FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihF1408 FLvalue " ", 40, 17, iefxX8_8, ifxvaly1

gkfx_ds_dry,ihF1411 FLknob "Dry",      0, 1, 0, 1, ihF1401, ifxknobsize, iefxX1,   ifxknoby1
gkfx_ds_flt2,ihF1415 FLknob "Filter2",    0, 1, 0, 1, ihF1405, ifxknobsize, iefxX5_8, ifxknoby1
gkfx_ds_dly1,ihF1416 FLknob "Delay1",    0, 1, 0, 1, ihF1406, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_ds_dly2,ihF1417 FLknob "Delay2",    0, 1, 0, 1, ihF1407, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_ds_rvb,ihF1418 FLknob "Reverb",    0, 1, 0, 1, ihF1408, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 1, ihF1411
                        FLsetVal_i 0, ihF1415
                        FLsetVal_i 0, ihF1416
                        FLsetVal_i 0.3, ihF1417
                        FLsetVal_i 0, ihF1418

                FLgroupEnd
; *************************
                        FLgroup "Filter 2",  475, 305, 10, 400

$EfxFader.(Filt2'0.40)
ih1501 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1502 FLvalue " ", 40, 15, iefxX2_6, iefxY1V
ih1503 FLvalue " ", 40, 15, iefxX3_6, iefxY1V
ih1504 FLvalue " ", 40, 15, iefxX4_6, iefxY1V
ih1505 FLvalue " ", 40, 15, iefxX5_6, iefxY1V
ih1506 FLvalue " ", 40, 15, iefxX6_6, iefxY1V

gkfx_f2_cfrq,ih1551 FLknob "Cutoff Freq",    20, 8000,-1, 1, ih1501, 40, iefxX1,   iefxY1
gkfx_f2_res,ih1552 FLknob "Resonance",    0.1,   1, 0, 1, ih1502, 40, iefxX2_6, iefxY1
gkfx_f2_dst,ih1553 FLknob "Distortion",    0,    20, 0, 1, ih1503, 40, iefxX3_6, iefxY1
gkfx_f2_lfrq,ih1554 FLknob "LFO Freq",    0.01,20, -1, 1, ih1504, 40, iefxX4_6, iefxY1
gkfx_f2_lamt,ih1555 FLknob "LFO amt",    0,   2,   0, 1, ih1505, 40, iefxX5_6, iefxY1
gkfx_f2_afrq,ih1556 FLknob "Amp -> Freq",   -1,   3,   0, 1, ih1506, 40, iefxX6_6, iefxY1

                        FLsetAlign 2, ih1551
                        FLsetAlign 2, ih1552
                        FLsetAlign 2, ih1553
                        FLsetAlign 2, ih1554
                        FLsetAlign 2, ih1555
                        FLsetAlign 2, ih1556
                        FLsetVal_i 1000, ih1551
                        FLsetVal_i 0.7, ih1552
                        FLsetVal_i 3.7, ih1553
                        FLsetVal_i 0.15, ih1554
                        FLsetVal_i 0.2, ih1555
                        FLsetVal_i 3, ih1556


ihF1541 FLbox "Effect Sends", 5, 1 , 11, 392, 17, iefxX1, ifxknoby1-25

ihF1501 FLvalue " ", 40, 17, iefxX1,   ifxvaly1
ihF1506 FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihF1507 FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihF1508 FLvalue " ", 40, 17, iefxX8_8, ifxvaly1

gkfx_f2_dry,ihF1511 FLknob "Dry",      0, 1, 0, 1, ihF1501, ifxknobsize, iefxX1,   ifxknoby1
gkfx_f2_dly1,ihF1516 FLknob "Delay1",    0, 1, 0, 1, ihF1506, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_f2_dly2,ihF1517 FLknob "Delay2",    0, 1, 0, 1, ihF1507, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_f2_rvb,ihF1518 FLknob "Reverb",    0, 1, 0, 1, ihF1508, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 1, ihF1511
                        FLsetVal_i 0.25, ihF1516
                        FLsetVal_i 0, ihF1517
                        FLsetVal_i 0, ihF1518

                FLgroupEnd
; *************************

; *************************

#define DelayEfx(A'B'C'D'E'F'G'H'I'J'K'L'M) #
;ARGS: delaymodule number, tempofact, subdivL, straightdotL, subdivR, strdtR, fineL, fineR,
; LfoFq, LfoAmtL, LfoAmtR, Feedback, FeedbackFiltFreq

                        FLlabel   -1
                        FLlabel   10, 1, 1, 0, 0, 0

ihDel$A2b FLbox "Tempofactor",  1, 1, 10,   74, 15,  imX1, iefxY1-15
gkfx_d$A2b,ihDel$A2 FLbutBank 2,  1,  8,   74, 130,  imX1, iefxY1, -105, -1
gkfx_d$A2b init $B
gkfx_d$A_timul table gkfx_d$A2b,  184 ; Deltime, Tempofactor

gkfx_d$A_unl,ihDel$A10 FLbutton "Unlink",    1, 0, 2,   74, 20, imX1, iefxY1+135, -1, -1

ihDel$A0a FLbox "deltime subdiv (2, 4, 8, 16)", 1, 1, 10,  180, 15, iefxX1+20,  iefxY1-15
ihDel$A0b FLbox "straight/dotted/triplet", 1, 1, 10,   140, 15, iefxX1+210, iefxY1-15
ihDel$A0c FLbox "delaytime",   1, 1, 10,    45, 15, iefxX1+345, iefxY1-15
ihDel$A0d FLbox "L",   1, 1, 10,    20, 18, iefxX1,     iefxY1
ihDel$A0e FLbox "R",   1, 1, 10,    20, 18, iefxX1,     iefxY1+25

gkfx_d$A1a,ihDel$A1a FLbutBank 2,  4,  1,   180, 18, iefxX1+20,  iefxY1, -105, -1
gkfx_d$A1a init $C
gkfx_d$A_subL table gkfx_d$A1a, 182 ; Left  deltime subdiv (2, 4, 8, 16)

gkfx_d$A1b,ihDel$A1b FLbutBank 2,  3,  1,   130, 18, iefxX1+210, iefxY1, -105, -1
gkfx_d$A1b init $D
gkfx_d$A_noteL table gkfx_d$A1b, 183 ; Left  straight/dotted/triplet

gkfx_d$A1c,ihDel$A1c FLbutBank 2,  4,  1,   180, 18, iefxX1+20,  iefxY1+25, -105, -1
gkfx_d$A1c init $E
gkfx_d$A_subR table gkfx_d$A1c, 182 ; Right deltime subdiv (2, 4, 8, 16)

gkfx_d$A1d,ihDel$A1d FLbutBank 2,  3,  1,   130, 18, iefxX1+210, iefxY1+25, -105, -1
gkfx_d$A1d init $F
gkfx_d$A_noteR table gkfx_d$A1d, 183 ; Right straight/dotted/triplet

gihDel$AtimL FLvalue " ",    45, 18, iefxX1+345, iefxY1
gihDel$AtimR FLvalue " ",    45, 18, iefxX1+345, iefxY1+25

                        FLlabel   -1
                        FLlabel   10, 1, 2, 0, 0, 0

ihDel$A3v FLvalue " ", 40, 17, iefxX1+20,   iefxY2V ; deltime fine L
ihDel$A4v FLvalue " ", 40, 17, iefxX2_5+20, iefxY2V ; deltime fine R
ihDel$A5v FLvalue " ", 40, 17, iefxX3_5+20, iefxY2V
ihDel$A6v FLvalue " ", 40, 17, iefxX4_5+20, iefxY2V
ihDel$A7v FLvalue " ", 40, 17, iefxX5_5+20, iefxY2V

ihDel$A8v FLvalue " ", 40, 17,  iefxX1+20,   ifxvaly1
ihDel$A9v FLvalue " ", 40, 17,  iefxX2_5+20, ifxvaly1

gkfx_d$A_timfL,ihDel$A3 FLknob "time fine L",     -0.2, 0.2,   0, 1, ihDel$A3v, 40, iefxX1+20,   iefxY2
gkfx_d$A_timfR,ihDel$A4 FLknob "time fine R",     -0.2, 0.2,   0, 1, ihDel$A4v, 40, iefxX2_5+20, iefxY2
gkfx_d$A_lfrq,ihDel$A5 FLknob "LFO Freq",    0.01, 5,   -1, 1, ihDel$A5v, 40, iefxX3_5+20, iefxY2
gkfx_d$A_lamtL,ihDel$A6 FLknob "LFO amtL",   -0.2, 0.2,   0, 1, ihDel$A6v, 40, iefxX4_5+20, iefxY2
gkfx_d$A_lamtR,ihDel$A7 FLknob "LFO amtR",   -0.2, 0.2,   0, 1, ihDel$A7v, 40, iefxX5_5+20, iefxY2

gkfx_d$A_fb,ihDel$A8 FLknob "Feedback",    0, 1,       0, 1, ihDel$A8v, 40, iefxX1+20,   ifxknoby1
gkfx_d$A_flt,ihDel$A9 FLknob "Fb Filter",      0, 10000,     0, 1, ihDel$A9v, 40, iefxX2_5+20, ifxknoby1

                        FLsetAlign 2, ihDel$A3
                        FLsetAlign 2, ihDel$A4
                        FLsetAlign 2, ihDel$A5
                        FLsetAlign 2, ihDel$A6
                        FLsetAlign 2, ihDel$A7
                        FLsetAlign 2, ihDel$A8
                        FLsetAlign 2, ihDel$A9
                        FLsetAlign 1, ihDel$A10
                        FLsetVal_i $G, ihDel$A3
                        FLsetVal_i $H, ihDel$A4
                        FLsetVal_i $I, ihDel$A5
                        FLsetVal_i $J, ihDel$A6
                        FLsetVal_i $K, ihDel$A7
                        FLsetVal_i $L, ihDel$A8
                        FLsetVal_i $M, ihDel$A9


ihFDel$A1bx FLbox "Effect Sends", 5, 1 , 11, 140, 17, iefxX6_8, ifxknoby1-25

ihFDel$A1v FLvalue " ", 40, 17, iefxX6_8, ifxvaly1
ihFDel$A7v FLvalue " ", 40, 17, iefxX7_8, ifxvaly1
ihFDel$A8v FLvalue " ", 40, 17, iefxX8_8, ifxvaly1

gkfx_d$A_dry,ihFDel$A1 FLknob "Dry",      0, 1, 0, 1, ihFDel$A1v, ifxknobsize, iefxX6_8, ifxknoby1
gkfx_d$A_dly2,ihFDel$A7 FLknob "Delay2",    0, 1, 0, 1, ihFDel$A7v, ifxknobsize, iefxX7_8, ifxknoby1
gkfx_d$A_rvb,ihFDel$A8 FLknob "Reverb",    0, 1, 0, 1, ihFDel$A8v, ifxknobsize, iefxX8_8, ifxknoby1

                        FLsetVal_i 1, ihFDel$A1
                        FLsetVal_i 0, ihFDel$A7
                        FLsetVal_i 0, ihFDel$A8


#
                        FLgroup "Delay 1",  475, 305, 10, 400
$EfxFader.(Del1'0.35)
$DelayEfx.(1'1'1'1'2'1'0.005'0.006'0.12'0.003'0.001'0.4'6100)
;ARGS: delaymodule number, tempofact, subdivL, straightdotL, subdivR, strdtR, fineL, fineR,
; LfoFq, LfoAmtL, LfoAmtR, Feedback, FeedbackFiltFreq
                        FLgroupEnd

                        FLgroup "Delay 2",  475, 305, 10, 400
$EfxFader.(Del2'0.65)
$DelayEfx.(2'1'1'1'1'0'0.0'0.0'0.7'0'0'0.35'6000)
                        FLgroupEnd
; ******** til hit, varname changes.txt + Improsculpt_bkupOldGui.csd
; *************************
                        FLgroup "Reverb",  475, 305, 10, 400

$EfxFader.(Revb'0.52)

ih1801 FLvalue " ", 40, 15, iefxX1,   iefxY1V
ih1802 FLvalue " ", 40, 15, iefxX2_5, iefxY1V
ih1803 FLvalue " ", 40, 15, iefxX3_5, iefxY1V
ih1804 FLvalue " ", 40, 15, iefxX4_5, iefxY1V
ih1805 FLvalue " ", 40, 15, iefxX5_5, iefxY1V

gkfx_rv_tim,ih1851 FLknob "Reverb Feedb",  0.4, 1,   130, 1, ih1801, 40, iefxX1,   iefxY1
gkfx_rv_pdly,ih1852 FLknob "Pre Delay", 0.001, 0.1,   0, 1, ih1802, 40, iefxX2_5, iefxY1
gkfx_rv_hf,ih1853 FLknob "HP Damp",    1, 15000, 0, 1, ih1803, 40, iefxX3_5, iefxY1
gkfx_rv_lf,ih1854 FLknob "LF Rolloff",    1, 1000,  0, 1, ih1804, 40, iefxX4_5, iefxY1
gkfx_rv_pmod,ih1855 FLknob "Pitchmod",    0, 4,     0, 1, ih1805, 40, iefxX5_5, iefxY1

                        FLsetAlign 2, ih1851
                        FLsetAlign 2, ih1852
                        FLsetAlign 2, ih1853
                        FLsetAlign 2, ih1854
                        FLsetAlign 2, ih1855
                        FLsetVal_i 0.77, ih1851
                        FLsetVal_i 0.1, ih1852
                        FLsetVal_i 10000, ih1853
                        FLsetVal_i 140, ih1854
                        FLsetVal_i 0.98, ih1855

                        FLgroupEnd
; *************************
                        FLtabsEnd
                        FLpanelEnd


;*******************************
        FLrun
;*******************************


;Pad 1
kpad1on trigger gkt701, 0.5, 0
schedkwhen kpad1on,  0, 0, 360.1, 0, -1, 7.04 ; E'
kpad1off trigger gkt701, 0.5, 1
schedkwhen kpad1off,  0, 0, -360.1, 0, 1, 7.04 ; E'
kpad2on trigger gkt702, 0.5, 0
schedkwhen kpad2on,  0, 0, 360.2, 0, -1, 8.04 ; E
kpad2off trigger gkt702, 0.5, 1
schedkwhen kpad2off,  0, 0, -360.2, 0, 1, 8.04 ; E
kpad3on trigger gkt703, 0.5, 0
schedkwhen kpad3on,  0, 0, 360.3, 0, -1, 9.04 ; e
kpad3off trigger gkt703, 0.5, 1
schedkwhen kpad3off,  0, 0, -360.3, 0, 1, 9.04 ; e
kpad4on trigger gkt704, 0.5, 0
schedkwhen kpad4on,  0, 0, 360.4, 0, -1, 9.06 ; f#
kpad4off trigger gkt704, 0.5, 1
schedkwhen kpad4off,  0, 0, -360.4, 0, 1, 9.06 ; f#
kpad5on trigger gkt705, 0.5, 0
schedkwhen kpad5on,  0, 0, 360.5, 0, -1, 9.08 ; g#
kpad5off trigger gkt705, 0.5, 1
schedkwhen kpad5off,  0, 0, -360.5, 0, 1, 9.08 ; g#
kpad6on trigger gkt706, 0.5, 0
schedkwhen kpad6on,  0, 0, 360.6, 0, -1, 9.10 ; a#
kpad6off trigger gkt706, 0.5, 1
schedkwhen kpad6off,  0, 0, -360.6, 0, 1, 9.10 ; a#
kpad7on trigger gkt707, 0.5, 0
schedkwhen kpad7on,  0, 0, 360.7, 0, -1, 9.11 ; h
kpad7off trigger gkt707, 0.5, 1
schedkwhen kpad7off,  0, 0, -360.7, 0, 1, 9.11 ; h
kpad8on trigger gkbtPadOn, 0.5, 0
schedkwhen kpad8on,  0, 0, 360.7, 0, -1, 10.03 ; d#
kpad8off trigger gkbtPadOn, 0.5, 1
schedkwhen kpad8off,  0, 0, -360.7, 0, 1, 10.03 ; d#

; *** trigger instr events
;;auto sampler voice 1 (instr 302)
schedkwhen gkt2, 0.1, 1, 302, 0, -1 ;note on
kt2 trigger gkt2, 0.5, 1
schedkwhen kt2,  0.1, 1, -302, 0, 1 ;note off

;auto sampler voice 2 (instr 303)
schedkwhen gkt22, 0.1, 1, 303, 0, -1 ;note on
kt22 trigger gkt22, 0.5, 1
schedkwhen kt22,  0.1, 1, -303, 0, 1 ;note off

;*******************************************************************
;pitch track instr scheduling
kPTstore trigger gkPSmpl,  0.5, 0
kPTst_off trigger gkPSmpl,  0.5, 1
kPTGrFrq trigger gkPGrFrq, 0.5, 0
kPTGrFrq_off trigger gkPGrFrq, 0.5, 1
kPTGrTsp trigger gkPGrTsp, 0.5, 0
kPTGrTsp_off trigger gkPGrTsp, 0.5, 1
kPTFmFrq trigger gkPFMFrq, 0.5, 0
kPTFmFrq_off trigger gkPFMFrq, 0.5, 1
kPTRmFrq trigger gkPRMFrq, 0.5, 0
kPTRmFrq_off trigger gkPRMFrq, 0.5, 1
kPTBasSyn trigger gkPBasSyn, 0.5, 0
kPTBasSyn_off trigger gkPBasSyn, 0.5, 1


schedkwhen kPTstore,   0, 1, 181, 0, -1 ; on store pitch
schedkwhen kPTst_off,   0, 1, -181, 0, 1 ; off store pitch
schedkwhen kPTGrFrq, 0, 1, 182, 0, -1 ; on pitch to GrainFreq
schedkwhen kPTGrFrq_off, 0, 1, -182, 0, 1 ; off pitch to GrainFreq
schedkwhen kPTGrTsp, 0, 1, 183, 0, -1 ; on pitch to GrainTransp
schedkwhen kPTGrTsp_off, 0, 1, -183, 0, 1 ; off pitch to GrainTransp
schedkwhen kPTFmFrq, 0, 1, 184, 0, -1 ; on pitch to FM Freq
schedkwhen kPTFmFrq_off, 0, 1, -184, 0, 1 ; off pitch to FM Freq
schedkwhen kPTRmFrq, 0, 1, 185, 0, -1 ; on pitch to RM Freq
schedkwhen kPTRmFrq_off, 0, 1, -185, 0, 1 ; off pitch to RM Freq
schedkwhen kPTBasSyn, 0, 1, 186, 0, -1 ; on pitch to BasSynth
schedkwhen kPTBasSyn_off, 0, 1, -186, 0, 1 ; off pitch to BasSynth
;*******************************************************************

;;rhythm engine (instr 255) (+ instr 256,257,258)
schedkwhen gktR,  0.1, 1, 255, 0, -1 ;note on
gktRo trigger gktR,  0.5, 1
schedkwhen gktRo, 0.1, 1, -255, 0, 1 ;note off(5)
schedkwhen gktRo, 0.1, 1, -256, 0, 1 ;note off(6)
schedkwhen gktRo, 0.1, 1, -257, 0, 1 ;note off(7)
schedkwhen gktRo, 0.1, 1, -258, 0, 1 ;note off(8)

;loop enable trig/mute
gkdrmoff = (gktR + gkbtLoopOn > 1 ? 0 : 1 ) ;if both buttons ON, let drumloop play

; pattern sequencer clock enable/disable
gkptrnoff = (gktR + gkbtPtSeqOn > 1 ? 0 : 1 ) ;if both buttons ON, let pattern play

;;grain playback voice 1 (instr 321)
schedkwhen gkbtGrain1On, 0.1, 1, 321, 0, -1 ;note on
kt61 trigger gkbtGrain1On, 0.5, 1
schedkwhen kt61,  0.1, 1, -321, 0, 1 ;note off

;;grain playback voice 2 (instr 322)
schedkwhen gkbtGrain2On, 0.1, 1, 322, 0, -1 ;note on
kt62 trigger gkbtGrain2On, 0.5, 1
schedkwhen kt62,  0.1, 1, -322, 0, 1 ;note off

;;grain playback voice 3 (instr 323)
schedkwhen gkbtGrain3On, 0.1, 1, 323, 0, -1 ;note on
kt63 trigger gkbtGrain3On, 0.5, 1
schedkwhen kt63,  0.1, 1, -323, 0, 1 ;note off

;;grain playback voice 4 (instr 324)
schedkwhen gkbtGrain4On, 0.1, 1, 324, 0, -1 ;note on
kt64 trigger gkbtGrain4On, 0.5, 1
schedkwhen kt64,  0.1, 1, -324, 0, 1 ;note off

;;random access grain module, voice 1 (control, instr 330)
schedkwhen gkbtRAGOn, 0.1, 1, 330, 0, -1 ;note on
k_rag_on trigger gkbtRAGOn, 0.5, 1
schedkwhen k_rag_on, 0.1, 1, -330, 0, 1 ;note off

        endin
;****************************************************************
;****************************************************************


;****************************************************************
; Tap tempo instr1, calculate tempo
;****************************************************************
        instr 19
;gktaptempo1 line 1, p3, 0.2

gitime_new times ; seconds since performance start
iperiod = gitime_new - gitime_old ; number of seconds since last tap
gitime_old = gitime_new ; update for next tap
itempo = 60/iperiod ; convert to bpm
gkbtpo = ( itempo > 30 ? itempo : gkbtpo ) ; filter extremely low values

FLprintk2 gkbtpo, gihCurTpo

        endin
;****************************************************************
;****************************************************************


;****************************************************************
; Pitch Tracker
;****************************************************************
instr 181
        a1,a2 ins
        imincps = 70
        imaxcps = 700
        a1 lowpass2 a1, imaxcps, 2

        initfreq = imincps
        imedian = 1
        idowns = 4
        iexcps = imincps
        irmsmedi = 0
        kcps,krms pitchamdf a1, imincps, imaxcps, initfreq ,imedian ,idowns ,iexcps ,irmsmedi
        gkcps = kcps
        gkrms = krms

        ifn = i((gkPn1-1)*2)+21 ; experimental
print ifn
        tableicopy ifn, 15 ; clear pitch table
        tableicopy ifn+1, 15 ; clear amp table

        kpeak init 0
        kpeak peak krms   ; peak level so far
        if kpeak < gk_sampthresh1 kgoto end   ; don't start writing before the first sound comes in
        krms = (krms < gk_sampthresh1 ? 0 : krms ) ; if low amplitude, set to zero
        krms tonek krms, 50 ; filter out abrupt changes in amp

        kndx line 0, 1, kr ; goes on forever
        kndx = (kndx > 262144 ? kndx-262144 : kndx) ; wrap around
  tablew kcps, kndx, ifn ; write pitch
  tablew krms, kndx, ifn+1 ; write amp
end:

endin
;****************************************************************
;****************************************************************
;playback of recorded pitches, to Grain Frequency, Grain Module 2
instr 182

        kretrig init 0 ; reinit, start over from start of pitch table
        kretrig = (gkPtrkTrig == 1 ? kretrig+1 : kretrig) ; if at count 1 of measure, step up
        kretrig1 = (kretrig > (gkPtrg5-1) ? 1 : 0 ) ; if over threshold, retrig
        kretrig1 = (gkPtrg5 == 0 ? 0 : kretrig1 ) ; if set to retrig every 0 measures, do not retrig
        kretrig = (kretrig > (gkPtrg5-1) ? 0 : kretrig ) ; if over threshold, start over from zero

if kretrig1 == 0 goto skipretrig
reinit skipretrig
skipretrig:
        iold = i(gkGrn2grfq)
        gk182active = 1
        ifn = i(gkPn2)+20
        kndx line 0, 1, kr ; goes on forever
rireturn
        kcps table kndx, ifn ; read pitch
        krms table kndx, ifn+1 ; read amp
        kcps = kcps * gkPmulti1
        gkGrn2grfq = (kcps > 30 ? kcps : gkGrn2grfq) ; pitchmel to grain freq

        if gktPAmp1 == 0 kgoto skipamp

        gksGrain2amp = (krms > gkPa2 ? krms*0.0001*gkPa1 : gkPa2) ; amp thresh and amount
        skipamp:

endin
;****************************************************************
;****************************************************************
;playback of recorded pitches, to Grain Transpose, Grain Module 2
instr 183

        kretrig init 0 ; reinit, start over from start of pitch table
        kretrig = (gkPtrkTrig == 1 ? kretrig+1 : kretrig) ; if at count 1 of measure, step up
        kretrig1 = (kretrig > (gkPtrg5-1) ? 1 : 0 ) ; if over threshold, retrig
        kretrig1 = (gkPtrg5 == 0 ? 0 : kretrig1 ) ; if set to retrig every 0 measures, do not retrig
        kretrig = (kretrig > (gkPtrg5-1) ? 0 : kretrig ) ; if over threshold, start over from zero

if kretrig1 == 0 goto skipretrig
reinit skipretrig
skipretrig:
        ifn = i(gkPn3)+20
        kndx line 0, 1, kr ; goes on forever
rireturn
        kcps table kndx, ifn ; read pitch
        krms table kndx, ifn+1 ; read amp
        kcps = kcps * gkPmulti2
        gkGrn2form = (kcps > 30 ? kcps/220 : gkGrn2form) ; pitchmel to grain transp

        if gktPAmp2 == 0 kgoto skipamp
        gksGrain2amp = (krms > gkPa4 ? krms*0.0001*gkPa3 : gkPa4) ; amp thresh and amount
        skipamp:

endin
;****************************************************************
;****************************************************************
;playback of recorded pitches, to FM Freq (FM aux effect)
instr 184

        kretrig init 0 ; reinit, start over from start of pitch table
        kretrig = (gkPtrkTrig == 1 ? kretrig+1 : kretrig) ; if at count 1 of measure, step up
        kretrig1 = (kretrig > (gkPtrg5-1) ? 1 : 0 ) ; if over threshold, retrig
        kretrig1 = (gkPtrg5 == 0 ? 0 : kretrig1 ) ; if set to retrig every 0 measures, do not retrig
        kretrig = (kretrig > (gkPtrg5-1) ? 0 : kretrig ) ; if over threshold, start over from zero

if kretrig1 == 0 goto skipretrig
reinit skipretrig
skipretrig:
        ifn = i(gkPn4)+20
        kndx line 0, 1, kr ; goes on forever
rireturn
        kcps table kndx, ifn ; read pitch
        krms table kndx, ifn+1 ; read amp
        kcps = kcps * gkPmulti3
        gkfx_fm_mfrq = (kcps > 30 ? kcps*2 : gkfx_fm_mfrq) ; pitchmel to FM Freq

endin
;****************************************************************
;****************************************************************
;playback of recorded pitches, to AmpMod Freq (AM aux effect)
instr 185

        kretrig init 0 ; reinit, start over from start of pitch table
        kretrig = (gkPtrkTrig == 1 ? kretrig+1 : kretrig) ; if at count 1 of measure, step up
        kretrig1 = (kretrig > (gkPtrg4-1) ? 1 : 0 ) ; if over threshold, retrig
        kretrig1 = (gkPtrg5 == 0 ? 0 : kretrig1 ) ; if set to retrig every 0 measures, do not retrig
        kretrig = (kretrig > (gkPtrg4-1) ? 0 : kretrig ) ; if over threshold, start over from zero

if kretrig1 == 0 goto skipretrig
reinit skipretrig
skipretrig:
        ifn = i(gkPn5)+20
        kndx line 0, 1, kr ; goes on forever
rireturn
        kcps table kndx, ifn ; read pitch
        krms table kndx, ifn+1 ; read amp
        kcps = kcps * gkPmulti4
        gkfx_rm_mfrq = (kcps > 30 ? kcps*2 : gkfx_rm_mfrq) ; pitchmel to AM Freq

endin
;****************************************************************


;****************************************************************
;playback of recorded pitches, BassSynth
instr 186

        kretrig init 0 ; reinit, start over from start of pitch table
        kretrig = (gkPtrkTrig == 1 ? kretrig+1 : kretrig) ; if at count 1 of measure, step up
        kretrig1 = (kretrig > (gkPtrg5-1) ? 1 : 0 ) ; if over threshold, retrig
        kretrig1 = (gkPtrg5 == 0 ? 0 : kretrig1 ) ; if set to retrig every 0 measures, do not retrig
        kretrig = (kretrig > (gkPtrg5-1) ? 0 : kretrig ) ; if over threshold, start over from zero

if kretrig1 == 0 goto skipretrig
reinit skipretrig
skipretrig:
        ifn = i(gkPn6)+20
        kndx line 0, 1, kr ; goes on forever
rireturn
        kcps table kndx, ifn ; read pitch
        krms table kndx, ifn+1 ; read amp
        kcps = kcps * gkPmulti5 * 0.5 ; octave down

        iamp = 1500
        kamp = iamp
        kthresh = 0
        kampmod = gkPa5
        kamp = (krms > kthresh ? krms*kampmod : kamp) ; amp thresh and amount
        amp = kamp * gkBasSynAmp
        amp tone amp, 50

        abogus rand 1 ; bogus low amp noise signal
        a1 oscil amp, kcps, 95
        a1 = a1 + abogus ; prevent filter underflow
        asine oscil amp, kcps, 93
        kfilt tonek kamp, 0.45
        alo lpf18 a1/32768, 20+(kfilt*0.3), 0.4, 0.4
        alo = (alo *32768) + (asine * 3)
        alo dcblock alo ; experimental, declick at note off

; VU meter
kVU maxk alo, gkupdate1, 0

; FLsetVal gkupdate1, kVU, gihsBasSynampD


;EFX and dry out amplitudes
        zawm alo * gkBasSyn_clean , 4 ; send to clean out Left
        zawm alo * gkBasSyn_clean , 5 ; send to clean out Right
        zawm alo * gkBasSyn_rm , 6 ; send to ring mod
        zawm alo * gkBasSyn_fm , 7 ; send to freq mod
        zawm alo * gkBasSyn_filt1, 8 ; send to filter 1
        zawm alo * gkBasSyn_dist , 9 ; send to distrortion
        zawm alo * gkBasSyn_filt2, 10 ; send to filter 2
        zawm alo * gkBasSyn_del1, 11 ; send to delay 1
        zawm alo * gkBasSyn_del2, 12 ; send to delay 2
        zawm alo * gkBasSyn_revb, 13 ; send to reverb
; zawm alo, 14 ; to output file

endin
;****************************************************************


;****************************************************************
;****************************************************************

instr 200 ;

; sorting of stored sounds related to sound length, in ascending order
; shortest sound has indx=1 in ftable 111.
; the indexes in ftable111 points to ftable numbers 1 to 14 where audio is stored

; ekspandere listen med "current rekkef�lge" lage mellomrom i den,
; skrive inn ny lyd i hullet mellom to eksisterende.
; kollapse listen ved � fjerne nuller og dobbeltoppf�ringer

is1 table 1, 111
is2 table 2, 111
is3 table 3, 111
is4 table 4, 111
is5 table 5, 111
is6 table 6, 111
is7 table 7, 111
is8 table 8, 111
is9 table 9, 111
is10 table 10, 111
is11 table 11, 111
is12 table 12, 111
is13 table 13, 111
is14 table 14, 111
is15 table 15, 111
is16 table 16, 111

i1 table is1, 110
i2 table is2, 110
i3 table is3, 110
i4 table is4, 110
i5 table is5, 110
i6 table is6, 110
i7 table is7, 110
i8 table is8, 110
i9 table is9, 110
i10 table is10, 110
i11 table is11, 110
i12 table is12, 110
i13 table is13, 110
i14 table is14, 110
i15 table is15, 110
i16 table is16, 110

; finding the index for the new sound, in the sorted list
; comparing the length of the new sound to the stored sounds, in ascending order
; e.g. if its longer than the one at index 2, assume it as number 3 in the list
; then compare if it's longer than number 3 in the list etcetera
; skip test if comparing with an empty storage location (length = 0)
; inew is length of new sound
; i1 is length of stored sound 1
; is1 is index number of shortest stored sound
; iindx is index number of new sound

inew = p4 ; inew is length of new sound
iindx = p5 ; audio storage index

if inew == 0 goto newzero ; if sound has been cleared (length recorded = zero)
goto newcompare

newzero:
indxnew = 16 ; to be sorted as the longest sound
goto skiptest

newcompare:
; FIXX this section ??
indxnew = 1
if i1 == 0 goto skiptest
indxnew = (inew > i1 ? 2 : indxnew )
if i2 == 0 goto skiptest
indxnew = (inew > i2 ? 3 : indxnew )
if i3 == 0 goto skiptest
indxnew = (inew > i3 ? 4 : indxnew )
if i4 == 0 goto skiptest
indxnew = (inew > i4 ? 5 : indxnew )
if i5 == 0 goto skiptest
indxnew = (inew > i5 ? 6 : indxnew )
if i6 == 0 goto skiptest
indxnew = (inew > i6 ? 7 : indxnew )
if i7 == 0 goto skiptest
indxnew = (inew > i7 ? 8 : indxnew )
if i8 == 0 goto skiptest
indxnew = (inew > i8 ? 9 : indxnew )
if i9 == 0 goto skiptest
indxnew = (inew > i9 ? 10 : indxnew )
if i10 == 0 goto skiptest
indxnew = (inew > i10 ? 11 : indxnew )
if i11 == 0 goto skiptest
indxnew = (inew > i11 ? 12 : indxnew )
if i12 == 0 goto skiptest
indxnew = (inew > i12 ? 13 : indxnew )
if i13 == 0 goto skiptest
indxnew = (inew > i13 ? 14 : indxnew )
if i14 == 0 goto skiptest
indxnew = (inew > i14 ? 15 : indxnew )
if i15 == 0 goto skiptest
indxnew = (inew > i15 ? 16 : indxnew )
skiptest:

; delete values to be stored in table 112 that equals iindx,
; to avoid duplicates, avoid the table exploding

is1 = (is1 == iindx ? 0 : is1)
is2 = (is2 == iindx ? 0 : is2)
is3 = (is3 == iindx ? 0 : is3)
is4 = (is4 == iindx ? 0 : is4)
is5 = (is5 == iindx ? 0 : is5)
is6 = (is6 == iindx ? 0 : is6)
is7 = (is7 == iindx ? 0 : is7)
is8 = (is8 == iindx ? 0 : is8)
is9 = (is9 == iindx ? 0 : is9)
is10 = (is10 == iindx ? 0 : is10)
is11 = (is11 == iindx ? 0 : is11)
is12 = (is12 == iindx ? 0 : is12)
is13 = (is13 == iindx ? 0 : is13)
is14 = (is14 == iindx ? 0 : is14)
is15 = (is15 == iindx ? 0 : is15)
is16 = (is16 == iindx ? 0 : is16)

; temporal storage of index numbers,
; stored with a space in between each one in f112, (expanded list)
; to make room for writing the new index in between
; spaces are later collapsed, and the list written back to f111
tablecopy 112, 113 ; clear f112
        tableiw is16, 32, 112 ; expand list
        tableiw is15, 30, 112
        tableiw is14, 28, 112
        tableiw is13, 26, 112
        tableiw is12, 24, 112
        tableiw is11, 22, 112
        tableiw is10, 20, 112
        tableiw is9, 18, 112
        tableiw is8, 16, 112
        tableiw is7, 14, 112
        tableiw is6, 12, 112
        tableiw is5, 10, 112
        tableiw is4, 8, 112
        tableiw is3, 6, 112
        tableiw is2, 4, 112
        tableiw is1, 2, 112

        indxnew2 = (2*indxnew)-1 ; write new indx in expanded list
        tableiw iindx, indxnew2, 112

; check for duplicates in f112 ******************* FIX !!

; read expanded list from f112
; compress the list and write to f111
in2 init 0
in1 init 0
ie2 init 0
loopstart:

in2 = in2 + 1
if in2 > 32 goto done
ie table in2, 112

if ie2 = ie goto skipduplicate
ie2 = ie
goto insert

skipduplicate:
ie2 = ie
goto loopstart

insert:
if ie == 0 goto loop
in1 = in1 + 1
        tableiw ie, in1, 111

loop:
goto loopstart
done:


end:

;read sound lengths from ftable 110
; print to GUI FLvalue
isnd1 table 1, 110
isnd2 table 2, 110
isnd3 table 3, 110
isnd4 table 4, 110
isnd5 table 5, 110
isnd6 table 6, 110
isnd7 table 7, 110
isnd8 table 8, 110
isnd9 table 9, 110
isnd10 table 10, 110
isnd11 table 11, 110
isnd12 table 12, 110
isnd13 table 13, 110
isnd14 table 14, 110

isnd1 = (isnd1 < 0.2 ? 0 : isnd1)
isnd2 = (isnd2 < 0.2 ? 0 : isnd2)
isnd3 = (isnd3 < 0.2 ? 0 : isnd3)
isnd4 = (isnd4 < 0.2 ? 0 : isnd4)
isnd5 = (isnd5 < 0.2 ? 0 : isnd5)
isnd6 = (isnd6 < 0.2 ? 0 : isnd6)
isnd7 = (isnd7 < 0.2 ? 0 : isnd7)
isnd8 = (isnd8 < 0.2 ? 0 : isnd8)
isnd9 = (isnd9 < 0.2 ? 0 : isnd9)
isnd10 = (isnd10 < 0.2 ? 0 : isnd10)
isnd11 = (isnd11 < 0.2 ? 0 : isnd11)
isnd12 = (isnd12 < 0.2 ? 0 : isnd12)
isnd13 = (isnd13 < 0.2 ? 0 : isnd13)
isnd14 = (isnd14 < 0.2 ? 0 : isnd14)

FLprintk2 isnd1, gihsnd1
FLprintk2 isnd2, gihsnd2
FLprintk2 isnd3, gihsnd3
FLprintk2 isnd4, gihsnd4
FLprintk2 isnd5, gihsnd5
FLprintk2 isnd6, gihsnd6
FLprintk2 isnd7, gihsnd7
FLprintk2 isnd8, gihsnd8
FLprintk2 isnd9, gihsnd9
FLprintk2 isnd10, gihsnd10
FLprintk2 isnd11, gihsnd11
FLprintk2 isnd12, gihsnd12
FLprintk2 isnd13, gihsnd13
FLprintk2 isnd14, gihsnd14


endin
;****************************************************************

;****************************************************************
; Clear single sounds, and update sound length info
;****************************************************************
        instr 201

; *** clear table
i_count = p4
tableicopy i_count, 15 ; clear table (copy from empty table)

; *** write zero as sound length to table
ktime init 0
tablew ktime, i_count, 110

;sort sound lengths, re-sort after clearing table
schedkwhen 1, 0, 1, 200, 0, 0.1, ktime, i_count ; initiate sorting of soundlength

endin
;****************************************************************

;***********************************************************************
; rhythm synthesizer, separated into 2 rhythmic levels:  grid, phrase
;***********************************************************************

;****************************************************************
; rhythm synthesizer level 1 : grid
;****************************************************************
        instr 255

kbtpo = 60 / gkbtpo ; base tempo in seconds (1 = 60 bpm)
gkbtpo_cps = 1 / kbtpo ; base tempo in cps


; *** ktrig1 is rhythmic level 1, counting/trigging the subdivisions of the grid
;ktrig1 metro gkbtpo_cps / gkout_tim1
ktrig1m oscil 1, gkbtpo_cps / gkout_tim1, 94 ; square wave
ktrig1 trigger ktrig1m, 0.5, 0

; *** trigseq supply duration and accent info for each subdivision of the grid

kloop = gkbeats ; kloop point is "group index" no
kfn_time1 init 201 ; init time signature
kfn_time1 = gktimesign1 ; set time signature

;trigseq ktrig1, 0, kloop, 0, kfn_time1, kout_ndx, kbeats, kout_tim1, kout_amp1 ; get values from table
;trigseq replacement:
gkindx255_1 init -4
gkindx255_1 = (gkindx255_1 >= kloop*3 ? -4 : gkindx255_1)
gkindx255_1 = gkindx255_1 + (ktrig1*4)
kout_ndx tablekt gkindx255_1, kfn_time1
kbeats tablekt gkindx255_1+1, kfn_time1
kout_tim1 tablekt gkindx255_1+2, kfn_time1
kout_amp1 tablekt gkindx255_1+3, kfn_time1


gkout_tim1 = kout_tim1

klastbeat = (kout_ndx == kbeats ? 1 : 0) ; set to 1 if current beat is last in a measure
gktimesign1 = (klastbeat == 1 ? gktimesign : gktimesign1) ;update current time signature at end of each measure

gkbeats = kbeats

; Drumloop trigging
klooptrig = (kout_ndx == 1 ? 1 : 0)
klooptrig1a trigger klooptrig, 0.5, 0 ; down-up gate
klooptrig1b init 0
klooptrig1b = klooptrig1b + klooptrig1a ; create step-up sequence
klooptrig1b = (klooptrig1b > 1 ? 0 : klooptrig1b) ; cyclic behaviour: 0,1,0,1...

; Trigger to reinit pitch track playback modules, jump to start of pitch track table at count 1 of a measure
aPtrkTrig upsamp klooptrig1a ; neccessary because there is no k-rate delay opcode
aPtrkTrig delay aPtrkTrig, gi_snc_delay ; sync delay trigger signal
gkPtrkTrig downsamp aPtrkTrig ; trigger to Pitch Track playback every 1 of a measure

;Force retrig drumloop when GUI actions for loop on, loop pitch and loop number select has occured
gkbtLoopOn_old init i(gkbtLoopOn)
gkdrumlop_pt_o init i(gkdrumlop_ptch)
gkDrmLopN_old init i(gkDrmLopN)
klopGUItest = gkbtLoopOn + gkdrumlop_ptch + gkDrmLopN
klopGUItest_old = gkbtLoopOn_old + gkdrumlop_pt_o + gkDrmLopN_old
klooptrig1b = (klopGUItest_old = klopGUItest ? klooptrig1b : 0) ; force trig loop if loopparams was changed via GUI
gkbtLoopOn_old = gkbtLoopOn
gkdrumlop_pt_o = gkdrumlop_ptch
gkDrmLopN_old = gkDrmLopN

klooptrig1 trigger klooptrig1b, 0.5, 0 ; down-up gate, trigs drumloop start every 2nd measure
klooptrig1 = klooptrig1 * gkbtLoopOn ; trig loop only when Loop On button is active

gkdrmoff = (klooptrig1 = 1 ? 0 : gkdrmoff ) ; reinit note-off trigger
schedkwhen klooptrig1, 0, 0,  350, gi_snc_delay, -1 ; trig drumloop, sync-delayed

gkptrnoff = (klooptrig1 = 1 ? 0 : gkptrnoff ) ; reinit note-off trigger
schedkwhen klooptrig1a, 0, 0,  261, 0, -1 ; trig patternclock

; metronome sound
kmetrotrig = ktrig1 * gkmetro_on
schedkwhen kmetrotrig, 0, 0, 340, gi_snc_delay, 1, kout_amp1 ; trig metronome sound, sync-delayed

; midi metronome
;kmetrotrigM = ktrig1 * gkmetro_onM
;schedkwhen kmetrotrigM, 0, 0, 345, gi_snc_delay, 1, kout_amp1 ; trig metronome sound, sync-delayed


; the (gi_snc_delay) delay to schedkwhen opcodes when trigging "straight" sounds make them sync
; with the live-recorded ones, as the live recorded ones have an inherent delay at the start
; of the sound, due to fade in curve when recording

; the following sets "phrase end" flag when the user changes tablenumber for the rhythm via GUI
; this faciliates user cross-combination of rhythm phrases

krytm1phrase init 0
krytm1change init 1
krytm1change = (krytm1phrase == gk_ryt_phrase ? 0 : 1) ; if rhythm table changed since last k-pass, set flag to 1
;gk_endflag = (krytm1change == 1 ? 1 : gk_endflag) ; and set "phrase end" flag
;gk_forcetrig1 = (krytm1change == 1 ? 1 : gk_forcetrig1) ; and set "force trig" flag
gktrig_phr = (krytm1change == 1 ? 1 : gktrig_phr) ; and set "trig enable" flag
krytm1phrase = gk_ryt_phrase ; then update local var from global, for comparision next k-pass

krytm2phrase init 0
krytm2change init 1
krytm2change = (krytm2phrase == gk_ryt_phrase2 ? 0 : 1) ; if rhythm table changed since last k-pass, set flag to 1
;gk_endflag2 = (krytm2change == 1 ? 1 : gk_endflag2) ; and set "phrase end" flag
;gk_forcetrig2 = (krytm2change == 1 ? 1 : gk_forcetrig2) ; and set "force trig" flag
gktrig_phr2 = (krytm2change == 1 ? 1 : gktrig_phr2) ; and set "trig enable" flag
krytm2phrase = gk_ryt_phrase2 ; then update local var from global, for comparision next k-pass

krytm3phrase init 0
krytm3change init 1
krytm3change = (krytm3phrase == gk_ryt_phrase3 ? 0 : 1) ; if rhythm table changed since last k-pass, set flag to 1
;gk_endflag3 = (krytm3change == 1 ? 1 : gk_endflag3) ; and set "phrase end" flag
gktrig_phr3 = (krytm3change == 1 ? 1 : gktrig_phr3) ; and set "trig enable" flag
krytm3phrase = gk_ryt_phrase3 ; then update local var from global, for comparision next k-pass

; the following generates phrase pauses,
; 1. watch for "end of phrase" indication
; 2. set minimum and maximum "metro ticks" pause before enabling next phrase trig
; 2. count the allowed number of metro ticks before trigging next phrase

kpause1 init 0
kpause2 init 0
kpause3 init 0

; trigger signal when a rhythmic phrase has ended
k_end1 trigger gk_endflag, 0.5, 0
k_end2 trigger gk_endflag2, 0.5, 0
k_end3 trigger gk_endflag3, 0.5, 0
; reset counter after phrase end
kpause1 = (k_end1 == 1 ? 0 : kpause1)
kpause2 = (k_end2 == 1 ? 0 : kpause2)
kpause3 = (k_end3 == 1 ? 0 : kpause3)
; reset trig_phrase to zero flag after phrase end
gktrig_phr = (k_end1 == 1 ? 0 : gktrig_phr)
gktrig_phr2 = (k_end2 == 1 ? 0 : gktrig_phr2)
gktrig_phr3 = (k_end3 == 1 ? 0 : gktrig_phr3)
; count the metroticks during pause
kpause1 = kpause1 + (ktrig1 * gk_endflag)
kpause2 = kpause2 + (ktrig1 * gk_endflag2)
kpause3 = kpause3 + (ktrig1 * gk_endflag3)
; generate random number for pause duration (number of metroticks in pause)
kpauseN1 rspline gkminpause1, gkmaxpause1, 0.2, 0.8
kpauseN2 rspline gkminpause2, gkmaxpause2, 0.2, 0.8
kpauseN3 rspline gkminpause3, gkmaxpause3, 0.2, 0.8
; when counted metroticks exceeds the wanted pause length, set flag to enable trig phrase
gktrig_phr = (kpause1 > kpauseN1 ? 1 : gktrig_phr)
gktrig_phr2 = (kpause2 > kpauseN2 ? 1 : gktrig_phr2)
gktrig_phr3 = (kpause3 > kpauseN3 ? 1 : gktrig_phr3)

; re-init, if rhythm module is turned off and then on again during the same session
gk_endflag init 1
gk_endflag2 init 1
gk_endflag3 init 1


; the following section turns on instr 6, for phrase generation, PHRASE 1
; and contains code for handling "force trig" and "loop current phrase" commands

k6off trigger gk_endflag, 0.5, 0

if gk_forcetrig1 == 1 kgoto forcetrig1 ; allow for force trigging at any time
if gkloop_phr1 == 1 kgoto skipoff1 ; allow for phrase to loop itself without turnoff/retrig from ktrig1
if gk_endflag == 0 kgoto end1 ; if no endflag is set, goto end
kgoto contin1

forcetrig1:
schedkwhen ktrig1, 0, 0, -256, 0, 1 ; turn off instr 6
schedkwhen ktrig1, 0, 1, 256, 0, -1 ; trig phrase (instr 6)
goto end1

contin1:
schedkwhen k6off, 0, 0, -256, 0, 1 ; turn off instr 6

skipoff1:
ktrig1t = ktrig1 * gktrig_phr ; phrase trigging only if both values nonzero
schedkwhen ktrig1t, 0, 1, 256, 0, -1 ; trig phrase (instr 6)

end1:

; the following section turns on instr 7, for phrase generation, PHRASE 2
; and contains code for handling "force trig" and "loop current phrase" commands

k7off trigger gk_endflag2, 0.5, 0

if gk_forcetrig2 == 1 kgoto forcetrig2 ; allow for force trigging at any time
if gkloop_phr2 == 1 kgoto skipoff2 ; allow for phrase to loop itself without turnoff/retrig from ktrig1
if gk_endflag2 == 0 kgoto end2 ; if no endflag is set, goto end
kgoto contin2

forcetrig2:
schedkwhen ktrig1, 0, 0, -257, 0, 1 ; turn off instr 7
schedkwhen ktrig1, 0, 1, 257, 0, -1 ; trig phrase (instr 7)
goto end2

contin2:
schedkwhen k7off, 0, 0, -257, 0, 1 ; turn off instr 7

skipoff2:
ktrig2 = ktrig1 * gktrig_phr2 ; phrase trigging only if both values nonzero
schedkwhen ktrig2, 0, 1, 257, 0, -1 ; trig phrase (instr 7)

end2:

; the following section turns on instr 8, for phrase generation, PHRASE 3
; and contains code for handling "force trig" and "loop current phrase" commands

k8off trigger gk_endflag3, 0.5, 0

if gk_forcetrig3 == 1 kgoto forcetrig3 ; allow for force trigging at any time
if gkloop_phr3 == 1 kgoto skipoff3 ; allow for phrase to loop itself without turnoff/retrig from ktrig1
if gk_endflag3 == 0 kgoto end3 ; if no endflag is set, goto end
kgoto contin3

forcetrig3:
schedkwhen ktrig1, 0, 0, -258, 0, 1 ; turn off instr 8
schedkwhen ktrig1, 0, 1, 258, 0, -1 ; trig phrase (instr 8)
goto end3

contin3:
schedkwhen k8off, 0, 0, -258, 0, 1 ; turn off instr 8

skipoff3:
ktrig3 = ktrig1 * gktrig_phr3 ; phrase trigging only if both values nonzero
schedkwhen ktrig3, 0, 1, 258, 0, -1 ; trig phrase (instr 8)

end3:

endin
;****************************************************************
;****************************************************************

;****************************************************************
; rhythm synthesizer level 2 : phrase1
;****************************************************************
        instr 256

; *** ktrig2is rhythmic level 2 counting/trigging the subdivisions of the grid
;ktrig2 metro gkbeatcps ; gkbeatcps is retreived from rhythm phrase table (trigseq opcode below)
ktrig2m oscil 1, gkbeatcps, 94 ; square wave
ktrig2 trigger ktrig2m, 0.5, 0

; *** trigseq supply duration and accent info for each event in the phrase
knumevents = gknumevents ; number of events in the phrase
kloop = knumevents ; kloop point is "group index" no
kfn_time2 init 301 ; table number for rhythm, phrase
kfn_time2 = i(gk_ryt_phrase) ; from GUI selector, changeable only at start of each new phrase

;trigseq ktrig2, 0, kloop, 0, kfn_time2, kout_ndx, kout_num, kout_tim2, kout_amp2, k_endflag  ; get values from table
;trigseq replacement:
gkindx256_1 init -5
gkindx256_1 = (gkindx256_1 >= kloop*4 ? -5 : gkindx256_1)
gkindx256_1 = gkindx256_1 + (ktrig2*5)
kout_ndx tablekt gkindx256_1, kfn_time2
kout_num tablekt gkindx256_1+1, kfn_time2
kout_tim2 tablekt gkindx256_1+2, kfn_time2
kout_amp2 tablekt gkindx256_1+3, kfn_time2
k_endflag tablekt gkindx256_1+4, kfn_time2


gkbeatcps = gkbtpo_cps * kout_tim2 * i(gk_ryt_fact1)
gk_endflag = k_endflag
gknumevents = kout_num

; this scheduling is for metro/phrase-tick only,
; the random player and other processes get their trig directly from gktrig
kphrasetick = ktrig2 * gkphrasetick
schedkwhen kphrasetick, 0, 0, 341, gi_snc_delay, 1, kout_amp2 ; trig metronome sound 2

gktrig = ktrig2 ; gktrig follows phrase metro
gkout_amp2 = kout_amp2

endin
;****************************************************************
;****************************************************************

;****************************************************************
; rhythm synthesizer level 2 : phrase2
;****************************************************************
        instr 257

; *** ktrig2is rhythmic level 2 counting/trigging the subdivisions of the grid
;ktrig2 metro gkbeatcps2 ; gkbeatcps is retreived from rhythm phrase table (trigseq opcode below)
ktrig2m oscil 1, gkbeatcps2, 94 ; square wave
ktrig2 trigger ktrig2m, 0.5, 0

; *** trigseq supply duration and accent info for each event in the phrase
knumevents = gknumevents2 ; number of events in the phrase
kloop = knumevents ; kloop point is "group index" no
kfn_time2 init 301 ; table number for rhythm, phrase
kfn_time2 = i(gk_ryt_phrase2) ; from GUI selector, changeable only at start of each new phrase

;trigseq ktrig2, 0, kloop, 0, kfn_time2, kout_ndx, kout_num, kout_tim2, kout_amp2, k_endflag  ; get values from table
;trigseq replacement:
gkindx257_1 init -5
gkindx257_1 = (gkindx257_1 >= kloop*4 ? -5 : gkindx257_1)
gkindx257_1 = gkindx257_1 + (ktrig2*5)
kout_ndx tablekt gkindx257_1, kfn_time2
kout_num tablekt gkindx257_1+1, kfn_time2
kout_tim2 tablekt gkindx257_1+2, kfn_time2
kout_amp2 tablekt gkindx257_1+3, kfn_time2
k_endflag tablekt gkindx257_1+4, kfn_time2


gkbeatcps2 = gkbtpo_cps * kout_tim2 * i(gk_ryt_fact2)
gk_endflag2 = k_endflag
gknumevents2 = kout_num

; this scheduling is for metro/phrase-tick only,
; the random player and other processes get their trig directly from gktrig
kphrasetick = ktrig2 * gkphrasetick2
schedkwhen kphrasetick, 0, 0, 342, gi_snc_delay, 1, kout_amp2 ; trig metronome sound 2

gktrig2 = ktrig2 ; gktrig follows phrase metro
gkout_amp22 = kout_amp2

endin
;****************************************************************
;****************************************************************

;****************************************************************
; rhythm synthesizer level 2 : phrase3
;****************************************************************
        instr 258

; *** ktrig2is rhythmic level 2 counting/trigging the subdivisions of the grid
;ktrig2 metro gkbeatcps3 ; gkbeatcps is retreived from rhythm phrase table (| opcode below)
ktrig2m oscil 1, gkbeatcps3, 94 ; square wave
ktrig2 trigger ktrig2m, 0.5, 0

; *** trigseq supply duration and accent info for each event in the phrase
knumevents = gknumevents3 ; number of events in the phrase
kloop = knumevents ; kloop point is "group index" no
kfn_time2 init 301 ; table number for rhythm, phrase
kfn_time2 = i(gk_ryt_phrase3) ; from GUI selector, changeable only at start of each new phrase

;trigseq ktrig2, 0, kloop, 0, kfn_time2, kout_ndx, kout_num, kout_tim2, kout_amp2, k_endflag  ; get values from table
;trigseq replacement:
gkindx258_1 init -5
gkindx258_1 = (gkindx258_1 >= kloop*4 ? -5 : gkindx258_1)
gkindx258_1 = gkindx258_1 + (ktrig2*5)
kout_ndx tablekt gkindx258_1, kfn_time2
kout_num tablekt gkindx258_1+1, kfn_time2
kout_tim2 tablekt gkindx258_1+2, kfn_time2
kout_amp2 tablekt gkindx258_1+3, kfn_time2
k_endflag tablekt gkindx258_1+4, kfn_time2


gkbeatcps3 = gkbtpo_cps * kout_tim2 * i(gk_ryt_fact3) * 2 ; twice the speed of "normal" rhythms
gk_endflag3 = k_endflag
gknumevents3 = kout_num
gkout_amp32 = kout_amp2

; this scheduling is for metro/phrase-tick only,
; the random player and other processes get their trig directly from gktrig
imaxinst = 0 ; 50
imintime = 0 ; 0.0001 ; (1/kr)*4

kphrasetick = ktrig2 * gkphrasetick3
schedkwhen kphrasetick, imintime, imaxinst, 343, gi_snc_delay, 1, kout_amp2 ; trig metronome sound 3
       
gktrig3 = ktrig2 ; gktrig follows phrase metro
                                                                ; gktrig3 is for RAG
endin
;****************************************************************
;****************************************************************


;****************************************************************
; rhythm synthesizer level 3 : phrase control
;****************************************************************
        instr 260
; phrase triggig control, based on poisson random distribution (average waiting time)
; this gives the possibility of a pause between rhythmic phrases
; the probable amount of pause is controlled by gklambda

; if forcetrig is enabled (gkforcetrig), a new phrase might be trigged even
; before the previous phrase has ended, allowing for cross-combination of phrases

;gk_endflag = gk_forcetrig
;gktrig_phr poisson gklambda
;gktrig_phr2 poisson gklambda2
;gktrig_phr3 poisson gklambda3

; force trig = fluctuation slow jitter with fader control for (almost) bypass

endin
;****************************************************************
;****************************************************************

;****************************************************************
; rhythm synthesizer level 4 : PatternSequencer clock & trig
;****************************************************************
        instr 261

if gkptrnoff = 0 kgoto contin
turnoff
contin:

;gkbtpo_cps ; base tempo in cps
ksubdiv = 4
ktpo = (gkbtpo_cps)*ksubdiv
;ktick metro ktpo
ktickm oscil 1, ktpo, 94 ; square wave
ktick trigger ktickm, 0.5, 0

kcount init 0
kcount = (kcount > 16 ? 1 : kcount + ktick)

if gkbtPtSeqOn == 0 goto mute ; dont't trig any events unless module is activated
imaxlength = 2.0 ; limit max length of playback, cut off very long sounds

#define PatternTrig(A'B) #

kfno$A = gkpt$Afno
ksoundlen$A table kfno$A, 110 ; get length of actual audio segment stored
ksoundlen$A = (ksoundlen$A > imaxlength ? imaxlength : ksoundlen$A) ; limit max length of playback, cut off very long sounds

ktick$A_1 trigger kcount, 0, 0
ktick$A_2 trigger kcount, 1, 0
ktick$A_3 trigger kcount, 2, 0
ktick$A_4 trigger kcount, 3, 0
ktick$A_5 trigger kcount, 4, 0
ktick$A_6 trigger kcount, 5, 0
ktick$A_7 trigger kcount, 6, 0
ktick$A_8 trigger kcount, 7, 0
ktick$A_9 trigger kcount, 8, 0
ktick$A_10 trigger kcount, 9, 0
ktick$A_11 trigger kcount, 10, 0
ktick$A_12 trigger kcount, 11, 0
ktick$A_13 trigger kcount, 12, 0
ktick$A_14 trigger kcount, 13, 0
ktick$A_15 trigger kcount, 14, 0
ktick$A_16 trigger kcount, 15, 0

ktrig_ptrn$A_1 = gkptrn$A_1 * ktick$A_1
ktrig_ptrn$A_2 = gkptrn$A_2 * ktick$A_2
ktrig_ptrn$A_3 = gkptrn$A_3 * ktick$A_3
ktrig_ptrn$A_4 = gkptrn$A_4 * ktick$A_4
ktrig_ptrn$A_5 = gkptrn$A_5 * ktick$A_5
ktrig_ptrn$A_6 = gkptrn$A_6 * ktick$A_6
ktrig_ptrn$A_7 = gkptrn$A_7 * ktick$A_7
ktrig_ptrn$A_8 = gkptrn$A_8 * ktick$A_8
ktrig_ptrn$A_9 = gkptrn$A_9 * ktick$A_9
ktrig_ptrn$A_10 = gkptrn$A_10 * ktick$A_10
ktrig_ptrn$A_11 = gkptrn$A_11 * ktick$A_11
ktrig_ptrn$A_12 = gkptrn$A_12 * ktick$A_12
ktrig_ptrn$A_13 = gkptrn$A_13 * ktick$A_13
ktrig_ptrn$A_14 = gkptrn$A_14 * ktick$A_14
ktrig_ptrn$A_15 = gkptrn$A_15 * ktick$A_15
ktrig_ptrn$A_16 = gkptrn$A_16 * ktick$A_16

schedkwhen ktrig_ptrn$A_1,  0, 0, $B, 0, ksoundlen$A*gkp$A_1dur, gkpt$Afno, gkp$A_1fm, gkp$A_1flt
schedkwhen ktrig_ptrn$A_2,  0, 0, $B, 0, ksoundlen$A*gkp$A_2dur, gkpt$Afno, gkp$A_2fm, gkp$A_2flt
schedkwhen ktrig_ptrn$A_3,  0, 0, $B, 0, ksoundlen$A*gkp$A_3dur, gkpt$Afno, gkp$A_3fm, gkp$A_3flt
schedkwhen ktrig_ptrn$A_4,  0, 0, $B, 0, ksoundlen$A*gkp$A_4dur, gkpt$Afno, gkp$A_4fm, gkp$A_4flt
schedkwhen ktrig_ptrn$A_5,  0, 0, $B, 0, ksoundlen$A*gkp$A_5dur, gkpt$Afno, gkp$A_5fm, gkp$A_5flt
schedkwhen ktrig_ptrn$A_6,  0, 0, $B, 0, ksoundlen$A*gkp$A_6dur, gkpt$Afno, gkp$A_6fm, gkp$A_6flt
schedkwhen ktrig_ptrn$A_7,  0, 0, $B, 0, ksoundlen$A*gkp$A_7dur, gkpt$Afno, gkp$A_7fm, gkp$A_7flt
schedkwhen ktrig_ptrn$A_8,  0, 0, $B, 0, ksoundlen$A*gkp$A_8dur, gkpt$Afno, gkp$A_8fm, gkp$A_8flt
schedkwhen ktrig_ptrn$A_9,  0, 0, $B, 0, ksoundlen$A*gkp$A_9dur, gkpt$Afno, gkp$A_9fm, gkp$A_9flt
schedkwhen ktrig_ptrn$A_10, 0, 0, $B, 0, ksoundlen$A*gkp$A_10dur, gkpt$Afno, gkp$A_10fm, gkp$A_10flt
schedkwhen ktrig_ptrn$A_11, 0, 0, $B, 0, ksoundlen$A*gkp$A_11dur, gkpt$Afno, gkp$A_11fm, gkp$A_11flt
schedkwhen ktrig_ptrn$A_12, 0, 0, $B, 0, ksoundlen$A*gkp$A_12dur, gkpt$Afno, gkp$A_12fm, gkp$A_12flt
schedkwhen ktrig_ptrn$A_13, 0, 0, $B, 0, ksoundlen$A*gkp$A_13dur, gkpt$Afno, gkp$A_13fm, gkp$A_13flt
schedkwhen ktrig_ptrn$A_14, 0, 0, $B, 0, ksoundlen$A*gkp$A_14dur, gkpt$Afno, gkp$A_14fm, gkp$A_14flt
schedkwhen ktrig_ptrn$A_15, 0, 0, $B, 0, ksoundlen$A*gkp$A_15dur, gkpt$Afno, gkp$A_15fm, gkp$A_15flt
schedkwhen ktrig_ptrn$A_16, 0, 0, $B, 0, ksoundlen$A*gkp$A_16dur, gkpt$Afno, gkp$A_16fm, gkp$A_16flt

#

$PatternTrig.(1'335) ; pattern 1 plays instr 335
$PatternTrig.(2'336) ; pattern 2 plays instr 336
$PatternTrig.(3'337) ; pattern 3 plays instr 337

mute:

endin
;****************************************************************
;****************************************************************


;****************************************************************
; Preset handling instruments, no 270 to 273
;****************************************************************

instr 270
i1 = i(gkPresN)
inumSnap, inumVal FLsetsnap i1
end:
endin

instr 271
i1 = i(gkPresN)
inumSnap FLgetsnap i1
endin

instr 272
FLsavesnap "C:/improsculpt/ImproSculpt2.pst"
endin

instr 273
FLloadsnap "C:/improsculpt/ImproSculpt2.pst"
endin

;****************************************************************
;****************************************************************




;****************************************************************
; analyse input amplitude,
; schedule the sampling instr,
; and give it an appropriate table number to write to
; Voice 1
;****************************************************************
        instr 302
        a1,a2 ins

if gkinputmix == 0 kgoto skipmix
        a1 = (a1 + a2) * 0.5 ; mix both inputs to sampler 1
skipmix:

        k_count init i(gk_v1_minfno)
        k_atck = gk_sampthresh1

        k_inamp rms a1, 2 ; measure volume of input signal

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihInAmp1

; gk_maxRMS1 init 0 ; maximum rms value for each sound stored
; gk_maxRMS1 = (k_inamp > gk_maxRMS1 ? k_inamp : gk_maxRMS1) ; update only when maximum is exceeded

if gk_manual1 > 0 goto manual
goto contin

manual:
        k_inamp = gk_mantrig1*10001

contin:
        k_trig trigger k_inamp, k_atck, 0 ;output 1 if signal is over threshold

        k_count = k_count+(k_trig*gk_next1) ; add 1 to k_trig if signal is over threshold, and next button active

; test if previous recorded sound was an error-recording (sound length less than 0.1 seconds)
; if error recording, go back to previous record location(ftable)
if k_trig == 0 kgoto skiptest
        ksndlen table k_count-1, 110
if ksndlen == 0 kgoto skiptest ; skip test if previous sound is cpmpletely empty, (never written to ftable)
        k_count = (ksndlen < 0.2 ? k_count -1 : k_count) ; error recording is defined as a sample shorter than 0.2 seconds
skiptest:

        k_count = (k_count > gk_v1_maxfno ? gk_v1_minfno : k_count) ; cyclic counter behaviour
; k_count = (k_count < gk_v1_minfno ? gk_v1_minfno : k_count) ; avoid "below zero" counting (after successive -1 counts)
; k_1 = 3
; k_1 = (k_1 < gk_v1_minfno ? gk_v1_minfno : k_1) ; avoid "below zero" counting (after successive -1 counts)


        k_count = (k_count == gksav1 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav2 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav3 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav4 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav5 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav6 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav7 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav8 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav9 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav10 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav11 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav12 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav13 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav14 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count

if k_count < (gk_v1_maxfno+1) kgoto skip_2ndtest
; second test to ensure correct "save" behaviour when wraparound from gk_v1_maxfno to gk_v1_minfno
        k_count = gk_v1_minfno
        k_count = (k_count == gksav1 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav2 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav3 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav4 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav5 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav6 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav7 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav8 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav9 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav10 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav11 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav12 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav13 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav14 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
skip_2ndtest:

; check time stamp of recording, used to limit sample length (turn off sampling instr after isamplen seconds)
isamplen = 5.7 ; max length of recording
ktimStamp times
ktimStart init 0
ktimStart = (k_trig == 1 ? ktimStamp : ktimStart )
ktimeLen = ktimStamp - ktimStart

;*** generate instr event for sampling /table-writing) instrument ***
schedkwhen k_trig,   0, 0,  304, 0, -1 , k_count ;note on
k_tr_off trigger k_inamp, k_atck, 1
k_tr_off2 = ( ktimeLen > isamplen ? 1 : 0 )
k_tr_off2t trigger k_tr_off2, 0.5, 0
k_tr_off3 = k_tr_off + k_tr_off2t
gk304off = k_tr_off3
k_tr_off3d vdelayk k_tr_off3, 0.2, 0.3 ; delay  note off trigger
schedkwhen k_tr_off3d, 0, 0, -304, 0, 1 , k_count ;note off

        a1d delay a1, 0.1 ; delay audio to be recorded, so rms and
                                ; control functions can set up in due time

zaw a1d, 1
;outs a1*1.1, a1*0.8 ; test, just for recording demo

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; analyse input amplitude,
; schedule the sampling instr,
; and give it an appropriate table number to write to
; Voice 2
;****************************************************************
        instr 303
        a1,a2 ins

        k_count init i(gk_v2_minfno)
        k_atck = gk_sampthresh2

        k_inamp rms a2, 2 ;measure volume of input signal

; VU meter
kVU maxk a2, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihInAmp2

; gk_maxRMS2 init 0 ; maximum rms value for each sound stored
; gk_maxRMS2 = (k_inamp > gk_maxRMS2 ? k_inamp : gk_maxRMS2) ; update only when maximum is exceeded

if gk_manual2 > 0 goto manual
goto contin

manual:
        k_inamp = gk_mantrig2*10001

contin:
        k_trig trigger k_inamp, k_atck, 0 ;output 1 if signal is over threshold

        k_count = k_count+(k_trig*gk_next2) ;add 1 to k_trig if signal is over threshold

; test if previous recorded sound was an error-recording (sound length less than 0.1 seconds)
; if error recording, go back to previous record location(ftable)
if k_trig == 0 kgoto skiptest
        ksndlen table k_count-1, 110
if ksndlen == 0 kgoto skiptest ; skip test if previous sound is cpmpletely empty, (never written to ftable)
        k_count = (ksndlen < 0.2 ? k_count -1 : k_count) ; error recording is defined as a sample shorter than 0.2 seconds
skiptest:

        k_count = (k_count > gk_v2_maxfno ? gk_v2_minfno : k_count) ;cyclic counter behaviour
; k_count = (k_count < gk_v1_minfno ? gk_v1_minfno : k_count) ; avoid "below zero" counting (after successive -1 counts)


        k_count = (k_count == gksav1 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav2 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav3 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav4 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav5 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav6 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav7 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav8 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav9 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav10 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav11 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav12 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav13 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav14 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count

if k_count < (gk_v2_maxfno+1) kgoto skip_2ndtest
; second test to ensure correct "save" behaviour when wraparound from gk_v1_maxfno to gk_v1_minfno
        k_count = gk_v2_minfno
        k_count = (k_count == gksav1 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav2 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav3 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav4 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav5 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav6 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav7 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav8 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav9 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav10 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav11 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav12 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav13 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
        k_count = (k_count == gksav14 ? k_count+1 : k_count) ; if current sound is marked "save" add 1 to k_count
skip_2ndtest:


; check time stamp of recording, used to limit sample length (turn off sampling instr after isamplen seconds)
isamplen = 5.7 ; max length of recording
ktimStamp times
ktimStart init 0
ktimStart = (k_trig == 1 ? ktimStamp : ktimStart )
ktimeLen = ktimStamp - ktimStart

;*** generate instr event for sampling /table-writing) instrument ***
schedkwhen k_trig,   0, 0,  305, 0, -1 , k_count ;note on
k_tr_off trigger k_inamp, k_atck, 1
k_tr_off2 = ( ktimeLen > isamplen ? 1 : 0 )
k_tr_off2t trigger k_tr_off2, 0.5, 0
k_tr_off3 = k_tr_off + k_tr_off2t
gk305off = k_tr_off3
k_tr_off3d vdelayk k_tr_off3, 0.2, 0.3 ; delay  note off trigger
schedkwhen k_tr_off3d, 0, 0, -305, 0, 1 , k_count ;note off

                                ; delay audio to be recorded, so rms and
        a2d delay a2, 0.1 ; control functions can set up in due time

zaw a2d, 2
;outs a1*0, a2*0.7 ; test, just for recording demo
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; table writing of audio signal from external input (ins) Voice 1
;****************************************************************
        instr 304

a1 zar 1
a0 init 0

ilength = ftlen(1) / sr ; length of recording, same as table length, all tables same length

; declick enveloping, attack and release
a_amp linseg 0, 0.05, 1, 1, 1
krel init 0
krel =  krel + gk304off ; add up each time gk304off is nonzero, this is only once for each instance of this instr
                                        ; so the adding is in effect a sample and hold mechanism
if krel == 0 kgoto norelease
aenv linseg 1, 0.2, 0, 1, 0
a_amp = a_amp * aenv
norelease:

a1 = a1 * a_amp

        i_count = p4
        k_count = i_count ; redefine as k-rate
        gkcount304 = k_count
        FLprintk2 k_count, gih102 ; print value to GUI, current sample number

;timout ilength, 10, end ; if input sound is longer than ftable,
                                        ; skip recording after ilength seconds,
                                        ; 10 seconds is set as the duration of skip-rec mode (...)

; *** table writing of input audio
        tableicopy i_count, 15 ; clear table (copy from empty table)
        kstart init 0
        kstart tablewa i_count, a1, 0 ;write audio a1 to table i_count

; *** write length of recorded sound to table
ktime timeinsts ; seconds since the start of this instr instance
tablew ktime, i_count, 110

gktime304 = ktime
gk304active = 1 ; for testing if this instr is active
end:
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; table writing of audio signal from external input (ins) Voice 2
;****************************************************************
        instr 305

a1 zar 2
a0 init 0

ilength = ftlen(1) / sr ; length of recording, same as table length, all tables same length

; declick enveloping, attack and release
a_amp linseg 0, 0.05, 1, 1, 1
krel init 0
krel =  krel + gk305off ; add up each time gk305off is nonzero, this is only once for each instance of this instr
                                        ; so the adding is in effect a sample and hold mechanism
if krel == 0 kgoto norelease
aenv linseg 1, 0.2, 0, 1, 0
a_amp = a_amp * aenv
norelease:

a1 = a1 * a_amp

        i_count = p4
        k_count = i_count ; redefine as k-rate
        gkcount305 = k_count
        FLprintk2 k_count, gih106 ; print value to GUI, current sample number

;timout ilength, 10, end ; if input sound is longer than ftable,
                                        ; skip recording after ilength seconds,
                                        ; 10 seconds is set as the duration of skip-rec mode (...)

; *** table writing of input audio
        tableicopy i_count, 15 ; clear table (copy from empty table)
        kstart init 0
        kstart tablewa i_count, a1, 0 ;write audio a1 to table i_count

; *** write length of recorded sound to table
ktime timeinsts ; seconds since the start of this instr instance
tablew ktime, i_count, 110

gktime305 = ktime
gk305active = 1 ; for testing if this instr is active
end:
        endin
;****************************************************************
;****************************************************************


;****************************************************************
; test if instr 304 is active, turn on control instrs when 304 stops
;****************************************************************
        instr 306

;for input 1
ktrig1 trigger gk304active, 0.5, 1
schedkwhen ktrig1, 0, 1, 200, 0, 0.1, gktime304, gkcount304 ; initiate sorting of soundlength when instr 304 stops
gk304active = 0

;for input 2
ktrig2 trigger gk305active, 0.5, 1
schedkwhen ktrig2, 0, 1, 200, 0, 0.1, gktime305, gkcount305 ; initiate sorting of soundlength when instr 305 stops
gk305active = 0

        endin
;****************************************************************
;****************************************************************




;****************************************************************
; random generation of events for instr 311 (sample playback) RandomPlay Voice 1
;****************************************************************
; based on rhythm-tick input from rhythm synth instr 5,6,7

        instr 310

gktrig trigger gktrig, 0.9, 0 ; make sure gktrig gives single pulses (it could hang at value 1)
k_trig = gktrig*gkbtRplay1On ; trigger from rhythm synth instr 5,6,7
kmaxins = gkRpl1poly ; max number of instr (polyphony)

; *** sound selector statements
; ******************************
; new sound select algorithm, less cpu intensive than betarand
; make random number in 0 - 1 range,
; index this number into a table containing the distribution "shape"
; multiply with krange/2 and +/-1
; offset to krange center (min + range/2)

krange = (gkRpl1fno2 - gkRpl1fno1) + 0.99 ; range of numbers wanted
kcenter = gkRpl1fno1 + (krange/2) ; center of range
krand0 randh 0.5, 10 ; uniform random
krand0 = krand0 + 0.5 ; within normalized range
kfno = (krand0*krange)+ gkRpl1fno1 ; map to range, offset with gkRpl1fno1 (first sound)
kfno = int(kfno) ; get rid of fractional part

kshort table kfno, 111 ; point to shortest sounds table,
kfno = (gkRpl1shrt == 1 ? kshort : kfno) ; select amongst the shortest sounds

if kfno = gkhide1 goto reselect ; if this sound is "hidden" from selection, select another sound
if kfno = gkhide2 goto reselect ; actually, this does not work for hiding several neighbouring sounds
if kfno = gkhide3 goto reselect ; in that case, a more sophisticated loop is needed
if kfno = gkhide4 goto reselect
if kfno = gkhide5 goto reselect
if kfno = gkhide6 goto reselect
if kfno = gkhide7 goto reselect
if kfno = gkhide8 goto reselect
if kfno = gkhide9 goto reselect
if kfno = gkhide10 goto reselect
if kfno = gkhide11 goto reselect
if kfno = gkhide12 goto reselect
if kfno = gkhide13 goto reselect
if kfno = gkhide14 goto reselect
goto no_reselect

reselect:
kfno = kfno + 1
kfo = (kfno > 14 ? 1 : kfno )
no_reselect:


; bypass sound selector in this instr, allowing a global variable to carry the sound selection value
if gks1bypas == 0 goto select_end
kfno = gks1fno
select_end:

; *** durational statements  ...(affected by playback freq/ratio)
; ******************************
k5frq = abs(gkRpl1trspo) ; positive only
k5frq = (k5frq == 0 ? 0.1 : k5frq) ; avoid zeroes
ksndlen table kfno, 110 ; get length of actual audio segment stored, update if it changes while instr is active
kdur = ksndlen / k5frq ; set duration = tablelength/sr/k5frq
; this allows instr 5 to play once thru the table for each event generated

; *** scheduling statements
; ******************************
schedkwhen k_trig, 0, kmaxins, 311, 0, kdur, kfno ; trig table playback

endin
;****************************************************************
;****************************************************************

;****************************************************************
; table playback
;****************************************************************
        instr 311

ifreq = 1
iamp = i(gkout_amp2)
iattack init 0.1
irelease init 1.0

;** select sample **
ifno = p4
isoundlen table ifno, 110 ; get length of actual audio segment stored
ilength = (ftlen(ifno) / sr) ; table length in seconds

ifno2 = i(gkRpl1mwav)

;** envelope **
        a_amp linen iamp, iattack, p3, irelease
        a_amp = a_amp * gksRplay1amp
;** oscillator and output **:

        ifnlength tableng ifno
        ifrq = 44100/ifnlength * ifreq
        kfreq = gkRpl1trspo * ifrq
        iphs init 0 ; iphs sets the starting point for reading from table
        iphs_end = isoundlen/ilength ; determine ending point for recorded sound in table, normalized value
        iphs = (i(gkRpl1trspo) < 0 ? iphs_end : iphs) ; if i(kfreq) < 0 (backwards playback), start playback from iphs_end
       
        amod = 0

;frequency modulation
        if gkRpl1fm == 0 kgoto skipFM ; conditional branch for FM

        kmodfrq = gkRpl1mfq ; 150
        kmodndx = gkRpl1mdx ; 0.01

        ;kmodfreq envelope, one breakpoint, breakpoint position set by gk5modfrqP parameter
        kmodfrqenv linseg i(gkRpl1mfqS), p3*i(gkRpl1mfqP), i(gkRpl1mfqT), p3*(1-i(gkRpl1mfqP)), i(gkRpl1mfqE)
        kmodfrq = kmodfrq * kmodfrqenv

        ;kmod-index envelope, one breakpoint, breakpoint position set by gk5modndxP parameter
        kmodndxenv linseg i(gkRpl1mdxS), p3*i(gkRpl1mdxP), i(gkRpl1mdxT), p3*(1-i(gkRpl1mdxP)), i(gkRpl1mdxE)
        kmodndx = kmodndx * kmodndxenv

        amod oscil kmodndx, kmodfrq, ifno2
skipFM:

        afreq = kfreq + amod
        a1 poscil a_amp, afreq, ifno, iphs

; output handled in instr 312
        zawm a1, 18 ; write to temporal storage channel (18)

endin

;****************************************************************
;****************************************************************

;****************************************************************
; filtering and throughput/output of signal from instr 311
;****************************************************************
        instr 312
a0 zar 18

iamp = 1
abogus rand iamp ; add low level noise, prevents underflow in the filters

a01 = a0 + abogus
; SV Filter

        alp, ahp, abp svfilter a01, gkRpl1SvCf, gkRpl1SvQ
        klp = (gkRpl1SvMd == 1 ? 1 : 0 )
        kbp = (gkRpl1SvMd == 2 ? 1 : 0 )
        khp = (gkRpl1SvMd == 3 ? 1 : 0 )
        kclean = (gkRpl1SvMd == 0 ? 1 : 0 )
        klp tonek klp, 1 ; filter selector signal, avoids clicks
        kbp tonek kbp, 1
        khp tonek khp, 1
        kclean tonek kclean, 1
        a1f mac klp,alp, kbp,abp, khp,ahp, kclean,a01 ; mix
        a1 balance a1f, a0

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsRplay1ampD


;EFX and dry out amplitudes
        zawm a1 * gkRplay1_clean * (1-gkRplay1_pan),4 ; send to clean out Left
        zawm a1 * gkRplay1_clean * gkRplay1_pan, 5 ; send to clean out Right
        zawm a1 * gkRplay1_rm , 6 ; send to ring mod
        zawm a1 * gkRplay1_fm , 7 ; send to freq mod
        zawm a1 * gkRplay1_filt1, 8 ; send to filter 1
        zawm a1 * gkRplay1_dist , 9 ; send to distrortion
        zawm a1 * gkRplay1_filt2, 10 ; send to filter 2
        zawm a1 * gkRplay1_del1 , 11 ; send to delay 1
        zawm a1 * gkRplay1_del2 , 12 ; send to delay 2
        zawm a1 * gkRplay1_revb , 13 ; send to reverb
; zawm a1, 14 ; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; random generation of events for instr 314 (sample playback)
;****************************************************************
; based on rhythm-tick input from rhythm synth instr 5,6,7

        instr 313


gktrig2 trigger gktrig2, 0.9, 0 ; make sure gktrig gives single pulses (it could hang at value 1)
k_trig = gktrig2*gkbtRplay2On ; trigger from rhythm synth instr 5,6,7
kmaxins = gkRpl2poly ; max number of instr (polyphony)

; *** sound selector statements
; ******************************
; new sound select algorithm, less cpu intensive than betarand
; make random number in 0 - 1 range,
; index this number into a table containing the distribution "shape"
; multiply with krange/2 and +/-1
; offset to krange center (min + range/2)

krange = gkRpl2fno2 - gkRpl2fno1 + 0.99 ; range of numbers wanted
kcenter = gkRpl2fno1 + (krange/2) ; center of range
krand0 randh 0.5, 10 ; uniform random
krand0 = krand0 + 0.5 ; within normalized range
kfno = (krand0*krange)+ gkRpl2fno1 ; map to range, offset with gkRpl1fno1 (first sound)

kshort table kfno, 111 ; point to shortest sounds table,
kfno = (gkRpl2shrt == 1 ? kshort : kfno) ; select amongst the sortest sounds

if kfno = gkhide1 goto reselect ; if this sound is "hidden" from selection, select another sound
if kfno = gkhide2 goto reselect ; actually, this does not work for hiding several neighbouring sounds
if kfno = gkhide3 goto reselect ; in that case, a more sophisticated loop is needed
if kfno = gkhide4 goto reselect
if kfno = gkhide5 goto reselect
if kfno = gkhide6 goto reselect
if kfno = gkhide7 goto reselect
if kfno = gkhide8 goto reselect
if kfno = gkhide9 goto reselect
if kfno = gkhide10 goto reselect
if kfno = gkhide11 goto reselect
if kfno = gkhide12 goto reselect
if kfno = gkhide13 goto reselect
if kfno = gkhide14 goto reselect
goto no_reselect

reselect:
kfno = kfno + 1
kfno = (kfno > 14 ? 1 : kfno )
no_reselect:

; bypass sound selector in this instr, allowing a global variable to carry the sound selection value
if gks2bypas == 0 goto select_end
kfno = gks2fno
select_end:

; *** durational statements  ...(affected by playback freq/ratio)
; ******************************
k52frq = abs(gkRpl2trspo) ; positive only
k52frq = (k52frq == 0 ? 0.1 : k52frq) ; avoid zeroes
ksndlen table kfno, 110 ; get length of actual audio segment stored, update if it changes while instr is active
kdur = ksndlen / k52frq ; set duration = tablelength/sr/k5frq
; this allows instr 5 to play once thru the table for each event generated

; *** scheduling statements
; ******************************
schedkwhen k_trig, 0, kmaxins, 314, 0, kdur, kfno ; trig table playback

endin
;****************************************************************
;****************************************************************

;****************************************************************
; table playback
;****************************************************************
        instr 314

ifreq = 1
iamp = i(gkout_amp22)
iattack init 0.1
irelease init 1.0


;** select sample **
ifno = p4
isoundlen table ifno, 110 ; get length of actual audio segment stored
ilength = (ftlen(ifno) / sr) ; table length in seconds

ifno2 = i(gkRpl2mwav)

;** envelope **
        a_amp linen iamp, iattack, p3, irelease
        a_amp = a_amp * gksRplay2amp
;** oscillator and output **:

        ifnlength tableng ifno
        ifrq = 44100/ifnlength * ifreq
        kfreq = gkRpl2trspo * ifrq
        iphs init 0 ; iphs sets the starting point for reading from table
        iphs_end = isoundlen/ilength ; determine ending point for recorded sound in table, normalized value
        iphs = (i(gkRpl2trspo) < 0 ? iphs_end : iphs) ; if kfreq < 0 (backwards playback), start playback from iphs_end

        amod = 0

;frequency modulation
        if gkRpl2fm == 0 kgoto skipFM ; conditional branch for FM

        kmodfrq = gkRpl2mfq ; 150
        kmodndx = gkRpl2mdx ; 0.01

        ;kmodfreq envelope, one breakpoint, breakpoint position set by gkRpl2mfqP parameter
        kmodfrqenv linseg i(gkRpl2mfqS), p3*i(gkRpl2mfqP), i(gkRpl2mfqT), p3*(1-i(gkRpl2mfqP)), i(gkRpl2mfqE)
        kmodfrq = kmodfrq * kmodfrqenv

        ;kmod-index envelope, one breakpoint, breakpoint position set by gkRpl2mdxP parameter
        kmodndxenv linseg i(gkRpl2mdxS), p3*i(gkRpl2mdxP), i(gkRpl2mdxT), p3*(1-i(gkRpl2mdxP)), i(gkRpl2mdxE)
        kmodndx = kmodndx * kmodndxenv

        amod oscil kmodndx, kmodfrq, ifno2
skipFM:

        afreq = kfreq + amod
        a1 poscil a_amp, afreq, ifno, iphs

; output handled in instr 315
        zawm a1, 19 ; write to temporal storage channel (18)

endin

;****************************************************************
;****************************************************************

;****************************************************************
; filtering and throughput/output of signal from instr 314
;****************************************************************
        instr 315
a0 zar 19

iamp = 1
abogus rand iamp ; add low level noise, prevents underflow in the filters
a01 = a0 + abogus

; SV Filter

        alp, ahp, abp svfilter a01, gkRpl2SvCf, gkRpl2SvQ
        klp = (gkRpl2SvMd == 1 ? 1 : 0 )
        kbp = (gkRpl2SvMd == 2 ? 1 : 0 )
        khp = (gkRpl2SvMd == 3 ? 1 : 0 )
        kclean = (gkRpl2SvMd == 0 ? 1 : 0 )
        klp tonek klp, 1 ; filter selector signal, avoids clicks
        kbp tonek kbp, 1
        khp tonek khp, 1
        kclean tonek kclean, 1
        a1f mac klp,alp, kbp,abp, khp,ahp, kclean,a01 ; mix
        a1 balance a1f, a0

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsRplay2ampD


;EFX and dry out amplitudes
        zawm a1 * gkRplay2_clean * (1-gkRplay2_pan), 4 ; send to clean out Left
        zawm a1 * gkRplay2_clean * gkRplay2_pan, 5 ; send to clean out Right
        zawm a1 * gkRplay2_rm , 6 ; send to ring mod
        zawm a1 * gkRplay2_fm , 7 ; send to freq mod
        zawm a1 * gkRplay2_filt1, 8 ; send to filter 1
        zawm a1 * gkRplay2_dist , 9 ; send to distrortion
        zawm a1 * gkRplay2_filt2, 10 ; send to filter 2
        zawm a1 * gkRplay2_del1 , 11 ; send to delay 1
        zawm a1 * gkRplay2_del2 , 12 ; send to delay 2
        zawm a1 * gkRplay2_revb , 13 ; send to reverb
; zawm a1, 15; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; granulated playback
;****************************************************************

;****************************************************************
; voice 1
;****************************************************************

        instr 321

;** envelope **
        iamp = 0.65
        kamp = gksGrain1amp*gkveloc
        amp interp kamp

;** lfo **
klfo oscil gkGrn1lfA, gkGrn1lfq, 93

;** random offset for timepoint **
krand rand gkGrn1rndA



;** granule setup **:

iolaps = 400
ifna = i(gkGrn1sel)
ifna = (ifna == 0 ? i(gkcount304) : ifna) ; if sound select = zero, use last recorded sound
ifnb = 101
itotdur = 6000
ilength = (ftlen(ifna) / sr) ; table length in seconds
kifna = ifna ; force update sound length stored in table 110
ksndlen table kifna, 110 ; get length of actual audio segment stored, update if it changes while instr is active

;reading of midi values:
gkGrn1form_mc = gkGrn1form * gkbend2midi ; moved from midi instr
gkGrn1oct_mc = gkGrn1oct + gkctrl2midi ; moved from midi instr

;gk6phs ="Time Ratio", -1, 2
kcps = gkGrn1trat ; time ratio, 1 is "original" speed
kcps = kcps / ilength ; timeratio / table-length in seconds
;kphs phasor kcps
kphs oscili 1, kcps, 99 ; alternative to clean phasor, ramp and hold

;manual time pointer
kphs_m = gkGrn1mPhs
kphs_m tonek kphs_m, 10 ; smooth out manual time pointer
kphs = (gkGrn1mTim == 1 ? kphs_m : kphs)
kphs = kphs + klfo + krand ; add lfo and random offset to time pointer
kphs = kphs * (ksndlen/ilength) ; scale kphs so that it points only to the part of the table actually used to store audio

;gk6form = "Transposition factor"
kform = gkGrn1form_mc / ilength

; grain shape/length params
kband = gkGrn1bw * gkGrn1grfq ; should gk6fund affect this ??
kdur = gkGrn1dur / gkGrn1grfq ; gk6dur controls the amount of grain overlaps
;kdur = (gkGrn1grfq > 100 ? kdur+(gkGrn1grfq*0.0001): kdur) ; hack, longer kdur during high grain freq
kris = gkGrn1ris * kdur ; rise time as a fractional part of kdur (0 < gk6ris < 1 )
kdec = gkGrn1dec * kdur ; as for rise time

;** oscillator and output **:

a1 fof2 iamp, gkGrn1grfq, kform, gkGrn1oct_mc, kband, kris, kdur, kdec, iolaps, ifna, ifnb, itotdur, kphs, gkGrn1gli
a1 = a1 * amp
krms rms a1
krms1 table krms, 125
arms interp krms1
a1 = a1 * arms

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsGrain1ampD


;EFX and dry out amplitudes
        zawm a1 * gkGrain1_clean * (1-gkGrain1_pan), 4 ; send to clean out Left
        zawm a1 * gkGrain1_clean * gkGrain1_pan, 5 ; send to clean out Right
        zawm a1 * gkGrain1_rm , 6 ; send to RingMod
        zawm a1 * gkGrain1_fm , 7 ; send to FreqMod
        zawm a1 * gkGrain1_filt1, 8 ; send to Filter1
        zawm a1 * gkGrain1_dist , 9 ; send to Distortion
        zawm a1 * gkGrain1_filt2, 10 ; send to Filter2
        zawm a1 * gkGrain1_del1 , 11 ; send to Delay1
        zawm a1 * gkGrain1_del2 , 12 ; send to Delay2
        zawm a1 * gkGrain1_revb , 13 ; send to Reverb
; zawm a1, 16 ; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; voice 2
;****************************************************************

        instr 322

;** envelope **
        iamp = 0.65
        kamp = iamp * gksGrain2amp

;** lfo **
klfo oscil gkGrn2lfA, gkGrn2lfq, 93

;** random offset for timepoint **
krand rand gkGrn2rndA

;** granule setup **:

iolaps = 400
ifna = i(gkGrn2sel)
ifna = (ifna == 0 ? i(gkcount304) : ifna) ; if sound select = zero, use last recorded sound
ifnb = 101
itotdur = 6000
ilength = (ftlen(ifna) / sr) ; table length in seconds
kifna = ifna ; force update sound length stored in table 110
ksndlen table kifna, 110 ; get length of actual audio segment stored, update if it changes while instr is active

;gk6phs ="Time Ratio", -1, 2
kcps = gkGrn2trat ; time ratio, 1 is "original" speed
kcps = kcps / ilength ; timeratio / table-length in seconds
;kphs phasor kcps
kphs oscil 1, kcps, 99 ; alternative to clean phasor, ramp and hold

;manual time pointer
kphs_m = gkGrn2mPhs
kphs_m tonek kphs_m, 10 ; smooth out manual time pointer
kphs = (gkGrn2mTim == 1 ? kphs_m : kphs)
kphs = kphs + klfo + krand ; add lfo and random offset to time pointer
kphs = kphs * (ksndlen/ilength) ; scale kphs so that it points only to the part of the table actually used to store audio

;gk6form = "Transposition factor"
kform = gkGrn2form / ilength

; grain shape/length params
kband = gkGrn2bw * gkGrn2grfq ; should gk6fund affect this ??
kdur = gkGrn2dur / gkGrn2grfq ; gk6dur controls the amount of grain overlaps
kris = gkGrn2ris * kdur ; rise time as a fractional part of kdur (0 < gk6ris < 1 )
kdec = gkGrn2dec * kdur ; as for rise time

;** oscillator and output **:

a1 fof2 kamp, gkGrn2grfq, kform, gkGrn2oct, kband, kris, kdur, kdec, iolaps, ifna, ifnb, itotdur, kphs, gkGrn2gli
krms rms a1
krms1 table krms, 125
arms interp krms1
a1 = a1 * arms

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsGrain2ampD


;EFX and dry out amplitudes
        zawm a1 * gkGrain2_clean * (1-gkGrain2_pan), 4 ; send to clean out Left
        zawm a1 * gkGrain2_clean * gkGrain2_pan, 5 ; send to clean out Right
        zawm a1 * gkGrain2_rm , 6 ; send to RingMod
        zawm a1 * gkGrain2_fm , 7 ; send to FreqMod
        zawm a1 * gkGrain2_filt1, 8 ; send to Filter1
        zawm a1 * gkGrain2_dist , 9 ; send to Distortion
        zawm a1 * gkGrain2_filt2, 10 ; send to Filter2
        zawm a1 * gkGrain2_del1 , 11 ; send to Delay1
        zawm a1 * gkGrain2_del2 , 12 ; send to Delay2
        zawm a1 * gkGrain2_revb , 13 ; send to Reverb
; zawm a1, 17 ; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; voice 3
;****************************************************************

        instr 323

;** envelope **
        iamp = 0.65
        kamp = iamp * gksGrain3amp

;** lfo **
klfo oscil gkGrn3lfA, gkGrn3lfq, 93

;** random offset for timepoint **
krand rand gkGrn3rndA

;** granule setup **:

iolaps = 400
ifna = i(gkGrn3sel)
ifna = (ifna == 0 ? i(gkcount304) : ifna) ; if sound select = zero, use last recorded sound
ifnb = 101
itotdur = 6000
ilength = (ftlen(ifna) / sr) ; table length in seconds
kifna = ifna ; force update sound length stored in table 110
ksndlen table kifna, 110 ; get length of actual audio segment stored, update if it changes while instr is active

;gk6phs ="Time Ratio", -1, 2
kcps = gkGrn3trat ; time ratio, 1 is "original" speed
kcps = kcps / ilength ; timeratio / table-length in seconds
kphs phasor kcps
kphs oscil 1, kcps, 99 ; alternative to clean phasor, ramp and hold
                       
;manual time pointer
kphs_m = gkGrn3mPhs
kphs_m tonek kphs_m, 10 ; smooth out manual time pointer
kphs = (gkGrn3mTim == 1 ? kphs_m : kphs)
kphs = kphs + klfo + krand ; add lfo and random offset to time pointer
kphs = kphs * (ksndlen/ilength) ; scale kphs so that it points only to the part of the table actually used to store audio

;gk6form = "Transposition factor"
kform = gkGrn3form / ilength

; grain shape/length params
kband = gkGrn3bw * gkGrn3grfq ; should gk6fund affect this ??
kdur = gkGrn3dur / gkGrn3grfq ; gk6dur controls the amount of grain overlaps
kris = gkGrn3ris * kdur ; rise time as a fractional part of kdur (0 < gk6ris < 1 )
kdec = gkGrn3dec * kdur ; as for rise time

;** oscillator and output **:

a1 fof2 kamp, gkGrn3grfq, kform, gkGrn3oct, kband, kris, kdur, kdec, iolaps, ifna, ifnb, itotdur, kphs, gkGrn3gli
krms rms a1
krms1 table krms, 125
arms interp krms1
a1 = a1 * arms

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsGrain3ampD


;EFX and dry out amplitudes
        zawm a1 * gkGrain3_clean * (1-gkGrain3_pan), 4 ; send to clean out Left
        zawm a1 * gkGrain3_clean * gkGrain3_pan, 5 ; send to clean out Right
        zawm a1 * gkGrain3_rm , 6 ; send to RingMod
        zawm a1 * gkGrain3_fm , 7 ; send to FreqMod
        zawm a1 * gkGrain3_filt1, 8 ; send to Filter1
        zawm a1 * gkGrain3_dist , 9 ; send to Distortion
        zawm a1 * gkGrain3_filt2, 10 ; send to Filter2
        zawm a1 * gkGrain3_del1 , 11 ; send to Delay1
        zawm a1 * gkGrain3_del2 , 12 ; send to Delay2
        zawm a1 * gkGrain3_revb , 13 ; send to Reverb
; zawm a1, 18 ; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; voice 4
;****************************************************************

        instr 324

;** envelope **
        iamp = 0.65
        kamp = iamp * gksGrain4amp

;** lfo **
klfo oscil gkGrn4lfA, gkGrn4lfq, 93

;** random offset for timepoint **
krand rand gkGrn4rndA

;** granule setup **:

iolaps = 400
ifna = i(gkGrn4sel)
ifna = (ifna == 0 ? i(gkcount304) : ifna) ; if sound select = zero, use last recorded sound
ifnb = 101
itotdur = 6000
ilength = (ftlen(ifna) / sr) ; table length in seconds
kifna = ifna ; force update sound length stored in table 110
ksndlen table kifna, 110 ; get length of actual audio segment stored, update if it changes while instr is active

;gk6phs ="Time Ratio", -1, 2
kcps = gkGrn4trat ; time ratio, 1 is "original" speed
kcps = kcps / ilength ; timeratio / table-length in seconds
kphs phasor kcps
kphs oscil 1, kcps, 99 ; alternative to clean phasor, ramp and hold

;manual time pointer
kphs_m = gkGrn4mPhs
kphs_m tonek kphs_m, 10 ; smooth out manual time pointer
kphs = (gkGrn4mTim == 1 ? kphs_m : kphs)
kphs = kphs + klfo + krand ; add lfo and random offset to time pointer
kphs = kphs * (ksndlen/ilength) ; scale kphs so that it points only to the part of the table actually used to store audio

;gk6form = "Transposition factor"
kform = gkGrn4form / ilength

; grain shape/length params
kband = gkGrn4bw * gkGrn4grfq ; should gk6fund affect this ??
kdur = gkGrn4dur / gkGrn4grfq ; gk6dur controls the amount of grain overlaps
kris = gkGrn4ris * kdur ; rise time as a fractional part of kdur (0 < gk6ris < 1 )
kdec = gkGrn4dec * kdur ; as for rise time

;** oscillator and output **:

a1 fof2 kamp, gkGrn4grfq, kform, gkGrn4oct, kband, kris, kdur, kdec, iolaps, ifna, ifnb, itotdur, kphs, gkGrn4gli
krms rms a1
krms1 table krms, 125
arms interp krms1
a1 = a1 * arms

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsGrain4ampD


;EFX and dry out amplitudes
        zawm a1 * gkGrain4_clean * (1-gkGrain4_pan), 4 ; send to clean out Left
        zawm a1 * gkGrain4_clean * gkGrain4_pan, 5 ; send to clean out Right
        zawm a1 * gkGrain4_rm , 6 ; send to RingMod
        zawm a1 * gkGrain4_fm , 7 ; send to FreqMod
        zawm a1 * gkGrain4_filt1, 8 ; send to Filter1
        zawm a1 * gkGrain4_dist , 9 ; send to Distortion
        zawm a1 * gkGrain4_filt2, 10 ; send to Filter2
        zawm a1 * gkGrain4_del1 , 11 ; send to Delay1
        zawm a1 * gkGrain4_del2 , 12 ; send to Delay2
        zawm a1 * gkGrain4_revb , 13 ; send to Reverb
; zawm a1, 19 ; to output file
        endin
;****************************************************************
;****************************************************************

;****************************************************************
;  Random Access Single Granulator, voice 1, control instr
;****************************************************************
        instr 330

; durational statements
kdur = gkRAGdur + (rnd(gkRAGrdur*gkRAGdur))

; time pointer statements (what part of the sound to use)
; phasor moves through the soundfile
; manual pointer sets location
; random offset added to any of the two above
; lfo added to any of the same two

krand = birnd(gkRAGrphs) ; random timepoint variation
klfo oscil gkRAGlfA, gkRAGlfq, 93 ; lfo for timepoint

kcps = gkRAGtrat ; time ratio, in cps ...
kphs phasor kcps
;kphs oscil 1, kcps, 99 ; alternative to clean phasor, ramp and hold

;manual time pointer
kphs_m = gkRAGmPhs
kphs_m tonek kphs_m, 10 ; smooth out manual time pointer
kphs = (gkRAGmTim == 1 ? kphs_m : kphs)
kphs = kphs + klfo + krand ; add lfo and random offset to time pointer
kphs = kphs % 1 ; no kphs above 1, wrap around (modulo 1)
kphs = (kphs < 0 ? 0 : kphs) ; avoid kphs below zero, crashes poscil/Csound

; generate event
imintime = 0
imaxinst = 0
krag = gktrig3 * gkbtRAGOn
schedkwhen krag, imintime, imaxinst, 331, gi_snc_delay, kdur, kphs ; trig Random Access Granulator

        endin
;****************************************************************
;****************************************************************

;****************************************************************
;  Random Access Single Granulator, voice 1, audio instr
;****************************************************************
        instr 331

;*********
; amp envelope, with rise and decay control

iamp = i(gksRAGamp*gkout_amp32*2)

irise = i(gkRAGris)*p3
irise = (irise < 0.01 ? 0.01 : irise) ; will click if irise is too low
idur = p3
idec = i(gkRAGdec)*p3
idec = (idec < 0.01 ? 0.01 : idec) ; will click if idec is too low
ifn = 101
iatss = 1 ; steady state, may implement a knob for this one
iatdec = 0.01
;amp envlpx iamp, irise, idur, idec, ifn, iatss, iatdec
amp linen iamp, irise, idur, idec


ifno = i(gkRAGsel) ; select original sound to read audio grains from
isndlen table ifno, 110 ; get length of actual audio segment stored

ilength = (ftlen(ifno) / sr) ; table length in seconds

; ioffset normalized value from p4
iphs = (p4*isndlen) / ilength

ifreq = 1 ; original playback rate
ifnlength tableng ifno ; table length in samples
ifrq = 44100/ifnlength * ifreq
kfreq = gkRAGtrspo * ifrq ; playback rate value from GUI
kfr_rand rspline 0, gkRAGrpch, 0.1, 7 ; random pitch variation
kfreq = kfreq + (kfreq * kfr_rand)

        a1 poscil amp, kfreq, ifno, iphs


;a1 oscil 1000, 440, 93
; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsRAGampD


;EFX and dry out amplitudes
        zawm a1 * gkRAG_clean * (1-gkRAG_pan), 4 ; send to clean out Left
        zawm a1 * gkRAG_clean * gkRAG_pan, 5 ; send to clean out Right
        zawm a1 * gkRAG_rm,     6 ; send to RingMod
        zawm a1 * gkRAG_fm,     7 ; send to FreqMod
        zawm a1 * gkRAG_filt1,   8 ; send to Filter1
        zawm a1 * gkRAG_dist,   9 ; send to Distortion
        zawm a1 * gkRAG_filt2, 10 ; send to Filter2
        zawm a1 * gkRAG_del1,   11 ; send to Delay1
        zawm a1 * gkRAG_del2,   12 ; send to Delay2
        zawm a1 * gkRAG_revb,   13 ; send to Reverb
; zawm a1, 20 ; to output file
        endin
;****************************************************************
;****************************************************************


;****************************************************************
; table playback for pattern sequencer
;****************************************************************
        instr 335

ifno = p4
ifrq = 0.1682281494140625 ; 44100/ifnlength * icps
iamp = i(gksPtSeqamp)

ifadein = i(gkp1fdin*p3) + 0.008
ifadeout = i(gkp1fdout*p3) + 0.012
ifmfreq = i(gkp1fmfrq)
ifmindx = p5* i(gkp1fmindx)
ifiltQ = i(gkp1fltQ)
ifiltfrq = p6 * i(gkp1fltfrq)

amod oscil ifmindx, ifmfreq, 93
a1 poscil iamp, ifrq+amod, ifno

iampB = 1
abogus rand iampB ; add low level noise, prevents underflow in the filters

a1f, ahigh, aband svfilter a1, ifiltfrq, ifiltQ
a1f balance a1f, a1
idur = p3 - ifadein - ifadeout ; sustain part of sound
idur = (idur < 0.01 ? 0.01 : idur ) ; avoid zero duration
;aenv linen 1, ifadein, idur, ifadeout
aenv expseg 0.1, ifadein, 1.1, idur, 1.1, ifadeout, 0.1, 1, 0.1
a1f = a1f * (aenv-0.1)

;EFX and dry out amplitudes

        zawm a1f * gkPtn1_clean * (1-gkPtn1_pan), 4 ; send to clean out Left
        zawm a1f * gkPtn1_clean * gkPtn1_pan, 5 ; send to clean out Right
        zawm a1f * gkPtn1_rm , 6 ; send to ring mod
        zawm a1f * gkPtn1_fm , 7 ; send to freq mod
        zawm a1f * gkPtn1_filt1, 8 ; send to filter 1
        zawm a1f * gkPtn1_dist , 9 ; send to distrortion
        zawm a1f * gkPtn1_filt2, 10 ; send to filter 2
        zawm a1f * gkPtn1_del1 , 11 ; send to delay 1
        zawm a1f * gkPtn1_del2 , 12 ; send to delay 2
        zawm a1f * gkPtn1_revb , 13 ; send to reverb
        zawm a1f, 14 ; to VU meter

        endin

;****************************************************************
; table playback for pattern sequencer
;****************************************************************
        instr 336

ifno = p4
ifrq = 0.1682281494140625 ; 44100/ifnlength * icps
iamp = i(gksPtSeqamp)

ifadein = i(gkp2fdin*p3) + 0.008
ifadeout = i(gkp2fdout*p3) + 0.012
ifmfreq = i(gkp2fmfrq)
ifmindx = p5* i(gkp2fmindx)
ifiltQ = i(gkp2fltQ)
ifiltfrq = p6 * i(gkp2fltfrq)

amod oscil ifmindx, ifmfreq, 93
a1 poscil iamp, ifrq+amod, ifno

iampB = 1
abogus rand iampB ; add low level noise, prevents underflow in the filters

a1f, ahigh, aband svfilter a1, ifiltfrq, ifiltQ
a1f balance a1f, a1
idur = p3 - ifadein - ifadeout ; sustain part of sound
idur = (idur < 0.01 ? 0.01 : idur ) ; avoid zero duration
;aenv linen 1, ifadein, idur, ifadeout
aenv expseg 0.1, ifadein, 1.1, idur, 1.1, ifadeout, 0.1, 1, 0.1
a1f = a1f * (aenv-0.1)

;EFX and dry out amplitudes

        zawm a1f * gkPtn2_clean * (1-gkPtn2_pan), 4 ; send to clean out Left
        zawm a1f * gkPtn2_clean * gkPtn2_pan, 5 ; send to clean out Right
        zawm a1f * gkPtn2_rm , 6 ; send to ring mod
        zawm a1f * gkPtn2_fm , 7 ; send to freq mod
        zawm a1f * gkPtn2_filt1, 8 ; send to filter 1
        zawm a1f * gkPtn2_dist , 9 ; send to distrortion
        zawm a1f * gkPtn2_filt2, 10 ; send to filter 2
        zawm a1f * gkPtn2_del1 , 11 ; send to delay 1
        zawm a1f * gkPtn2_del2 , 12 ; send to delay 2
        zawm a1f * gkPtn2_revb , 13 ; send to reverb
        zawm a1f, 14 ; to VU meter

        endin
;****************************************************************
; table playback for pattern sequencer
;****************************************************************
        instr 337

ifno = p4
ifrq = 0.1682281494140625 ; 44100/ifnlength * icps
iamp = i(gksPtSeqamp)

ifadein = i(gkp3fdin*p3) + 0.008
ifadeout = i(gkp3fdout*p3) + 0.012
ifmfreq = i(gkp3fmfrq)
ifmindx = p5* i(gkp3fmindx)
ifiltQ = i(gkp3fltQ)
ifiltfrq = p6 * i(gkp3fltfrq)

amod oscil ifmindx, ifmfreq, 93
a1 poscil iamp, ifrq+amod, ifno

iampB = 1
abogus rand iampB ; add low level noise, prevents underflow in the filters

a1f, ahigh, aband svfilter a1, ifiltfrq, ifiltQ
a1f balance a1f, a1
idur = p3 - ifadein - ifadeout ; sustain part of sound
idur = (idur < 0.01 ? 0.01 : idur ) ; avoid zero duration
;aenv linen 1, ifadein, idur, ifadeout
aenv expseg 0.1, ifadein, 1.1, idur, 1.1, ifadeout, 0.1, 1, 0.1
a1f = a1f * (aenv-0.1)


;EFX and dry out amplitudes

        zawm a1f * gkPtn3_clean * (1-gkPtn3_pan), 4 ; send to clean out Left
        zawm a1f * gkPtn3_clean * gkPtn3_pan, 5 ; send to clean out Right
        zawm a1f * gkPtn3_rm , 6 ; send to ring mod
        zawm a1f * gkPtn3_fm , 7 ; send to freq mod
        zawm a1f * gkPtn3_filt1, 8 ; send to filter 1
        zawm a1f * gkPtn3_dist , 9 ; send to distrortion
        zawm a1f * gkPtn3_filt2, 10 ; send to filter 2
        zawm a1f * gkPtn3_del1 , 11 ; send to delay 1
        zawm a1f * gkPtn3_del2 , 12 ; send to delay 2
        zawm a1f * gkPtn3_revb , 13 ; send to reverb
        zawm a1f, 14 ; to VU meter

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; metronome instr (Bass Drum)
;****************************************************************
        instr 340
iamp = p4 * 5000
a1 loscil iamp, 1, 40, 1
        outs a1, a1
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; phrase metronome instr (hihat)
;****************************************************************
        instr 341
iamp = p4 * 10000
a1 loscil iamp, 1, 41, 1
        outs a1, a1
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; phrase2 metronome instr (hihat)
;****************************************************************
        instr 342
iamp = p4 * 2000
a1 loscil iamp, 0.5, 41, 1
        outs a1, a1
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; phrase3 metronome instr (hihat)
;****************************************************************
        instr 343
iamp = p4 * 8000
a1 loscil iamp, 1.5, 41, 1
        outs a1, a1
        endin
;****************************************************************
;****************************************************************



;****************************************************************
; midi out metronome instr
;****************************************************************
        instr 345

iamp = p4 * 10000
a1 loscil iamp, 1, 40, 1
        outs a1, a1

noteondur2 1, 60, 100, 0.3


        endin
;****************************************************************
;****************************************************************


;****************************************************************
; drumloop instr, loop should fill exactly one measure of the current time signature
;****************************************************************
        instr 350

ilowcut = 50
ilowcut2 = 30

kampR init 1 ; release envelope
krinflag init 1 ; reinit for release flag
ireltime = 0.2

if gkdrmoff = 0 kgoto contin
if krinflag < 1 goto skip_rin ; reinit only once, at start of release stage
reinit release
krinflag = 0
skip_rin:
timout 0, ireltime, release
turnoff

release:
kampR linseg 1, ireltime, 0, 1, 0
rireturn
contin:

iamp = 0.68
kamp = gkDrmLopAm * iamp * gksLoopamp * kampR

; DrumLoop
ifno =  i(gkDrmLopN) + 250 ; select table number
ilength = ftlen(ifno) ; get number of samples in table
iorig = sr / ilength ; get "original pitch", so that a kcps=1 through the loop in 1 second
icps init 0.5
icps = i(gkdrumlop_ptch)
kcps = (gkbtpo_cps * 0.25) * icps
a1o,a2o loscil kamp, kcps, ifno, iorig, 1, 1, ilength/2

abogus rand 0.1 ; bogus signal, to feed the filters when instrument is active and silent,
                                                ; prevents underflow in filters

a1o = a1o + abogus
a2o = a2o + abogus

a1f butterhp a1o, ilowcut ; low freq cut
a2f butterhp a2o, ilowcut ; low freq cut
a1 butterhp a1f, ilowcut2 ; low freq cut
a2 butterhp a2f, ilowcut2 ; low freq cut

; beat cutting
ibps = i(gkbtpo_cps)
isubdiv = i(gkDLsubdiv)
ibarlength = i(gkDLbarlen)
iphrasebars = i(gkDLphrbar)
inumrepeats = i(gkDLnumrep)
istutterspeed = i(gkDLstuspd)
istutterchance = i(gkDLsturnd*0.01)
ienvchoice   = i(gkDLenv)
a1b bbcutm a2, ibps, isubdiv, ibarlength, iphrasebars, inumrepeats , istutterspeed, istutterchance, ienvchoice  
a2b bbcutm a2, ibps, isubdiv, ibarlength, iphrasebars, inumrepeats , istutterspeed, istutterchance, ienvchoice

a1 = (a1 * (1-gkDLbbmix)) + (a1b * gkDLbbmix) ; mix/balance of original and bbcut loop
a2 = (a2 * (1-gkDLbbmix)) + (a2b * gkDLbbmix) ; mix/balance of original and bbcut loop

; BassLoop
;ifno2 = (ifno < 64 ? 58 : 59 )
;ilength2= ftlen(ifno2) ; get number of samples in table
;kamp2 = kamp * gkBasLopAm
;a3o loscil kamp2, kcps, ifno2, iorig, 1, 1, ilength2/2
;a3o = a3o + abogus ; prevent filter underflow
;a3f butterhp a3o, ilowcut ; low freq cut
;a3 butterhp a3f, ilowcut2 ; low freq cut
;a1 = a1 + a3
;a2 = a2 + a3

; VU meter
kVU maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsLoopampD


;EFX and dry out amplitudes
        zawm a1 * gkLoop_clean * (1-gkLoop_pan), 4 ; send to clean out Left
        zawm a2 * gkLoop_clean * gkLoop_pan, 5 ; send to clean out Right
        zawm a1 * gkLoop_rm,     6 ; send to RingMod
        zawm a1 * gkLoop_fm,     7 ; send to FreqMod
        zawm a1 * gkLoop_filt1,   8 ; send to Filter1
        zawm a1 * gkLoop_dist,   9 ; send to Distortion
        zawm a1 * gkLoop_filt2, 10 ; send to Filter2
        zawm a1 * gkLoop_del1,   11 ; send to Delay1
        zawm a1 * gkLoop_del2,   12 ; send to Delay2
        zawm a1 * gkLoop_revb,   13 ; send to Reverb
; zawm a1, 21 ; to output fileL
; zawm a2, 22 ; to output fileR

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Pad 1, Gui controlled by note on buttons
;****************************************************************

        instr 360
iorig = 647 ;(e)
iamp = 3000
kamp = iamp * gksPadamp
icps1 = cpspch(p4) * 1.0001
icps2 = cpspch(p4) * 0.9999

a1 loscil kamp, icps1, 90, iorig
a2 loscil kamp, icps2, 90, iorig
ao = (a1 + a2) * 0.5

; VU meter
kVU maxk ao, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsPadampD


;EFX and dry out amplitudes

        zawm a1 * gkPad_clean * (1-gkPad_pan), 4 ; send to clean out Left
        zawm a2 * gkPad_clean * gkPad_pan, 5 ; send to clean out Right
        zawm ao * gkPad_rm , 6 ; send to RingMod
        zawm ao * gkPad_fm , 7 ; send to FreqMod
        zawm ao * gkPad_filt1, 8 ; send to Filter1
        zawm ao * gkPad_dist , 9 ; send to Distortion
        zawm ao * gkPad_filt2, 10 ; send to Filter2
        zawm ao * gkPad_del1 , 11 ; send to Delay1
        zawm ao * gkPad_del2 , 12 ; send to Delay2
        zawm ao * gkPad_revb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Intro text reading, for rehearsal
;****************************************************************
        instr 398


        endin

;****************************************************************
;****************************************************************




;****************************************************************
; EFX channel "keep it alive instr",
;****************************************************************
; this instr runs bogus/unhearable audio values through the efx/output channels
; this stabilizes the audio patching channels and thus avoids dropouts
; it's a hack, it works around the underflow bug of intel processors

        instr 401

aVU zar 14 ; mixed signal from PatternSequencer, for VU

; VU meter
kVU maxk aVU, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsPtSeqampD


; prevents underflow in filters
iamp = 1
a1 rand iamp

;EFX and dry out amplitudes

        zawm a1, 4 ; send to clean out Left
        zawm a1, 5 ; send to clean out Right
        zawm a1, 6 ; send to RingMod
        zawm a1, 7 ; send to FreqMod
        zawm a1, 8 ; send to Filter1
        zawm a1, 9 ; send to Distortion
        zawm a1, 10 ; send to Filter2
        zawm a1, 11 ; send to Delay1
        zawm a1, 12 ; send to Delay2
        zawm a1, 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************


;****************************************************************
; Ring Mod1 instr
;****************************************************************
        instr 491

        a1 zar 6
        a1 = a1 / 32768

        kmodfrq = gkfx_rm_mfrq ; modulator freq
        kbal = gkfx_rm_mndx ; modulation index (balance)
        krms rms a1, 5 ; get rms of input signal
        kampmod = krms * gkfx_rm_afrq / 32000 ; amount of amp->freq
        kmodfrq = kmodfrq + (kmodfrq*kampmod) ; input amp modifies mod freq
        klfo oscil gkfx_rm_lamt, gkfx_rm_lfrq, 93 ; make lfo
        kmodfrq = kmodfrq + (kmodfrq*klfo) ; lfo modifies mod freq
        amod oscil 1, kmodfrq, 93 ; modulator oscil
        arm = a1 * amod ; calculate ring mod
        aout = ((arm * kbal) + (a1 * (1-kbal)) ) * 32768
        aout = aout * gksRngModamp

; VU meter
kVU maxk aout, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsRngModampD


;EFX and dry out amplitudes
        zawm aout * gkfx_rm_dry * (1-gkpanRngMod), 4 ; send to clean out Left
        zawm aout * gkfx_rm_dry * gkpanRngMod, 5 ; send to clean out Right
        zawm aout * gkfx_rm_fm  , 7 ; send to FreqMod
        zawm aout * gkfx_rm_flt1, 8 ; send to Filter1
        zawm aout * gkfx_rm_dist, 9 ; send to Distortion
        zawm aout * gkfx_rm_flt2, 10 ; send to Filter2
        zawm aout * gkfx_rm_dly1, 11 ; send to Delay1
        zawm aout * gkfx_rm_dly2, 12 ; send to Delay2
        zawm aout * gkfx_rm_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Freq Mod effect instr
;****************************************************************
        instr 492

;frequency modulation implemented as an a-rate variable delay line
        a1 zar 7

        kmodfrq = gkfx_fm_mfrq ; modulator freq
        kmodndx = gkfx_fm_mndx*0.1 ; modulation index
        krms rms a1, 5 ; get rms of input signal
        kampmod = krms * gkfx_fm_afrq / 32000 ; amount of amp->freq
        kmodfrq = kmodfrq + (kmodfrq*kampmod) ; input amp modifies mod freq
        klfo oscil gkfx_fm_lamt, gkfx_fm_lfrq, 93 ; make lfo
        kmodfrq = kmodfrq + (kmodfrq*klfo) ; lfo modifies mod freq

        imaxdel = 1 ; lower is CPU-cheaper
; imaxdel = 2
; iwinsiz = 8
        iwinsiz = 4 ; lower is CPU-cheaper

        amod oscil kmodndx, kmodfrq, 93
        amod = amod + kmodndx + 0.001
        acar vdelayx a1, amod, imaxdel, iwinsiz

        acar = acar * gksFrqModamp

; VU meter
kVU maxk acar, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsFrqModampD


;EFX and dry out amplitudes
        zawm acar * gkfx_fm_dry * (1-gkpanFrqMod), 4 ; send to clean out Left
        zawm acar * gkfx_fm_dry * gkpanFrqMod, 5 ; send to clean out Right
        zawm acar * gkfx_fm_flt1, 8 ; send to Filter1
        zawm acar * gkfx_fm_dist, 9 ; send to Distortion
        zawm acar * gkfx_fm_flt2, 10 ; send to Filter2
        zawm acar * gkfx_fm_dly1, 11 ; send to Delay1
        zawm acar * gkfx_fm_dly2, 12 ; send to Delay2
        zawm acar * gkfx_fm_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Filter 1  instr
;****************************************************************
        instr 493

        a1 zar 8

        kfreq = gkfx_f1_cfrq ; filter freq
        kq = gkfx_f1_q*(kfreq*0.5) ; filter Q
        krms rms a1, 5 ; get rms of input signal
        kampmod = krms * gkfx_f1_afrq / 32000 ; amount of amp->freq
        kfreq = kfreq + (kfreq*kampmod) ; input amp modifies freq
        klfo oscil gkfx_f1_lamt, gkfx_f1_lfrq, 93 ; make lfo
        kfreq = kfreq + (kfreq*klfo) ; lfo modifies freq
        kfreq = (kfreq > 20000 ? 20000 : kfreq) ; limit upper range to 20000
        kfreq = (kfreq < 20 ? 20 : kfreq) ; limit lower range to 20

        alp,ahp,abp svfilter a1, kfreq, kq
        alp balance alp, a1
        abp balance abp, a1
        ahp balance ahp, a1
        ares mac gkfx_f1_lp, alp, gkfx_f1_bp, abp, gkfx_f1_hp, ahp ; add and multiply
        ares = ares * gksFilt1amp

; VU meter
kVU maxk ares, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsFilt1ampD


;EFX and dry out amplitudes
        zawm ares * gkfx_f1_dry * (1-gkpanFilt1), 4 ; send to clean out Left
        zawm ares * gkfx_f1_dry * gkpanFilt1, 5 ; send to clean out Right
        zawm ares * gkfx_f1_dist, 9 ; send to Distortion
        zawm ares * gkfx_f1_flt2, 10 ; send to Filter2
        zawm ares * gkfx_f1_dly1, 11 ; send to Delay1
        zawm ares * gkfx_f1_dly2, 12 ; send to Delay2
        zawm ares * gkfx_f1_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Distortion  instr
;****************************************************************
        instr 494

        a1 zar 9

        kpregain = gkfx_ds_drv
        krms rms a1, 5 ; get rms of input signal
        kampmod = krms * gkfx_ds_adrv / 32000 ; amount of amp->freq
        kpregain = kpregain + (kpregain*kampmod) ; input amp modifies dist drive (+/- range)
        kpostgain = (0.5 / kpregain) * (kpregain*0.5) ; auto set output gain corresponding to input drive
        kshape1 = gkfx_ds_shp*2
        kshape2 = gkfx_ds_shp

        adist distort1 a1, kpregain, kpostgain, kshape1, kshape2
        aout rezzy adist, gkfx_ds_pflt*0.4, 2 ; post dist filter
        aout = aout * gksDistamp

; VU meter
kVU maxk aout, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsDistampD


;EFX and dry out amplitudes
        zawm aout * gkfx_ds_dry * (1-gkpanDist), 4 ; send to clean out Left
        zawm aout * gkfx_ds_dry * gkpanDist, 5 ; send to clean out Right
        zawm aout * gkfx_ds_flt2, 10 ; send to Filter2
        zawm aout * gkfx_ds_dly1, 11 ; send to Delay1
        zawm aout * gkfx_ds_dly2, 12 ; send to Delay2
        zawm aout * gkfx_ds_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; Filter 2  instr
;****************************************************************
        instr 495

        a1 zar 10
        kfreq = gkfx_f2_cfrq ; filter freq
        kres = gkfx_f2_res ; filter bandwidth
        kdist = gkfx_f2_dst ; filter dist
        krms rms a1 ; get rms of input signal
        kampmod = krms * gkfx_f2_afrq / 32000 ; amount of amp->freq
        kfreq = kfreq + (kfreq*kampmod) ; input amp modifies mod freq
        klfo oscil gkfx_f2_lamt, gkfx_f2_lfrq, 93 ; make lfo
        kfreq = kfreq + (kfreq*klfo) ; lfo modifies mod freq
        kfreq = (kfreq > 20000 ? 20000 : kfreq) ; limit upper range to 20000
        kfreq = (kfreq < 20 ? 20 : kfreq) ; limit lower range to 20

        a2 = a1 / 32000
        ares lpf18 a2, kfreq, kres, kdist
        ares balance ares, a2
        ares = ares * 32000 * gksFilt2amp

; VU meter
kVU maxk ares, gkupdate1, 0

        FLsetVal gkupdate1, kVU, gihsFilt2ampD


;EFX and dry out amplitudes
        zawm ares * gkfx_f2_dry * (1-gkpanFilt2), 4 ; send to clean out Left
        zawm ares * gkfx_f2_dry * gkpanFilt2, 5 ; send to clean out Right
        zawm ares * gkfx_f2_dly1, 11 ; send to Delay1
        zawm ares * gkfx_f2_dly2, 12 ; send to Delay2
        zawm ares * gkfx_f2_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; delay 1  instr
;****************************************************************
        instr 496
; Delay 1:
; Xfeed ??

        a1 zar 11
        kinlevl = 1 ; input level
        kfblevl = gkfx_d1_fb ; feedback level
        kffrq = gkfx_d1_flt ; feedback filter freq
        kfineL = gkfx_d1_timfL ; Left  delay time fine adjust
        kfineR = gkfx_d1_timfR ; Right delay time fine adjust

        klfo oscil gkfx_d1_lfrq, 1, 93
        klfoL = (klfo * gkfx_d1_lamtL)+ gkfx_d1_lamtL ; range and offset
        klfoR = (klfo * gkfx_d1_lamtR)+ gkfx_d1_lamtR ; range and offset


        imaxdel = 14 ; maximum delay time
        kbtpo init 4 ; init in case unlink on
if gkfx_d1_unl = 1 kgoto contin ; skip master tempo synchronizing if "unlink" is active
        kbtpo = 240 / gkbtpo ; sync to master tempo
contin:
        kmult = kbtpo / gkfx_d1_timul ; multiply, master delay tempo factor
        kdeltL = kmult / (gkfx_d1_subL * gkfx_d1_noteL); calculate subdivision and note value
        kdeltR = kmult / (gkfx_d1_subR * gkfx_d1_noteR); calculate subdivision and note value
        kdeltL = kdeltL + (kdeltL*kfineL) + (kdeltL*klfoL) ; fine tune and LFO
        kdeltR = kdeltR + (kdeltR*kfineR) + (kdeltR*klfoR) ; fine tune and LFO
; FLprintk2 kdeltL, gih1651vL ; print to GUI
; FLprintk2 kdeltR, gih1651vR ; print to GUI
; FLsetVal gkupdate1, kdeltL, gihDel1timL ; print to GUI
; FLsetVal gkupdate1, kdeltR, gihDel1timR ; print to GUI

        adeltL upsamp kdeltL ; smoothing
        adeltR upsamp kdeltR ; smoothing
        adeltL tone adeltL, 20 ; smoothing
        adeltR tone adeltR, 20 ; smoothing

        adummy delayr imaxdel ; establish delay line
        adelayL deltapi adeltL ; tap delay Left
        adelwL = (a1*kinlevl) + (adelayL*kfblevl) ; mix input and feedback
        adelwL butterlp adelwL, kffrq ; filter delay signal
                delayw adelwL ; write source to delay line

        adummy delayr imaxdel ; establish delay line
        adelayR deltapi adeltR ; tap delay Right
        adelwR = (a1*kinlevl) + (adelayR*kfblevl) ; mix input and feedback
        adelwR butterlp adelwR, kffrq ; filter delay signal
                delayw adelwR ; write source to delay line


        amono = (adelayL + adelayR ) * 0.5 * gksDel1amp
        adelayL = adelayL * gksDel1amp
        adelayR = adelayR * gksDel1amp

; VU meter
kVU maxk amono, gkupdate1, 0

        FLsetVal gkupdate1, kVU*2, gihsDel1ampD ; double VU-meter values for Delay, just my taste


;EFX and dry out amplitudes

        zawm adelayL * gkfx_d1_dry * (1-gkpanDel1),4 ; send to clean out Left
        zawm adelayR * gkfx_d1_dry * gkpanDel1, 5 ; send to clean out Right
        zawm amono * gkfx_d1_dly2, 12 ; send to Delay2
        zawm amono * gkfx_d1_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; delay 2  instr
;****************************************************************
        instr 497

        a1 zar 12
        kinlevl = 1 ; input level
        kfblevl = gkfx_d2_fb ; feedback level
        kffrq = gkfx_d2_flt ; feedback filter freq
        kfineL = gkfx_d2_timfL ; Left  delay time fine adjust
        kfineR = gkfx_d2_timfR ; Right delay time fine adjust

        klfo oscil gkfx_d2_lfrq, 1, 93
        klfoL = (klfo * gkfx_d2_lamtL)+ gkfx_d2_lamtL ; range and offset
        klfoR = (klfo * gkfx_d2_lamtR)+ gkfx_d2_lamtR ; range and offset


        imaxdel = 14 ; maximum delay time
        kbtpo init 4 ; init in case unlink on
if gkfx_d2_unl = 1 kgoto contin ; skip master tempo synchronizing if "unlink" is active
        kbtpo = 240 / gkbtpo ; sync to master tempo
contin:
        kmult = kbtpo / gkfx_d2_timul ; multiply, master delay tempo factor
        kdeltL = kmult / (gkfx_d2_subL * gkfx_d2_noteL); calculate subdivision and note value
        kdeltR = kmult / (gkfx_d2_subR * gkfx_d2_noteR); calculate subdivision and note value
        kdeltL = kdeltL + (kdeltL*kfineL) + (kdeltL*klfoL) ; fine tune and LFO
        kdeltR = kdeltR + (kdeltR*kfineR) + (kdeltR*klfoR) ; fine tune and LFO
; FLprintk2 kdeltL, gih1751vL ; print to GUI
; FLprintk2 kdeltR, gih1751vR ; print to GUI
; FLsetVal gkupdate1, kdeltL, gihDel2timL ; print to GUI
; FLsetVal gkupdate1, kdeltR, gihDel2timR ; print to GUI

        adeltL upsamp kdeltL ; smoothing
        adeltR upsamp kdeltR ; smoothing
        adeltL tone adeltL, 20 ; smoothing
        adeltR tone adeltR, 20 ; smoothing

        adummy delayr imaxdel ; establish delay line
        adelayL deltapi adeltL ; tap delay Left
        adelwL = (a1*kinlevl) + (adelayL*kfblevl) ; mix input and feedback
        adelwL butterlp adelwL, kffrq ; filter delay signal
                delayw adelwL ; write source to delay line

        adummy delayr imaxdel ; establish delay line
        adelayR deltapi adeltR ; tap delay Right
        adelwR = (a1*kinlevl) + (adelayR*kfblevl) ; mix input and feedback
        adelwR butterlp adelwR, kffrq ; filter delay signal
                delayw adelwR ; write source to delay line


        amono = (adelayL + adelayR ) * 0.5 * gksDel2amp
        adelayL = adelayL * gksDel2amp
        adelayR = adelayR * gksDel2amp

; VU meter
kVU maxk amono, gkupdate1, 0

        FLsetVal gkupdate1, kVU*2, gihsDel2ampD ; double VU-meter values for Delay, just my taste


;EFX and dry out amplitudes

        zawm adelayL * gkfx_d2_dry * (1-gkpanDel2),4 ; send to clean out Left
        zawm adelayR * gkfx_d2_dry * gkpanDel2, 5 ; send to clean out Right
        zawm amono * gkfx_d2_rvb , 13 ; send to Reverb

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; WG reverb instr
;****************************************************************

; 8 delay line FDN reverb, with feedback matrix based upon
; physical modeling scattering junction of 8 lossless waveguides
; of equal characteristic impedance. Based on Julius O. Smith III,
; "A New Approach to Digital Reverberation using Closed Waveguide
; Networks," Proceedings of the International Computer Music
; Conference 1985, p. 47-53 (also available as a seperate
; publication from CCRMA), as well as some more recent papers by
; Smith and others.
;
; Coded by Sean Costello, October 1999.
; Small modifications by Oeyvind Brandtsegg, 2001.

        instr 498        

ain zar 13 ; input signal

kpre = gkfx_rv_pdly*1000 ; predelay is in millisecs
a1 vdelay ain, kpre, 1000 ; Pre Delay

inlevl = 0.5 ; input level
ioutlevl = 0.5 ; output level
klfroll tonek gkfx_rv_lf, 0.1 ; LF rolloff freq

kgain tonek gkfx_rv_tim, 0.1 ; gain of reverb. Adjust empirically
                ; for desired reverb time. .6 gives
                ; a good small "live" room sound, .8
                ; a small hall, .9 a large hall,
                ; .99 an enormous stone cavern.

kpitchmod tonek gkfx_rv_pmod, 0.1 ; amount of random pitch modulation
                ; for the delay lines. 1 is the "normal"
                ; amount, but this may be too high for
                ; held pitches such as piano tones.
                ; Adjust to taste.

ktone tonek gkfx_rv_hf, 0.1 ; Cutoff frequency of lowpass filters
                ; in feedback loops of delay lines,
                ; in Hz. Lower cutoff frequencies results
                ; in a sound with more high-frequency
                ; damping.

       
afilt1 init 0
afilt2 init 0
afilt3 init 0
afilt4 init 0
afilt5 init 0
afilt6 init 0
afilt7 init 0
afilt8 init 0

; Delay times chosen to be prime numbers.
; Works with sr=44100 ONLY. If you wish to
; use a different delay time, find some new
; prime numbers that will give roughly the
; same delay times for the new sampling rate.
; Or adjust to taste.
idel1 = (2473.000/sr)
idel2 = (2767.000/sr)
idel3 = (3217.000/sr)
idel4 = (3557.000/sr)
idel5 = (3907.000/sr)
idel6 = (4127.000/sr)
idel7 = (2143.000/sr)
idel8 = (1933.000/sr)

; k1-k8 are used to add random pitch modulation to the
; delay lines. Helps eliminate metallic overtones
; in the reverb sound.
k1      randi   .001, 3.1, .06
k2      randi   .0011, 3.5, .9
k3      randi   .0017, 1.11, .7
k4      randi   .0006, 3.973, .3
k5      randi   .001, 2.341, .63
k6      randi   .0011, 1.897, .7
k7      randi   .0017, 0.891, .9
k8      randi   .0006, 3.221, .44

; apj is used to calculate "resultant junction pressure" for
; the scattering junction of 8 lossless waveguides
; of equal characteristic impedance. If you wish to
; add more delay lines, simply add them to the following
; equation, and replace the .25 by 2/N, where N is the
; number of delay lines.
apj = .25 * (afilt1 + afilt2 + afilt3 + afilt4 + afilt5 + afilt6 + afilt7 + afilt8)

a1 = a1 * inlevl

adum1   delayr  1
adel1   deltapi idel1 + k1 * kpitchmod
        delayw  a1 + apj - afilt1

adum2   delayr  1
adel2   deltapi idel2 + k2 * kpitchmod
        delayw  a1 + apj - afilt2

adum3   delayr  1
adel3   deltapi idel3 + k3 * kpitchmod
        delayw  a1 + apj - afilt3

adum4   delayr  1
adel4   deltapi idel4 + k4 * kpitchmod
        delayw  a1 + apj - afilt4

adum5   delayr  1
adel5   deltapi idel5 + k5 * kpitchmod
        delayw  a1 + apj - afilt5

adum6   delayr  1
adel6   deltapi idel6 + k6 * kpitchmod
        delayw  a1 + apj - afilt6

adum7   delayr  1
adel7   deltapi idel7 + k7 * kpitchmod
        delayw  a1 + apj - afilt7

adum8   delayr  1
adel8   deltapi idel8 + k8 * kpitchmod
        delayw  a1 + apj - afilt8

; 1st order lowpass filters in feedback
; loops of delay lines.
afilt1  tone    adel1 * kgain, ktone
afilt2  tone    adel2 * kgain, ktone
afilt3  tone    adel3 * kgain, ktone
afilt4  tone    adel4 * kgain, ktone
afilt5  tone    adel5 * kgain, ktone
afilt6  tone    adel6 * kgain, ktone
afilt7  tone    adel7 * kgain, ktone
afilt8  tone    adel8 * kgain, ktone

; The outputs of the delay lines are summed
; and sent to the stereo outputs. This could
; easily be modified for a 4 or 8-channel
; sound system.
aoutL = (afilt1 + afilt3 + afilt5 + afilt7) * ioutlevl * gksRevbamp
aoutL buthp aoutL, klfroll
aoutR = (afilt2 + afilt4 + afilt6 + afilt8) * ioutlevl * gksRevbamp
aoutR buthp aoutR, klfroll

; VU meter
kVU maxk aoutL, gkupdate1, 0

        FLsetVal gkupdate1, kVU*2, gihsRevbampD ; double VU-meter values for Reverb, just my taste


;Send to output
        zawm aoutL * (1-gkpanRevb), 4 ; send to clean out Left (no clean amp control needed)
        zawm aoutR * gkpanRevb, 5 ; send to clean out Right (no clean amp control needed)

endin
;****************************************************************
;****************************************************************

;****************************************************************
; dry out, stereo
;****************************************************************
        instr 499
a1 zar 4
a2 zar 5

a1 = a1 * gksMastamp
a2 = a2 * gksMastamp

a1 clip a1, 2, 32000, 0.75
a2 clip a2, 2, 32000, 0.75


; VU meter
kVUl maxk a1, gkupdate1, 0

        FLsetVal gkupdate1, kVUl, gihsMLampD

kVUr maxk a2, gkupdate1, 0

        FLsetVal gkupdate1, kVUr, gihsMRampD


outs a1, a2
        endin
;****************************************************************
;****************************************************************

;****************************************************************
; write output soundfiles
;****************************************************************
        instr 500
a1,a2 ins

a3 zar 4
a4 zar 5

; decrease amplitude by *0.8
; and soft limit
; safety for 16 bit file writing ...
a1 clip a1*0.6, 0, 32000, 0.9
;a2 clip a2*0.6, 0, 32000, 0.9
a3 clip a3*0.6, 0, 32000, 0.9
a4 clip a4*0.6, 0, 32000, 0.9

        soundout a1, "E:in1.wav", 4
; soundout a2, "E:in2.wav", 4

        soundout a3, "E:mixL.wav", 4
        soundout a4, "E:mixR.wav", 4

        endin
;****************************************************************
;****************************************************************

;****************************************************************
; clear zak
;****************************************************************
        instr 501
        zacl 0,24
        endin
;****************************************************************
;****************************************************************


</CsInstruments>


<CsScore>

;audio tables
f1  0  262144  7   0   32768   0   ; bogus table, empty
f2  0  262144  7   0   32768   0   ; bogus table, empty
f3  0  262144  7   0   32768   0   ; bogus table, empty
f4  0  262144  7   0   32768   0   ; bogus table, empty
f5  0  262144  7   0   32768   0   ; bogus table, empty
f6  0  262144  7   0   32768   0   ; bogus table, empty
f7  0  262144  7   0   32768   0   ; bogus table, empty
f8  0  262144  7   0   32768   0   ; bogus table, empty
f9  0  262144  7   0   32768   0   ; bogus table, empty
f10  0  262144  7   0   32768   0   ; bogus table, empty
f11  0  262144  7   0   32768   0   ; bogus table, empty
f12  0  262144  7   0   32768   0   ; bogus table, empty
f13  0  262144  7   0   32768   0   ; bogus table, empty
f14  0  262144  7   0   32768   0   ; bogus table, empty
f15  0  262144  7   0   32768   0   ; bogus table, kept empty to clear other tables by tablecopy
; old table size: 131072


;control, pitch/amp
f21  0  262144  7   0   32768   0   ; bogus table, empty, for pitchtracker
f22  0  262144  7   0   32768   0   ; bogus table, empty, amptracking
f23  0  262144  7   0   32768   0   ; bogus table, empty, for pitchtracker
f24  0  262144  7   0   32768   0   ; bogus table, empty, amptracking
f25  0  262144  7   0   32768   0   ; bogus table, empty, for pitchtracker
f26  0  262144  7   0   32768   0   ; bogus table, empty, amptracking
f27  0  262144  7   0   32768   0   ; bogus table, empty, for pitchtracker
f28  0  262144  7   0   32768   0   ; bogus table, empty, amptracking



f40   0  0   1  "BD_1016.wav"  0  0  0
f41   0  0   1  "D4closed2.wav"  0  0  0
f84   0  0   1  "PadWsSeq1_C2.aif"  0  0  0
f85   0  0   1  "PadWsSeq1_C3.aif"  0  0  0
f86   0  0   1  "PadWsSeq1_C4.aif"  0  0  0
f87   0  0   1  "PadWsSeq1_C5.aif"  0  0  0
f88   0  0   1  "PadWsSeq1_C6.aif"  0  0  0
f89   0  0   1  "PadWsSeq1_C7.aif"  0  0  0
f90   0  0   1  "PadWs_E.aif"  0  0  0
f251  0  0  -1  "improsculpt_set1_1.wav"  0  0  0
f252  0  0  -1  "improsculpt_set1_2.wav"  0  0  0
f253  0  0  -1  "improsculpt_set1_3.wav"  0  0  0
f254  0  0  -1  "improsculpt_set1_4.wav"  0  0  0


f91 0 128    7   0   64   1   0   -1   64   0 ; saw
f92 0 128    7   0   32   1   64  -1   32   0 ; tri
f93 0 65536 10   1     ; sine
f94 0 128    7   0   0    1   64   1   0   -1   64   -1 ; square
f95 0 1024   7   0  4 1 196 0.9 624 -0.9 196 -1 4 0 ;saw wave, supersaw

f99 0 2048    7   0   1024   1    1024  1 ; ramp up, then hold

f101 0   8192 19  .5  1  270  1 ; sigmoid rise/decay shape for fof2, half cycle from bottom to top
f102 0   8192 19  1   1  270  1 ; sigmoid rise/decay shape for fof2, full cycle start and end at bottom. for RAG
;f103 0   8192 16 ;  rise and decay shape for RAG
;0 512 4
;0.5 512 -4
;1 6144 0
;1 512 4
;0.5 512 -4
;0
f103 0 8192 7 0 512 0.8 512 1 6144 1 512 0.8 512 0 ; alternate table, because gen16 is buggy

f110 0   64 7 0 64 0 ; empty table for storing length of recorded audio segments
f111 0   64 -2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; table for storing sorted indexes to f110, based on ascending length
                                                                ; f111 initialized as 1,2,3,4,5 etcetera
f112 0   64 7 0 64 0 ; empty table for temp storage in sorting values from f111
f113 0   64 7 0 64 0 ; empty table for clearing ftable 112


;f122 0   1024 5  0.1 1024 1500 ; exp shape 1 for grain freq
f122 0   1024 8  3 128 7 128 30 128 60 128 120 128 240 128 580 128 1160 128 2220
;f123 0   128 19  .5  1  270  1 ; sigmoid rise, for grain freq
f123 0    128  7  1 12 4 12 15 12 36 92 92 ; tuned "by hand/ear/preference" table for grain freq

f125 0    32768  7  1 4096 1 4096 0.8 8192 0.6 16384 0.4 ; amplitude limiter table

;f130 0   1024 16  0 1024 -4 1 ; convex curve 1, for reverb time knob ...
f130 0   8192 19  .5  1  270  1 ; sigmoid rise, alternate table because gen16 is buggy

f132 0  32  -2  36 46 52 60 72 84 96 110

f149 0   1024  -7  0.5  512  1  512  2 ; pitch bend table

f150 0     32  -2   ; step function for pitch shifting in semitone steps

;0,249999984027651637144924968445418
;0,264865758077886289209637356336585
;0,280615497137047449413538943420162
;0,29730176450485741560276115096665
;0,314980249057786202592489697562695
;0,333709951105534249335867171697835
;0,353553379299117742957550774915221
;0,374576759247719111218809912399082
;0,39685025454054215750112512810106
;0,420448200911311869866830281705846
;0,445449354326921298715908597429949
;0,471937153828198452593582541949786
0.5 ; down one octave
0.529731516155772578419274712673169 ; down 11 semotones
0.561230994274094898827077886840325 ; down 10 semitones
0.5946035290097148312055223019333 ; ...
0.62996049811557240518497939512539
0.66741990221106849867173434339567
0.707106758598235485915101549830442
0.749153518495438222437619824798164
0.79370050908108431500225025620212
0.840896401822623739733660563411692
0.890898708653842597431817194859898
0.943874307656396905187165083899571 ; down 1 semitone
1 ; original pitch
1.0594631 ; up 1 semitone
1.12246206026161 ; up 2 semitones
1.189207133997152141591 ; ...
1.2599210767267381991016397921
1.33483988970424790530864050922162
1.41421360754972056892679873068552
1.49830713271681035808894985628814
1.58740111958026332409302889048759
1.68179291109397648015990507670554
1.78179753114564871299730152827219 ; up 10 semitones
1.887748735919915536983131368778 ; up 11 semitones
2.00000012777879506655031300767278 ; up one octave


f180 0 32  -2 0.0625 0.125 0.25 0.5 1 ; table for drumloop playback frequency ratios (1/4, 1/2, normal, x2, x4)
f181 0 32  -2 0.5 1 2 4     ; table for phrase tempo factor
f182 0 32  -2 2 4 8 16     ; table for delaytime subdiv factor
f183 0 32  -2 1 1.333 1.5     ; table for delaytime note value factor
f184 0 32  -2 0.5 1 2 3 4 5 6 7 8     ; table for delaytime factor
f185 0 32  -2 0.25 0.5 1 2 4     ; table for freq multiply factor

f198 0 128 7  1 128 0 ; tempest masking table, for taptempo

;ftables 200 -> 299 sets time signature
;contains delta times and amplitudes in the following format:
;part_index  numbeats time amp  
;part_index is not used in any instr, just for reference
f201 0 32  -2  
1   4 1  1.00
2   4 1  0.20
3   4 1  0.50
4   4 1  0.25

f202 0 32  -2  
1   5 1  1.00
2   5 1  0.30
3   5 1  0.60
4   5 1  1.00
5   5 1  0.50

f203 0 32  -2  
1   3 1  1.00
2   3 1  0.20
3   3 1  0.50

f204 0 32  -2  
1   3 0.5  1.00
2   3 0.5  0.20
3   3 0.5  0.50

f205 0 32  -2  
1   5 0.5  1.00
2   5 0.5  0.20
3   5 0.5  1.00
4   5 0.5  0.50
5   5 0.5  0.10

f206 0 32  -2  
1   7 0.5  1.00
2   7 0.5  0.20
3   7 0.5  0.50
4   7 0.5  0.20
5   7 0.5  1.00
6   7 0.5  0.20
7   7 0.5  0.40

f207 0 32  -2  
1   3 0.25  1.00
2   3 0.25  0.20
3   3 0.25  0.50

f208 0 32  -2  
1   5 0.25  1.00
2   5 0.25  0.20
3   5 0.25  0.50
4   5 0.25  0.90
5   5 0.25  0.50




;ftables 300 -> 307 contains rhythmic phrases
;delta times and amplitudes in the following format:
;part_index  num_events time  amp  endflag
;endflag should be set to 1 at end of each phrase
;part_index is not used in any instr, just for reference

;values for different notes :
; whole = 0.25
; half = 0.5
; 4dot = 0.666
; hlftri= 0.75
; 4th = 1
; 8dot = 1.33
; 4tri = 1.5
; 8th = 2
; 8tri = 3
;16th = 4
;16tri = 6
;32nd = 8

f301 0 128  -2  
1   5  0.5 1.00 0
2   5  0.5 0.60 0
3   5  0.666 0.90 0
4   5  0.666 1.00 0
5   5  0.5 1.00 1

f302 0 128  -2  
1   8   0.333 1.00 0
2   8   0.5 0.80 0
3   8   1 0.60 0
4   8   0.5 0.90 0
5   8   2 0.50 0
6   8   0.666 0.75 0
7   8   0.333 0.20 0
8   8   0.333 0.60 1

f303 0 128  -2  
1  11   0.666 1.00 0
2  11   2 0.50 0
3  11   0.5 0.70 0
4  11   1 0.30 0
5  11   0.333 0.90 0
6  11   1 0.50 0
7  11   1 0.60 0
8  11   0.666 0.70 0
9  11   2 0.40 0
10 11   2 0.50 0
11 11   0.666 0.90 0

f304 0 128  -2  
1  17   1 1.00 0
2  17   1 0.40 0
3  17   1 0.60 0
4  17   1 0.80 0
5  17   0.666 0.90 0
6  17   2 0.30 0
7  17   0.666 0.70 0
8  17   2 0.40 0
9  17   0.5 0.50 0
10 17   2 0.50 0
11 17   0.666 0.90 0
12 17   2 0.80 0
13 17   2 0.80 0
14 17   0.5 0.50 0
15 17   0.666 0.70 0
16 17   2 0.40 0
17 17   0.5 0.50 1

f305 0 128  -2  
1   9   1.333 1.00 0
2   9   1.333 0.90 0
3   9   1 0.80 0
4   9   2 0.30 0
5   9   2 0.50 0
6   9   0.5 0.80 0
7   9   2 0.40 0
8   9   2 0.60 0
9   9   1 0.90 1

f306 0 128  -2  
1  14   2 1.00 0
2  14   4 0.20 0
3  14   4 0.30 0
4  14   2 0.20 0
5  14   0.666 0.75 0
6  14   2 1.00 0
7  14   4 0.20 0
8  14   4 0.30 0
9  14   2 0.20 0
10 14   1 0.75 0
11 14   2 1.00 0
12 14   4 0.20 0
13 14   4 0.30 0
14 14   2 0.60 1

f307 0 128  -2  
1  10   4 1.00 0
2  10   4 0.20 0
3  10   1 0.30 0
4  10   4 1.00 0
5  10   4 0.20 0
6  10   1 0.30 0
7  10   2 1.00 0
8  10   4 0.50 0
9  10   1.333 0.50 0
10 10   1 0.80 1

f308 0 128  -2  
1  23   4 1.00 0
2  23   4 0.90 0
3  23   4 0.80 0
4  23   4 0.70 0
5  23   4 0.70 0
6  23   4 0.70 0
7  23   4 0.70 0
8  23   4 0.70 0
9  23   4 0.75 0
10 23   4 0.80 0
11 23   4 0.85 0
12 23   4 0.90 0
13 23   1.33 1.00 0
14 23   4 0.80 0
15 23   1 1.00 0
16 23   1 0.20 0
17 23   4 0.80 0
18 23   4 0.40 0
19 23   1 0.50 0
20 23   1 0.60 0
21 23   2 0.70 0
22 23   2 0.80 0
23 23   2 0.90 1


;not in use !! check out as variation
f309 0 64  -2  
1   10   2 1.00 0
2   10   2 0.40 0
3   10   1 0.60 0
4   10   0.5 0.70 0
5   10   2 0.20 0
6   10   2 0.40 0
7   10   2 0.60 0
8   10   1 0.80 0
9   10   2 0.50 0
10  10   1 0.70 1



f501  0 16  2  1 ; bogus ftable, force loading more than 309 ftables .... hack

; *******************

i1   0 60000

i260  0 60000
i306  0 60000 ; control instr, testing if instr 304 is active
i310  0 60000 ; Rplay1 event generator, initiate instr 311 events
i312  0 60000 ; filtering and throughput/output of signal from instr 311
i313  0 60000 ; Rplay2 event generator, initiate instr 314 events
i315  0 60000 ; filtering and throughput/output of signal from instr 314

i401  0 60000
i491  0 60000
i492  0 60000
i493  0 60000
i494  0 60000
i495  0 60000
i496  0 60000
i497  0 60000
i498  0 60000
i499  0 60000
;i500 0 60000 ; output audio files
i501 0 60000 ; clear zak

e

</CsScore>

</CsoundSynthesizer>



<bsbPanel>
 <label>Widgets</label>
 <objectName/>
 <x>100</x>
 <y>144</y>
 <width>320</width>
 <height>240</height>
 <visible>true</visible>
 <uuid/>
 <bgcolor mode="nobackground">
  <r>255</r>
  <g>255</g>
  255
 </bgcolor>
</bsbPanel>
<bsbPresets>
</bsbPresets>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
Mea culpa

An edittig error -- now fixed in git
==Kon

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
can you point me to that file please?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
Chane in Engine/csound_pre.lex

On Tue, 4 Jul 2017, Patrick.Pagano~ wrote:

> can you point me to that file please?
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757011.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
ah.
i thought it might be in examples related to the file or something

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Oeyvind Brandtsegg-3
Does this mean that we should test ImproSculpt again with a new build from dev?


2017-07-04 7:11 GMT-07:00 Patrick.Pagano~ <[hidden email]>:
ah.
i thought it might be in examples related to the file or something





--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757014.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here



--
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
Yes

Sent from TypeApp
On 5 Jul 2017, at 11:47, Oeyvind Brandtsegg <[hidden email]> wrote:
Does this mean that we should test ImproSculpt again with a new build from dev?


2017-07-04 7:11 GMT-07:00 Patrick.Pagano~ <[hidden email]>:
ah.
i thought it might be in examples related to the file or something





--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757014.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here



--
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
In reply to this post by Oeyvind Brandtsegg-3
yes, jpff
i would love to run this soon if possible.
i admit i am a little rusty on my csound but i am the prodigal coder :-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Oeyvind Brandtsegg-3
Hi,
I tested again just now. I built from source, but I think it should run the same from the last binary release too. 
There was indeed some macros that was not terminated correctly. Macros with longer names was terminated, but single letter macros (argument expansions inside of macros) was not. 
The csd now compiles and runs, and I could live sample and do simple playback, but I did not do an extensive test. There might be odd stuff not working. Do tell if you encounter any problems. I attach just the csd here, drop it in to your ImproSculpt folder, and hopefully it will "just work".
all best 
Oeyvind

2017-07-05 17:20 GMT+02:00 Patrick.Pagano~ <[hidden email]>:
yes, jpff
i would love to run this soon if possible.
i admit i am a little rusty on my csound but i am the prodigal coder :-)



--
View this message in context: http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757045.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here



--
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

ImproSculpt_2017.csd (389K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Fabio De Sanctis De Benedictis
Hi,

If useful, I have done a slight test (sorry, I don't completely know how
to use Improsculpt) on Linux Fedora 20 with Csound 6.07 and on OsX
10.8.5 with Csound 6.08: it seems to run in both systems.

Best


fdsdb


Il giorno gio, 06/07/2017 alle 12.59 +0200, Oeyvind Brandtsegg ha
scritto:

> Hi,
> I tested again just now. I built from source, but I think it should
> run the same from the last binary release too.
> There was indeed some macros that was not terminated correctly. Macros
> with longer names was terminated, but single letter macros (argument
> expansions inside of macros) was not.
> The csd now compiles and runs, and I could live sample and do simple
> playback, but I did not do an extensive test. There might be odd stuff
> not working. Do tell if you encounter any problems. I attach just the
> csd here, drop it in to your ImproSculpt folder, and hopefully it will
> "just work".
> all best
> Oeyvind
>
> 2017-07-05 17:20 GMT+02:00 Patrick.Pagano~ <[hidden email]>:
>         yes, jpff
>         i would love to run this soon if possible.
>         i admit i am a little rusty on my csound but i am the prodigal
>         coder :-)
>        
>        
>        
>         --
>         View this message in context:
>         http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757045.html
>         Sent from the Csound - General mailing list archive at
>         Nabble.com.
>        
>         Csound mailing list
>         [hidden email]
>         https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>         Send bugs reports to
>                 https://github.com/csound/csound/issues
>         Discussions of bugs and features can be posted here
>        
>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://www.partikkelaudio.com/
> http://crossadaptive.hf.ntnu.no
> http://gdsp.hf.ntnu.no/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp
>  
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and
> features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Oeyvind Brandtsegg-3
That is good to know. Thank you.

2017-07-06 17:46 GMT+02:00 Fabio De Sanctis De Benedictis <[hidden email]>:
Hi,

If useful, I have done a slight test (sorry, I don't completely know how
to use Improsculpt) on Linux Fedora 20 with Csound 6.07 and on OsX
10.8.5 with Csound 6.08: it seems to run in both systems.

Best


fdsdb


Il giorno gio, 06/07/2017 alle 12.59 +0200, Oeyvind Brandtsegg ha
scritto:
> Hi,
> I tested again just now. I built from source, but I think it should
> run the same from the last binary release too.
> There was indeed some macros that was not terminated correctly. Macros
> with longer names was terminated, but single letter macros (argument
> expansions inside of macros) was not.
> The csd now compiles and runs, and I could live sample and do simple
> playback, but I did not do an extensive test. There might be odd stuff
> not working. Do tell if you encounter any problems. I attach just the
> csd here, drop it in to your ImproSculpt folder, and hopefully it will
> "just work".
> all best
> Oeyvind
>
> 2017-07-05 17:20 GMT+02:00 Patrick.Pagano~ <[hidden email]>:
>         yes, jpff
>         i would love to run this soon if possible.
>         i admit i am a little rusty on my csound but i am the prodigal
>         coder :-)
>
>
>
>         --
>         View this message in context:
>         http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757045.html
>         Sent from the Csound - General mailing list archive at
>         Nabble.com.
>
>         Csound mailing list
>         [hidden email]
>         https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>         Send bugs reports to
>                 https://github.com/csound/csound/issues
>         Discussions of bugs and features can be posted here
>
>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: <a href="tel:%2B47%2092%20203%20205" value="+4792203205">+47 92 203 205
>
> http://www.partikkelaudio.com/
> http://crossadaptive.hf.ntnu.no
> http://gdsp.hf.ntnu.no/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp
>
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and
> features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here



--
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

jpff
In reply to this post by Fabio De Sanctis De Benedictis
but does it run on 6.09.1?   There was a change in macros that was broke

On Thu, 6 Jul 2017, Fabio De Sanctis De Benedictis wrote:

> Hi,
>
> If useful, I have done a slight test (sorry, I don't completely know how
> to use Improsculpt) on Linux Fedora 20 with Csound 6.07 and on OsX
> 10.8.5 with Csound 6.08: it seems to run in both systems.
>
> Best
>
>
> fdsdb
>
>
> Il giorno gio, 06/07/2017 alle 12.59 +0200, Oeyvind Brandtsegg ha
> scritto:
>> Hi,
>> I tested again just now. I built from source, but I think it should
>> run the same from the last binary release too.
>> There was indeed some macros that was not terminated correctly. Macros
>> with longer names was terminated, but single letter macros (argument
>> expansions inside of macros) was not.
>> The csd now compiles and runs, and I could live sample and do simple
>> playback, but I did not do an extensive test. There might be odd stuff
>> not working. Do tell if you encounter any problems. I attach just the
>> csd here, drop it in to your ImproSculpt folder, and hopefully it will
>> "just work".
>> all best
>> Oeyvind
>>
>> 2017-07-05 17:20 GMT+02:00 Patrick.Pagano~ <[hidden email]>:
>>         yes, jpff
>>         i would love to run this soon if possible.
>>         i admit i am a little rusty on my csound but i am the prodigal
>>         coder :-)
>>
>>
>>
>>         --
>>         View this message in context:
>>         http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757045.html
>>         Sent from the Csound - General mailing list archive at
>>         Nabble.com.
>>
>>         Csound mailing list
>>         [hidden email]
>>         https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>         Send bugs reports to
>>                 https://github.com/csound/csound/issues
>>         Discussions of bugs and features can be posted here
>>
>>
>>
>>
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://www.partikkelaudio.com/
>> http://crossadaptive.hf.ntnu.no
>> http://gdsp.hf.ntnu.no/
>> http://soundcloud.com/brandtsegg
>> http://flyndresang.no/
>> http://soundcloud.com/t-emp
>>
>> Csound mailing list [hidden email]
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and
>> features can be posted here
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Improsculpt

Patrick.Pagano~
i am going to check this today and i'll report what i find

On Thu, Jul 6, 2017 at 2:21 PM, jpff <[hidden email]> wrote:
but does it run on 6.09.1?   There was a change in macros that was broke


On Thu, 6 Jul 2017, Fabio De Sanctis De Benedictis wrote:

Hi,

If useful, I have done a slight test (sorry, I don't completely know how
to use Improsculpt) on Linux Fedora 20 with Csound 6.07 and on OsX
10.8.5 with Csound 6.08: it seems to run in both systems.

Best


fdsdb


Il giorno gio, 06/07/2017 alle 12.59 +0200, Oeyvind Brandtsegg ha
scritto:
Hi,
I tested again just now. I built from source, but I think it should
run the same from the last binary release too.
There was indeed some macros that was not terminated correctly. Macros
with longer names was terminated, but single letter macros (argument
expansions inside of macros) was not.
The csd now compiles and runs, and I could live sample and do simple
playback, but I did not do an extensive test. There might be odd stuff
not working. Do tell if you encounter any problems. I attach just the
csd here, drop it in to your ImproSculpt folder, and hopefully it will
"just work".
all best
Oeyvind

2017-07-05 17:20 GMT+02:00 Patrick.Pagano~ <[hidden email]>:
        yes, jpff
        i would love to run this soon if possible.
        i admit i am a little rusty on my csound but i am the prodigal
        coder :-)



        --
        View this message in context:
        http://csound.1045644.n5.nabble.com/Improsculpt-tp5756958p5757045.html
        Sent from the Csound - General mailing list archive at
        Nabble.com.

        Csound mailing list
        [hidden email]
        https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
        Send bugs reports to
                https://github.com/csound/csound/issues
        Discussions of bugs and features can be posted here





--

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway
Cell: <a href="tel:%2B47%2092%20203%20205" value="+4792203205" target="_blank">+47 92 203 205

http://www.partikkelaudio.com/
http://crossadaptive.hf.ntnu.no
http://gdsp.hf.ntnu.no/
http://soundcloud.com/brandtsegg
http://flyndresang.no/
http://soundcloud.com/t-emp

Csound mailing list [hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
https://github.com/csound/csound/issues Discussions of bugs and
features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here



--
Patrick Pagano  B.S, M.F.A
Assistant Professor in Residence
University of Connecticut
Stamford, Connecticut
(352)226-2016

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
12
Loading...