Skip to content

Instantly share code, notes, and snippets.

@lennart
Last active May 29, 2016 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennart/bce48f8057c04fefaf8fe00d737ce948 to your computer and use it in GitHub Desktop.
Save lennart/bce48f8057c04fefaf8fe00d737ce948 to your computer and use it in GitHub Desktop.
Record Tidal patterns from SuperCollider (HW output or SuperDirt outBus)
-- either `:load SyncSC.hs` here or within `tidal.el`
-- then
(record, pause) <- Recorder.init(record, pause) <- Recorder.init
cd $HOME
mkdir recordings
emacs rec.tidal &
sclang tidal-synced-record.scd
module Recorder where
import Sound.Tidal.Tempo (Tempo(..), clocked)
import Sound.Tidal.Stream (logicalOnset')
import Sound.OSC.FD
import Sound.OSC.Datum
import Control.Concurrent
import Control.Concurrent.MVar
init :: IO ((IO (), IO ()))
init = do s <- openUDP "127.0.0.1" 57130
m <- newMVar False
forkIO $ clocked $ onTick s m
return $ ((record m True) , (record m False))
record :: MVar Bool -> Bool -> IO ()
record m state = do
swapMVar m state
return ()
onTick :: UDP -> MVar Bool -> Tempo -> Int -> IO ()
onTick s m current ticks = do
m' <- tryReadMVar m
case m' of
Nothing -> do
return ()
Just True -> do
let logicalOnset = logicalOnset' current ticks 0 0
msg = Bundle (ut_to_ntpr logicalOnset) [Message "/sync" [float (cps current)]]
sendOSC s msg
Just False -> do
return ()
(
s.options.numBuffers = 1024 * 16;
s.options.memSize = 8192 * 16;
s.options.maxNodes = 1024*32;
(
s.waitForBoot {
~dirt = SuperDirt(2, s);
~dirt.loadSoundFiles;
s.sync;
~dirt.start(57120, 0 ! 2);
thisProcess.openUDPPort(57130);
n = NetAddr("127.0.0.1");
(
~recordings = Array.fill(16, { arg i;
var n = RecNodeProxy.audio(s, 2), name = "tidal-midi-rec-" ++ i ++ ".aif";
n.source = { /*SoundIn.ar([0,1]);*/ InFeedback.ar([~dirt.orbits[0].outBus, ~dirt.orbits[1].outBus]); };
n.open(name);
n.record;
[n, name];
});
);
~count = 0;
~recording = True;
(
OSCdef(\syncTidal, {|msg, time, addr, recvPort|
if ( ~recording == True, {
var cps = msg[1], o = ~recordings[~count], n = o[0], stamp = Date.getDate.stamp, filename = o[1];
["cps", cps].postln;
n.unpause;
~count = (~count + 1).mod(16);
{
n.close;
{
["cps for file writing", cps].postln;
File.copy(filename, "recordings/tidal-rec-" ++ stamp ++ "-cps-" ++ cps ++ ".aif");
}.defer(1 / cps);
{
n.open(filename);
n.record;
}.defer(4 / cps);
}.defer(1 / cps);
},
{
"Not recording".postln;
});
}, '/sync', n, recvPort: 57130);
);
OSCdef(\syncTidal).enable;
}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment