From: Eugene Petkevich Date: Tue, 4 Apr 2023 19:54:03 +0000 (+0200) Subject: Update midi handler, midisynth and startup X-Git-Url: https://git.zuelum.org/?a=commitdiff_plain;h=26c602fe14d1b500e35b984cec8521ee4e182c6e;p=scprojects.git Update midi handler, midisynth and startup --- diff --git a/extensions/classes/midihydrogen.sc b/extensions/classes/midihydrogen.sc index cff6a19..1175698 100644 --- a/extensions/classes/midihydrogen.sc +++ b/extensions/classes/midihydrogen.sc @@ -1,35 +1,12 @@ MidiHydrogen : MidiHandler { - classvar gmrock; - *new {|name='Hydrogen', midiNames=#["Hydrogen", ["Hydrogen Midi-In", "Hydrogen Midi-Out"]], reveal=true| - ^super.newCopyArgs(name, midiNames, reveal).midiInit.controlInit; - } - - *initClass { - gmrock = IdentityDictionary[ - \bass -> 36, - \side -> 37, - \snare -> 38, - \clap -> 39, - \rim -> 40, - \tomfloor -> 41, - \hatclosed -> 42, - \tomlow -> 43, - \hatpedal -> 44, - \tomhigh -> 45, - \hatopen -> 46, - \cowbell -> 47, - \ride -> 48, - \ccrash -> 49, - \ride2 -> 50, - \splash -> 51, - \hatsemiopen -> 52, - \bell -> 53, - ]; - gmrock.know = true; + *new {|name='Hydrogen', midiNames=#["Hydrogen", ["IAC Driver", "Bus 1"]], reveal=true| + ^super.newCopyArgs(name, midiNames, reveal).controlInit; } controlInit { + midiout = MIDIOut.newByName("IAC Driver", "Bus 1").latency_(0); + idin = MIDIClient.sources.detect{|i| (i.device == "Hydrogen").and(["Hydrogen"].includesEqual(i.name))}.uid; midiout.latency_(Server.default.latency); "Hydrogen is connected to supercollider"; } @@ -39,7 +16,7 @@ MidiHydrogen : MidiHandler { \type, \midi, \midiout, this.midiout, \midicmd, \noteOn, - \chan, 1, + \chan, 0, ) } diff --git a/extensions/classes/midisynths.sc b/extensions/classes/midisynths.sc index f607ab0..bbcdd8f 100644 --- a/extensions/classes/midisynths.sc +++ b/extensions/classes/midisynths.sc @@ -65,11 +65,16 @@ KeySynth : MidiSynth { n = 60 + this.distanceWhite(60, n); }; if (d) { - notes[n] = Synth(synthName, params.value.asPairs++[ - \gate, 1, - \freq, this.midiKeyToFreq(n), - \amp, amp * v, - ]++this.makePanParam(n), group); + var freq = this.midiKeyToFreq(n); + notes[n] = Synth( + synthName.value, + params.value(freq, v).asPairs++[ + \gate, 1, + \freq, freq, + \amp, amp.value(freq, v) * v, + ]++this.makePanParam(n), + group + ); } { notes[n].set(\gate, 0); notes[n] = nil; diff --git a/startup.scd b/startup.scd index 57574a3..dda53e0 100644 --- a/startup.scd +++ b/startup.scd @@ -1,19 +1,69 @@ // ==== Server setup +//ServerOptions.outDevices +s.options.outDevice = "Aggregate Device"; //s.options.outDevice = "MA WFRIENDZ"; //s.options.outDevice = "MacBook Air Speakers"; //s.options.outDevice = "External Headphones"; //s.options.outDevice = "EDIFIER R1080BT"; -s.options.outDevice = "Scarlett 2i4 USB"; +//s.options.outDevice = "Scarlett 2i4 USB"; +//s.options.outDevice = "Bose Mini II SE SoundLink"; //s.options.inDevice = "MacBook Air Microphone"; -s.options.inDevice = "Scarlett 2i4 USB"; +//s.options.inDevice = "Scarlett 2i4 USB"; +s.options.inDevice = "Aggregate Device"; s.options.maxNodes = 128 * 1024; s.options.maxSynthDefs = 32 * 1024; s.options.memSize = 1024 * 1024; s.options.numBuffers = 32 * 1024; s.options.numAudioBusChannels = 32 * 1024; s.options.numControlBusChannels = 256 * 1024; -s.options.numInputBusChannels = 2; -s.options.numOutputBusChannels = 4; +s.options.numInputBusChannels = 17; +s.options.numOutputBusChannels = 20; +s.options.numWireBufs = 128; +s.options.hardwareBufferSize = 64; + +s.recHeaderFormat = "wav"; +s.latency = 0.4; + +Platform.case( + \osx, { + thisProcess.platform.recordingsDir = "/Users/genio/stock/audio/supercollider"; + }, + \linux, { "Linux".postln }, + \windows, { "Windows".postln } +); + +// global nice variables + +a = ( + outs: 20, + s: 16, // speakers output + h: 18, // headpohens output + v: 0, // virtual output first bus + m: 16, // microphone input + e: 0, // external software input +); + +// hydrogen drum machine constants +b = ( + bass: 36, + side: 37, + snare: 38, + clap: 39, + rim: 40, + tomfloor: 41, + hatclosed: 42, + tomlow: 43, + hatpedal: 44, + tomhigh: 45, + hatopen: 46, + cowbell: 47, + ride: 48, + ccrash: 49, + ride2: 50, + splash: 51, + hatsemiopen: 52, + bell: 53, +); // ==== Midi setup ~midiup = { @@ -22,6 +72,55 @@ s.options.numOutputBusChannels = 4; }; ~midiup.value; +try { + ~macbookMidiOut = MIDIOut.newByName("IAC Driver", "Bus 1").latency_(s.latency); +} { + "Cannot connect to macbook midi out".postln; +}; + +m = ( + hydrogenOut: ~macbookMidiOut, + abletonOut: ~macbookMidiOut, + ardourOut: ~macbookMidiOut, +); + +// Fader + +SynthDef(\fader, {|in, out, amp=1.0| + var sig; + sig = In.ar(in, 2); + Out.ar(out, sig*amp); +}).add; + +// Other stuff + +// A simple triangle wave synth in stereo with panning and a simple low pass filter +// This synthDef was written by Mads Kjeldgaard and requires the sc3 plugins +/* +s.doWhenBooted{ + SynthDef.new(\default, { + arg dur, attack=0.01, release=1.0, + t_gate=1, out, freq=442, cutoff=5500, + rq=1, pan=0.0, amp=0.5; + var env = EnvGen.kr(Env.perc(attack, release), t_gate, timeScale: dur, doneAction: 2); + var sig = DPW3Tri.ar(freq: freq, mul: env); + sig = RLPF.ar(sig, cutoff.clip(20.0, 20000.0), rq.clip(0.0,1.0)); + sig = Pan2.ar(sig, pan); + Out.ar(out, sig * amp); + }).add; +}; + +s.waitForBoot { + ~clean = SuperClean(2, s); + ~clean.loadSoundFiles; // hot swap in samples from anywhere! + ~clean.loadSoundFiles("~/gart/media/Хахомо"); + s.sync; // optionally: wait for samples to be read + ~clean.start([0,2,4]); // first 8 out looks like [0,2,4,6] + SuperClean.default = ~clean; + "[ SuperClean up + running ]".postln; +}; +*/ + // ==== Scales // == Tunings @@ -38,7 +137,7 @@ Scale.all.put(\hivi, Scale([0, 2, 4, 5, 7, 10, 12], 13, tuning: ~tun)); // == Sources // fm synth -SynthDef(\bino, { | +SynthDef(\bino, {| out=0, gate=1, freq=440, modFreq=440, amp=1, release=1.0, maxIndex=1 | var sig, modIndex, env;