Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jacobjoaquin/csd
base: 700c6d7831
...
head fork: jacobjoaquin/csd
compare: 5d2d937f03
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 55 additions and 60 deletions.
  1. +55 −60 demo/pysco/markov.csd
View
115 demo/pysco/markov.csd
@@ -3,43 +3,24 @@
sr = 44100
kr = 44100
ksmps = 1
-nchnls = 2
+nchnls = 1
0dbfs = 1.0
-; Uses one of the millions of Amen loops by the Winstons. Originally, that is.
-gS_loop = "Amenbreak.aif"
-gisr filesr gS_loop
-gilength filelen gS_loop
-gibeats = 64
-
instr 1
- p3 = 0.13
- iamp = p4
- ibeat = p5
- ipos = ((ibeat / gibeats) * gilength)
-
- aenv linseg iamp, p3 * 0.85, iamp, p3 * 0.15, 0
- a1, a2 diskin2 gS_loop, 1.5, ipos
- out a1 * aenv, a2 * aenv
+ idur = p3 ; Duration
+ iamp = p4 ; Amplitude
+ ifreq = p5 ; Frequency
+
+ kenv line iamp, idur, 0 ; Line envelope
+ a1 vco2 kenv, ifreq, 12, 0.5 ; Triangle wave
+ out a1
endin
</CsInstruments>
<CsScore bin="./pysco.py">
-# Import choice from python library
-from random import choice
from random import random
-# Create wrapper functions for instruments.
-def kick(amp=1):
- event_i(1, 0, 1, amp, choice([0, 0.5, 4, 8, 16]))
-
-def snare(amp=1):
- event_i(1, 0, 1, amp, choice([1, 5, 9, 11.5]))
-
-def hat(amp=1):
- event_i(1, 0, 1, amp, choice([3.5, 7.5, 10, 11, 19.5]))
-
class Markov:
@@ -51,21 +32,24 @@ class Markov:
def begin(self, node, duration):
self.next_node = node
self.duration = duration
- self.go()
+
+ while self.time < self.duration:
+ self.go()
def go(self):
if self.time < self.duration:
self.next_node.play()
- def node(self):
- return MarkovNode(self)
+ def node(self, duration, func, *args):
+ return MarkovNode(self, duration, func, *args)
class MarkovNode:
- def __init__(self, parent):
- self.duration = None
- self.action_func = None
+ def __init__(self, parent, duration, func, *args):
+ self.duration = duration
+ self.action_func = func
+ self.args = args
self.edges = []
self.parent = parent
@@ -92,40 +76,51 @@ class MarkovNode:
def play(self):
with cue(self.parent.time):
- self.action_func()
+ self.action_func(*self.args)
self.parent.time += self.duration
self.parent.next_node = self._select_next()
- self.parent.go()
-markov = Markov()
-node = markov.node()
-node_2 = markov.node()
-node_3 = markov.node()
-
-node.duration = 0.5
-node.action(kick)
-node.edge(node, 1)
-node.edge(node_2, 1)
-node.edge(node_3, 1)
-
-node_2.duration = 0.5
-node_2.action(snare)
-node_2.edge(node, 1)
-node_2.edge(node_2, 1)
-node_2.edge(node_3, 1)
+def note(dur, amp, pch):
+ event_i(1, 0, dur, amp, cpspch(pch))
-node_3.duration = 0.25
-node_3.action(hat)
-node_3.edge(node, 1)
-node_3.edge(node_2, 1)
-node_3.edge(node_3, 1)
-
-markov.begin(node, 128)
-
-score('t 0 170')
+# Create markov object
+markov = Markov()
+# Create nodes and set parameters
+state_0 = markov.node(1.0, note, 1.0, 1.0, 8.00)
+state_1 = markov.node(0.5, note, 0.5, 1.0, 8.02)
+state_2 = markov.node(1.0, note, 1.0, 1.0, 8.03)
+state_3 = markov.node(0.5, note, 0.5, 1.0, 8.05)
+state_4 = markov.node(1.0, note, 1.0, 1.0, 8.07)
+state_5 = markov.node(1.5, note, 1.5, 1.0, 8.10)
+state_6 = markov.node(1.0, note, 1.0, 1.0, 8.09)
+state_7 = markov.node(0.5, note, 0.5, 1.0, 9.00)
+
+# Connect nodes and set probablity
+state_0.edge(state_1, 1)
+state_1.edge(state_0, 1)
+state_1.edge(state_2, 1)
+state_2.edge(state_0, 1)
+state_2.edge(state_3, 1)
+state_3.edge(state_0, 1)
+state_3.edge(state_3, 4)
+state_3.edge(state_4, 1)
+state_4.edge(state_5, 1)
+state_5.edge(state_4, 1)
+state_5.edge(state_6, 2)
+state_6.edge(state_4, 1)
+state_6.edge(state_7, 2)
+state_7.edge(state_4, 1)
+state_7.edge(state_7, 4)
+state_7.edge(state_0, 2)
+
+# Play
+score('t 0 120')
+markov.begin(state_0, 128)
+
+# Change amplitude
pmap('i', 1, 4, lambda x: x * 0.707)
</CsScore>

No commit comments for this range

Something went wrong with that request. Please try again.