From 9cf0a3c1e7a6079b2c929776c074ba07a7b9346c Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Sun, 11 Jan 2015 20:34:46 +0000 Subject: [PATCH] Metronome now syncs! --- main.ck | 32 ++++++++++++++++++++++++++----- main.py | 4 ++-- scratch.ck | 56 ++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/main.ck b/main.ck index e5a0d72..edc0bba 100644 --- a/main.ck +++ b/main.ck @@ -1,7 +1,6 @@ // TODO: turn off adcThru when recording // TODO: Effects break panning for some unknown reason // TODO: currently I don't turn ADC thru back on after recording - // Effects chain with limiters, reverb, filters NRev reverb => LPF lpf => HPF hpf => Dyno outputLimiter => dac; outputLimiter.limit(); @@ -19,7 +18,7 @@ inputLimiter @=> UGen @ mainInput; .5 => adcThru.gain; 10000 => lpf.freq; 10 => hpf.freq; -1::second => dur loopTime; +//1::second => dur loopTime; // Plug in the pedals LoopPedal pedals[4]; @@ -28,6 +27,10 @@ for( 0 => int i; i < pedals.cap(); i++ ) { pedals[i].outputTo(outputWet, outputDry); } +// Create the metronome +Metronome metronome; +spork ~metronome.run(); + // Start listening to OSC messages OscIn oin; 9000 => oin.port; oin.listenAll(); @@ -42,10 +45,9 @@ while (true) { msg.getFloat(1) => adcThru.gain; } else if(msg.address=="/delay") { - msg.getFloat(0)::second => loopTime; + msg.getFloat(0)::second => dur loopTime; msg.getFloat(1) => float feedback; for( 0 => int i; i < pedals.cap(); i++ ) { - //pedals[i].setLoopPoint(loopTime + (i*.1)::second); pedals[i].setLoopPoint(loopTime); pedals[i].setFeedback(feedback); } @@ -78,7 +80,7 @@ while (true) { } } -public class LoopPedal +class LoopPedal { // We are wrapping a live sampler, LiSa LiSa sample; @@ -100,6 +102,7 @@ public class LoopPedal public void setWet( float ratio ) { ratio => wet.gain; 1-ratio => dry.gain;} public void clear() { sample.clear(); } public void recordFrom(UGen ugen) { ugen => sample; } + public dur remaining() { return sample.loopEnd() - sample.playPos(); } public void outputTo(UGen wetSink, UGen drySink) { 1 => sample.play; @@ -115,6 +118,25 @@ public class LoopPedal } +class Metronome +{ + // A simple metronome + SinOsc s => ADSR a => dac; + 0.5 => s.gain; + a.set(0.01, .1, .5, .2); + 0.01::second => dur plipTime; + + fun void run() + { + while(true){ + pedals[0].remaining() => now; + a.keyOn(); + plipTime => now; + a.keyOff(); + } + } +} + diff --git a/main.py b/main.py index 68135c6..1b0c67f 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import wx def sendOSCSafe(channel, data): try: - print channel, data + #print channel, data sendOSCMsg(channel, data) except OSCClientError: print "OSC comms error" @@ -115,7 +115,7 @@ class DelayPanel(wx.Panel): label.SetFont(font) sizer.Add(label, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5) - self.delayTime = OSCSlider(self, "Time", default_value=1, max_value=10, align=False) + self.delayTime = OSCSlider(self, "Time", default_value=1, max_value=10, min_value=0.5, align=False) sizer.Add(self.delayTime, 1, wx.ALL, 5) self.feedback = OSCSlider(self, "Hold", default_value=.99, align=False) diff --git a/scratch.ck b/scratch.ck index f9d014d..c2fa206 100644 --- a/scratch.ck +++ b/scratch.ck @@ -1,26 +1,44 @@ -1::second => dur loopTime; - -fun void plip() -{ - SinOsc s => dac; - 0.05::second => dur plipTime; - 2000 => s.freq; +// the event +KBHit kb; + +class MetronomeEvent extends Event{ int value; } + +class Metronome { + MetronomeEvent metronomeEvent; + spork ~pulse(); + + fun void listen(){ + while (true){ + metronomeEvent => now; + <<<"Metronome got event " + metronomeEvent.value>>>; + if (metronomeEvent.value==0){ + spork ~pulse(); + } + } + } - while(true){ - .1 => s.gain; - plipTime => now; - 0 => s.gain; - loopTime - plipTime => now; + fun void pulse(){ + 1::second => now; + 0=>metronomeEvent.value; + metronomeEvent.signal(); } + fun void signal(){ + 1=>metronomeEvent.value; + metronomeEvent.signal(); + } } -spork ~plip(); +Metronome m; +spork ~m.listen(); -while(true){ - 1::second => now; - loopTime - 0.1::second => loopTime; +// time-loop +while( true ) +{ + kb => now; + while( kb.more() ) + { + <<< "ascii: ", kb.getchar() >>>; + m.signal(); + } } - - -