This repository has been archived by the owner on Jul 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbasma.orc
144 lines (133 loc) · 5.04 KB
/
tbasma.orc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//trans rights
//Copyright © 2022 Amy Universe
//This work is free. You can redistribute it and/or modify it under the
//terms of the Do What The Fuck You Want To Public License, Version 2,
//as published by Sam Hocevar. See the COPYING file for more details.
opcode tBasma, kk[], kk[]k[]k[]k[]OO
/*
Taphy's sister, she specializes in time magic
(The idea of Aria's MSR applied to rhythm)
[https://aria.dog/modules/]
with some ideas from the Laundry Soup sequencer by computerscare
(it was how i first learned that a rhythm sequencer is a clock divider)
[https://github.com/freddyz]
Syntax:
kActiveStep, kTrigArr[] tBasma kTrig, kCount[], kMin[], kMax[], kQArr[]
[, kStepMode] [, kLmtMode]
kActiveStep, kTrigArr[] tBasma kTrig, kCount[], kMin, kMax, kQArr[]
[, kStepMode] [, kLmtMode]
Performance:
kActiveStep: Index of the currently active step (from 0 to lenarray(kCount))
kTrigArr[]: Each step's trigger output.
kTrig: Input trigger that runs the sequencer. Every k-cycle when this is
non-zero will advance the sequencer (according to count and step mode)
kCount[]: Count of how many input triggers it takes to move to next step
(how long a step is in clicks) These sould be positive integers.
The length of this array controls the length of the sequence.
kMin[], kMax[]: Minimum and maximum count for each step (kMin <= count < kMax)
kMin, kMax: Minimum and maximum count for all steps (kMin <= count < kMax)
(you can have min be a variable and max be an array or vice versa)
kQArr[]: The queue inputs for each step. Queued steps take priority over other
steps. This won't be modified by the sequencer but can be from within the
calling instrument after invoking the sequencer. Example:
kQueueArr[kActiveStep] = kQueueArr[kActiveStep]*kToggle
kToggle = 0 for reset, and kToggle = 1 for keep.
Positive values add the corresponding steps to queue, non-positive remove them.
kStepMode: Direction in which the sequencer will move.
0 = forward, 1 = backward, 2 = random. (halt otherwise) (defaults to 0)
kLmtMode: How to behave around the boundaries. (0=wrap (default), 1=limit, 2=mirror)
(other values are treated as 0)
*/
kTrig, kCount[], kMin[], kMax[], kQArr[], kStepMode, kLmtMode xin
ilen = lenarray(kCount)
kTrigArr[] init ilen
kcnt init 0
;first k-cycle stuff
kfirst init 1
if kfirst == 1 then
kfirst = 0
;pick initial step
if kStepMode == 0 then
kAS = (ilen-1)%ilen
else
kAS = 0
endif
endif
kTrigArr = 0
if kcnt < 1 && kTrig != 0 then
; go to the next step
kmax maxarray kQArr
if kmax == 0 then ; no queued steps (max=0 means entire array's non-positive)
if kStepMode == 0 then
kAS = (kAS+1)%ilen ;step foreward
elseif kStepMode == 1 then
kAS = wrap(kAS-1, 0, ilen) ;step backward
elseif kStepMode == 2 then
kAS = trandom(kTrig, 0, ilen) ;go to random step
else
endif
else ;there are queued steps
if kStepMode == 0 then
kAS = (kAS+1)%ilen ;make sure to not get stuck if current step is queued
while kQArr[kAS] <= 0 do ;go to nearest queued step forward
kAS = (kAS+1)%ilen
od
elseif kStepMode == 1 then
kAS = wrap(kAS-1, 0, ilen) ;same deal but we're moving backward
while kQArr[kAS] <= 0 do
kAS = wrap(kAS-1, 0, ilen) ;wrap is easier than dealing with neg %
od
elseif kStepMode == 2 then
kAS = trandom(kTrig, 0, ilen) ;jump to random step..
while kQArr[kAS] <= 0 do ; ..then go to nearest queued step foreward
kAS = (kAS+1)%ilen
od
else
endif
endif
kTrigArr[kAS] = 1
endif
;counter
if kTrig != 0 then
;when trigger is recieved, increment count then % against
;limited kCount input. if counter is at 0 it's considered a new step
; limit mode
if kLmtMode == 1 then
kcnt = (kcnt+1) % limit(kCount[kAS], kMin[kAS], kMax[kAS])
; mirror mode
elseif kLmtMode == 2 then
kcnt = (kcnt+1) % mirror(kCount[kAS], kMin[kAS], kMax[kAS])
; wrap mode
else
kcnt = (kcnt+1) % wrap(kCount[kAS], kMin[kAS], kMax[kAS])
endif
endif
xout kAS, kTrigArr
endop
;overloads
opcode tBasma, kk[], kk[]kkk[]OO ;pass min and max as scalars
kTrig, kCount[], kMin, kMax, kQArr[], kStepMode, kLmtMode xin
ilen = lenarray(kCount)
kMinArr[] init ilen
kMaxArr[] init ilen
kMinArr = kMin
kMaxArr = kMax
kAS,kT[] tBasma kTrig,kCount,kMinArr,kMaxArr,kQArr,kStepMode,kLmtMode
xout kAS, kT
endop
opcode tBasma, kk[], kk[]kk[]k[]OO ;only scaler min
kTrig, kCount[], kMin, kMax[], kQArr[], kStepMode, kLmtMode xin
ilen = lenarray(kCount)
kMinArr[] init ilen
kMinArr = kMin
kAS,kT[] tBasma kTrig,kCount,kMinArr,kMax,kQArr,kStepMode,kLmtMode
xout kAS, kT
endop
opcode tBasma, kk[], kk[]k[]kk[]OO ;scaler max
kTrig, kCount[], kMin[], kMax, kQArr[], kStepMode, kLmtMode xin
ilen = lenarray(kCount)
kMaxArr[] init ilen
kMaxArr = kMax
kAS,kT[] tBasma kTrig,kCount,kMin,kMaxArr,kQArr,kStepMode,kLmtMode
xout kAS, kT
endop