A simple one today, but importantly a variant of the flocking sketch. This is a stereo envelope that can be modulated with a single slider. Enjoy.
//
// WorkSpace.swift
// DAY4
//
// Created by Adam Tindale on 2016-05-04.
// Copyright © 2016 Adam Tindale. All rights reserved.
//
import UIKit
class WorkSpace: CanvasController {
var webview = UIWebView()
let freqslider = UISlider()
override func setup() {
// loads flocking.js in home.html
webview.frame = CGRectMake(0, CGFloat(canvas.height/4.0), CGFloat(canvas.width), CGFloat(3.0*canvas.height/4.0))
webview.mediaPlaybackRequiresUserAction = false
let url = NSBundle.mainBundle().URLForResource("home", withExtension: "html")
let request = NSURLRequest(URL: url!)
webview.loadRequest(request)
freqslider.frame = CGRectMake(10, CGFloat(canvas.height/2 - 15), CGFloat(canvas.width - 20), 30)
freqslider.value = 0.1
canvas.add(freqslider)
freqslider.addTarget(self, action: "freq:", forControlEvents: UIControlEvents.ValueChanged)
}
func freq(sender: UISlider!){
let myval = sender.value * 20.0
self.webview.stringByEvaluatingJavaScriptFromString("synth.set('lefthat.mul.gate.freq', \(myval) );synth.set('righthat.mul.gate.freq', \(myval) );")
}
}
<html>
<head>
<style>
*{border:0;margin:0;}
#wave{position:fixed;top:0;left:0;width:100%;height:100%;background-color:blue;}
</style>
</head>
<body>
<script src="flocking-all.min.js"></script>
<script>
// Sine tone shaped by a simple attack/sustain/release envelope and periodically triggered.
var synth = flock.synth({
synthDef: [
{
id: "righthat",
ugen: "flock.ugen.whiteNoise",
mul: {
ugen: "flock.ugen.env.simpleASR",
start: 0.0,
attack: 0.01,
sustain: 0.2,
release: 0.1,
gate: {
ugen: "flock.ugen.impulse",
rate: "control",
freq: 2,
phase: 0.5
}
}
},
{
id: "lefthat",
ugen: "flock.ugen.whiteNoise",
mul: {
ugen: "flock.ugen.env.simpleASR",
start: 0.0,
attack: 0.01,
sustain: 0.2,
release: 0.1,
gate: {
ugen: "flock.ugen.impulse",
rate: "control",
freq: 2,
phase: 0.0
}
}
}
]
});
synth.play();
</script>
</body>
</html>