Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 74576d6

Browse files
committed
examples > notochord > tidalcycles
1 parent aa73141 commit 74576d6

2 files changed

Lines changed: 209 additions & 0 deletions

File tree

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{-
2+
3+
Notochord OSC target, OSC specs and Tidal parameters
4+
5+
See github.com/jarmitage/jarmlib for reference of
6+
how to incorporate this file into your Tidal setup
7+
8+
-}
9+
10+
-- Notochord Target
11+
:{
12+
ncTarget = Target {oName = "Notochord",
13+
oAddress = "127.0.0.1",
14+
oHandshake = False,
15+
oPort = 6789,
16+
oBusPort = Nothing,
17+
oLatency = 0.1,
18+
oSchedule = Pre BundleStamp,
19+
oWindow = Nothing
20+
}
21+
:}
22+
23+
{-
24+
Notochord.feed() consumes an event and advance hidden state
25+
26+
inst: int. instrument of current note.
27+
0 is start token
28+
1-128 are General MIDI instruments
29+
129-256 are drumkits (MIDI 1-128 on channel 13)
30+
257-264 are 'anonymous' melodic instruments
31+
265-272 are 'anonymous' drumkits
32+
pitch: int. MIDI pitch of current note.
33+
0-127 are MIDI pitches / drums
34+
128 is start token
35+
time: float. elapsed time in seconds since previous event.
36+
vel: float. (possibly dequantized) MIDI velocity from 0-127 inclusive.
37+
0 indicates a note-off event
38+
-}
39+
40+
-- Notochord Feed OSC Specs
41+
:{
42+
ncFeedOSCSpecs = [OSC "/notochord/feed/inst" $ ArgList [("ncfeedI", Nothing)],
43+
OSC "/notochord/feed/pitch" $ ArgList [("ncfeedP", Nothing)],
44+
OSC "/notochord/feed/time" $ ArgList [("ncfeedT", Nothing)],
45+
OSC "/notochord/feed/vel" $ ArgList [("ncfeedV", Nothing)]]
46+
:}
47+
48+
-- Notochord Feed Parameters
49+
:{
50+
let ncfeedI = pI "ncfeedI"
51+
ncfeedP = pI "ncfeedP"
52+
ncfeedT = pF "ncfeedT"
53+
ncfeedV = pF "ncfeedV"
54+
ncfeed i p t v = ncfeedI i # ncfeedP p # ncfeedT t # ncfeedV v
55+
:}
56+
57+
{-
58+
Notochord.query() returns a prediction for the next note.
59+
various constraints on the the next note can be requested.
60+
61+
# hard constraints
62+
fix_*: same as the arguments to feed, but to fix a value for the predicted note.
63+
sampled values will always condition on fixed values, so passing
64+
`fix_instrument=1`, for example, will make the event appropriate
65+
for the piano (instrument 1) to play.
66+
67+
# partial constraints
68+
allow_end: if False, zero probability of sampling the end marker
69+
min_time, max_time: if not None, truncate the time distribution
70+
include_instrument: instrument id(s) to include in sampling.
71+
(if not None, all others will be excluded)
72+
exclude_instrument: instrument id(s) to exclude from sampling.
73+
include_pitch: pitch(es) to include in sampling.
74+
(if not None, all others will be excluded)
75+
exclude_pitch: pitch(es) to exclude from sampling.
76+
min_vel, max_vel: if not None, truncate the velocity distribution
77+
78+
# sampling strategies
79+
instrument_temp: if not None, apply top_p sampling to instrument. 0 is
80+
deterministic, 1 is 'natural' according to the model
81+
pitch_temp: if not None, apply top_p sampling to pitch. 0 is
82+
deterministic, 1 is 'natural' according to the model
83+
velocity_temp: if not None, apply temperature sampling to the velocity
84+
component.
85+
rhythm_temp: if not None, apply top_p sampling to the weighting
86+
of mixture components. this affects coarse rhythmic patterns;
87+
0 is deterministic, 1 is 'natural' according to the model
88+
timing_temp: if not None, apply temperature sampling to the time
89+
component. this affects fine timing; 0 is deterministic and
90+
precise, 1 is 'natural' according to the model.
91+
index_pitch: Optional[int]. if not None, deterministically take the
92+
nth most likely pitch instead of sampling.
93+
94+
# multiple predictions
95+
pitch_topk: Optional[int]. if not None, instead of sampling pitch,
96+
stack the top k most likely pitches along the batch dimension
97+
sweep_time: if True, instead of sampling time, choose a diverse set of
98+
times and stack along the batch dimension
99+
100+
Returns: dict of
101+
'end': int. value of 1 indicates the *current* event (the one
102+
passed as arguments to `predict`) was the last event, and the
103+
predicted event should *not* be played. if `allow end` is false,
104+
this will always be 0.
105+
'step': int. number of steps since calling `reset`.
106+
'instrument': int. id of predicted instrument.
107+
1-128 are General MIDI standard melodic instruments
108+
129-256 are drumkits for MIDI programs 1-128
109+
257-264 are 'anonymous' melodic instruments
110+
265-272 are 'anonymous' drums
111+
'pitch': int. predicted MIDI number of next note, 0-128.
112+
'time': float. predicted time to next note in seconds.
113+
'velocity': float. unquantized predicted velocity of next note.
114+
0-127; hard 0 indicates a note-off event.
115+
'*_params': tensor. distribution parameters for visualization
116+
purposes.
117+
-}
118+
119+
-- Notochord Query OSC Specs
120+
:{
121+
ncQueryOSCSpecs = [OSC "/notochord/query/fix/inst" $ ArgList [("ncqueryfixI", Nothing)],
122+
OSC "/notochord/query/fix/pitch" $ ArgList [("ncqueryfixP", Nothing)],
123+
OSC "/notochord/query/fix/time" $ ArgList [("ncqueryfixT", Nothing)],
124+
OSC "/notochord/query/fix/vel" $ ArgList [("ncqueryfixV", Nothing)],
125+
OSC "/notochord/query/constrain/excludei" $ ArgList [("ncqueryexcludeI", Nothing)],
126+
OSC "/notochord/query/constrain/includep" $ ArgList [("ncqueryincludeP", Nothing)],
127+
OSC "/notochord/query/constrain/excludep" $ ArgList [("ncqueryexcludeP", Nothing)],
128+
OSC "/notochord/query/constrain/mint" $ ArgList [("ncqueryminT", Nothing)],
129+
OSC "/notochord/query/constrain/maxt" $ ArgList [("ncquerymaxT", Nothing)],
130+
OSC "/notochord/query/constrain/minv" $ ArgList [("ncqueryminV", Nothing)],
131+
OSC "/notochord/query/constrain/maxv" $ ArgList [("ncquerymaxV", Nothing)],
132+
OSC "/notochord/query/sample/ncquerytempi" $ ArgList [("ncquerytempI", Nothing)],
133+
OSC "/notochord/query/sample/ncquerytempp" $ ArgList [("ncquerytempP", Nothing)],
134+
OSC "/notochord/query/sample/ncquerytempt" $ ArgList [("ncquerytempT", Nothing)],
135+
OSC "/notochord/query/sample/ncquerytempr" $ ArgList [("ncquerytempR", Nothing)],
136+
OSC "/notochord/query/sample/ncquerytempv" $ ArgList [("ncquerytempV", Nothing)],
137+
OSC "/notochord/query/sample/ncqueryindexp" $ ArgList [("ncqueryindexP", Nothing)],
138+
OSC "/notochord/query/multi/ncquerytopp" $ ArgList [("ncquerytopP", Nothing)],
139+
OSC "/notochord/query/multi/ncquerysweept" $ ArgList [("ncquerysweepT", Nothing)]
140+
]
141+
:}
142+
143+
-- Notochord Query: fix
144+
:{
145+
let ncqueryfixI = pI "ncqueryfixI"
146+
ncqueryfixP = pI "ncqueryfixP"
147+
ncqueryfixT = pF "ncqueryfixT"
148+
ncqueryfixV = pF "ncqueryfixV"
149+
:}
150+
151+
-- Notochord Query: constraints
152+
:{
153+
let ncqueryexcludeI = pI "ncqueryexcludeI"
154+
ncqueryincludeP = pI "ncqueryincludeP"
155+
ncqueryexcludeP = pI "ncqueryexcludeP"
156+
ncqueryminT = pF "ncqueryminT"
157+
ncquerymaxT = pF "ncquerymaxT"
158+
ncqueryminV = pF "ncqueryminV"
159+
ncquerymaxV = pF "ncquerymaxV"
160+
:}
161+
162+
-- Notochord Query: sampling
163+
:{
164+
let ncquerytempI = pF "ncquerytempI"
165+
ncquerytempP = pF "ncquerytempP"
166+
ncquerytempT = pF "ncquerytempT"
167+
ncquerytempR = pF "ncquerytempR"
168+
ncquerytempV = pF "ncquerytempV"
169+
ncqueryindexP = pI "ncqueryindexP"
170+
:}
171+
172+
-- Notochord Query: multiple predictions
173+
:{
174+
let ncquerytopP = pI "ncquerytopP"
175+
ncquerysweepT = pI "ncquerysweepT"
176+
:}
177+
178+
let ncOSCSpecs = ncFeedOSCSpecs++ncQueryOSCSpecs
179+
180+
-- Notochord OSC Map
181+
ncOscMap = (ncTarget, ncOSCSpecs)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Notochord feed and query demo patterns
2+
3+
d "feed"
4+
$ ncfeedP (scale "<major minor>" $ run 16)
5+
# ncfeedT (range 0 1 $ cos)
6+
# ncfeedV (range 0 1 $ sine)
7+
# ncfeedI "0 1 2 3"
8+
9+
d "query"
10+
$ ncqueryfixP (scale "<major minor>" $ run 16)
11+
# ncqueryfixT (range 0 1 $ cos)
12+
# ncqueryfixV (range 0 1 $ sine)
13+
# ncqueryfixI "0 1 2 3"
14+
# ncqueryexcludeI "[0, 1, 2, 3]"
15+
# ncqueryincludeP "[0, 1, 2, 3]"
16+
# ncqueryexcludeP "[0, 1, 2, 3]"
17+
# ncqueryminT (range 0 1 $ cos)
18+
# ncquerymaxT (range 0 1 $ sine)
19+
# ncqueryminV (range 0 1 $ cos)
20+
# ncquerymaxV (range 0 1 $ sine)
21+
# ncquerytempI (range 0 1 $ cos)
22+
# ncquerytempP (range 0 1 $ sine)
23+
# ncquerytempT (range 0 1 $ cos)
24+
# ncquerytempR (range 0 1 $ sine)
25+
# ncquerytempV (range 0 1 $ cos)
26+
# ncqueryindexP "[0, 1, 2, 3]"
27+
# ncquerytopP "[0, 1, 2, 3]"
28+
# ncquerysweepT "<0 1>"

0 commit comments

Comments
 (0)