Skip to content

Instantly share code, notes, and snippets.

View antonhornquist's full-sized avatar

Anton Hörnquist antonhornquist

  • Linköping, Sweden
View GitHub Profile
// This is a step sequencer with 8 tracks and 8 steps. The sequencer triggers playback of one sample per
// track. Sequencer tempo and swing amount is variable.
// The code below is split in two main sections (core + monome and arc UI) followed by an example of
// loading samples for the tracks, a pattern and tempo and swing amount setting.
(
// Section 1: Define the core step sequencer functionality. All step sequencer functionality is available
// using the exported functions.
var num_samples = 8, num_pattern_steps = 8, pattern_beats = 2, default_tempo = 100, default_swing_amount = 50;
// Hello World
a=GRMonome64.new; // create a monome
b=GRButton(a, 0@0); // a 1x1 button placed at top left key
b.action = { |view, value| (value.if("Hello", "Goodbye") + "World").postln }; // an action triggered when the button is pressed
// A tour of widgets...
b.remove; // remove the button created above
// Grrr for SuperCollider: an UI library for grid based controllers
// Grrr classes are loosely based on SuperCollider GUI classes. GRControllers are similar to Windows, GRView and its subclasses are similar to View and its subclasses. Like GUI classes a parent is typically passed to a GRView upon instantiation to indicate which controller or view the view will become a child of. Instead of GUI bounds (a Rect supplied to GUI Views) arguments origin (a Point), numCols and numRows designate where on the parent view or controller a Grrr widget is added and how large it is supposed to be.
a=GRScreenGrid.new; // A GRScreenGrid is a virtual grid with configurable size that defaults to 8x8
b=GRButton(a, 0@0, 2, 2); // a button spanning 2x2 keys is placed at top left key on the virtual grid
b.action = { |view, value| (value.if("Hello", "Goodbye") + "World").postln }; // pressing the top-leftmost 2x2 grid keys will now post a message to the Post Window and toggle button value which in turn toggles led state
b.value
(
s.boot;
s.latency = 0.02;
~grid=GRMonome64.new;
~grid.spawnGui;
~playpos=GRHToggle.newDecoupled(~grid, 0@7, 8, 1, nillable: true).value_(nil);
~pages=GRSwitcher(~grid, 0@1, 8, 6);
~pageselect=GRHToggle(~grid, 0@0, 4, 1).action_({ |view, value| ~pages.value = value });
~transport=GRHToggle(~grid, 6@0, 2, 1);
~transport.action = { |view, value| if (value == 1) { ~player.play } { ~player.stop } };
(
var plotpath, update, plotxy, position, size, alpha;
plotpath = { |to|
var steps = 5;
var delta = (to - position) / steps;
fork {
steps.do {
position = position + delta;
update.();
(
var app = \toggle;
var state;
var update;
var client;
~disposeApp.();
state=Ref(Archive.global.at(\apps, app, \value) ? true);
(
var app = \bulb;
var position, size, alpha;
var plotpath, update;
var client;
Archive.global.at(\apps, app).isNil.if {
Archive.global.put(\apps, app, \position, `([email protected])));
Archive.global.put(\apps, app, \size, `50);
Archive.global.put(\apps, app, \alpha, `0);
@antonhornquist
antonhornquist / pd.rb
Last active May 19, 2017 11:39
run and patch pd from ruby
require 'socket'
require 'tempfile'
file = Tempfile.new('foo')
# note: using pd netreceive is unsafe, only do this if you know what you're doing
lines =<<-PATCH
#N canvas 87 360 450 300 10;
#X obj 24 25 netreceive 2000 1;
#X obj 24 51 s pd-#{File.basename(file.path)};
require 'tempfile'
# pure data patching dsl for ruby hack
file = Tempfile.new
begin
my_patch = patch # 1. create patch
my_patch + 'declare -stdpath creb' # 2. add object
mod = my_patch + 'loadbang' >> 'list 200 10000' >> 'line~' >> 'osc~ 2' >> '*~ 800' >> '+~ 1000' # 3. connect
sine = mod >> 'osc~ 429' >> '*~ 0.5'
@antonhornquist
antonhornquist / dw-howto-load-samples.scd
Last active October 8, 2017 21:23
dw: How to load samples

( // code below loads 16 samples into first kit ~loadKit.value( 0, // kit index. four kits, indexed 0 to 3, are available ( root: "/path/to/samples", // root path for samples samples: [ // an array of up to 16 samples "kick1.wav", "kick2.wav", "snare.wav",