From: Eugene Petkevich Date: Tue, 31 May 2022 10:22:24 +0000 (+0300) Subject: Add common midi handler class X-Git-Url: https://git.zuelum.org/?a=commitdiff_plain;h=9004504e7b7afa55c435ae1b495065a85dfeb427;p=scprojects.git Add common midi handler class --- diff --git a/extensions/classes/midihandler.sc b/extensions/classes/midihandler.sc new file mode 100644 index 0000000..817c333 --- /dev/null +++ b/extensions/classes/midihandler.sc @@ -0,0 +1,23 @@ +MidiHandler { + var reveal = false; + + noCallback {|handlerName...args| + if (reveal) { + "%.%(%)".format(this.name, handlerName, args).postln; + }; + } + + midiInit { + var dest; + dest = MIDIClient.destinations.detect({ |item| + item.device == midiNames[0]; + }); + if (dest == nil) { + Error("Cannot connect to "++name).throw; + }; + midiout = MIDIOut.newByName(dest.device, dest.name).latency_(0); + idin = MIDIClient.sources.detect{|i| i.device == midiNames[0]}.uid; + } +} \ No newline at end of file diff --git a/extensions/classes/midimix.sc b/extensions/classes/midimix.sc index 5de6ad5..fbb05bd 100644 --- a/extensions/classes/midimix.sc +++ b/extensions/classes/midimix.sc @@ -1,11 +1,7 @@ -MidiMix { +MidiMix101 : MidiHandler { classvar ledValues, ledControls; classvar controlNotes; - const reveal = false; // channel selector var <>chanrot; // modes @@ -62,26 +58,11 @@ MidiMix { ]; } - *new {|name=\Mix101| - ^super.newCopyArgs(name).prInit; + *new {|name='DJ-Tech MIX-101', midiNames=#["Mix-101", "Mix-101 MIDI 1", "Mix-101 MIDI 1"]| + ^super.newCopyArgs(name, midiNames).midiInit.controlInit; } - noCallback {|handlerName...args| - if (reveal) { - "%.%(%)".format(this.name, handlerName, args).postln; - }; - } - - prInit { - var dest = MIDIClient.destinations.detect({ |item| - item.device == "Mix-101" - }); - if (dest == nil) { - Error("Cannot connect to DJ-Tech MIX-101").throw; - }; - midiout = MIDIOut.newByName(dest.device, dest.name).latency_(0); - idin = MIDIClient.sources.detect{|i| i.device == "Mix-101"}.uid; - + controlInit { // MIDI out channel selector (back of the device) // velocity is the channel MIDIdef.noteOn(\chanrot++name, {|...args| diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/bcr2000-control.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/bcr2000-control.scd" index 3aee9c4..4724e84 100644 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/bcr2000-control.scd" +++ "b/\320\245\321\215\320\267\320\270\321\204\321\203/bcr2000-control.scd" @@ -16,7 +16,7 @@ MIDIdef.cc(\bcr2000defaultTurn, { |...args| controler.turn(*args); - }, (1..110), controler.channel); + }, (1..110), controler.channel, 2883584); "Ԃиџуту готов к использованию 😊".postln; diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/mix101-control.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/mix101-control.scd" index cc33257..8e4a7d5 100644 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/mix101-control.scd" +++ "b/\320\245\321\215\320\267\320\270\321\204\321\203/mix101-control.scd" @@ -1,29 +1,3 @@ -( -MIDIdef.cc(\testcc, {|...args| - (["cc"] ++ args).postln; -}); -MIDIdef.noteOn(\testnoteon, {|...args| - (["note on"] ++ args).postln; -}); -MIDIdef.noteOff(\testnoteoff, {|...args| - (["note off"] ++ args).postln; -}); -MIDIdef.touch(\testtouch, {|...args| - (["touch"] ++ args).postln; -}); -MIDIdef.polytouch(\testpolytouch, {|...args| - (["polytouch"] ++ args).postln; -}); -MIDIdef.bend(\testbend, {|...args| - (["bend"] ++ args).postln; -}); -MIDIdef.sysex(\testsysex, {|...args| - (["sysex"] ++ args).postln; -}); -) - -MKtl.find; - ( ~mix = MidiMix(); ~se = Sampler(); @@ -128,7 +102,7 @@ SynthDef(\granular, {|out=0, amp=1, buf=0, density=10, len=0.1, rate=1, pos=0| ) ( -~amp = 0.5; +~amp = 1; ~density = 10; ~len = 0.1; ~rate = 1; diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" index b719154..0bffc00 100644 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" +++ "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" @@ -28,7 +28,7 @@ a = a.resamp1(500); ~se.plotter.specs = \bipolar.asSpec; ~se.soundView.setData(~data, 1024, samplerate: ~se.buf.sampleRate); -~se.soundView.data +~se.soundView.data. (\freq: 220).play; @@ -59,6 +59,7 @@ a = a.resamp1(500); }; ~push.padDown = { |zi, row, col, vel| var freq; + vel = vel * 5; ~push.padLight(row, col, 2, 1, false, 0); freq = Scale.major.degreeToFreq(col, 0.midicps, row+1); ~notes[freq.cpsmidi.asInteger] = Synth(~se.synthdefName, ~se.makeSynthArgs++[\freq, freq, \amp, vel]); @@ -74,6 +75,7 @@ a = a.resamp1(500); }; ~push.padPressure = { |zi, row, col, vel| var freq; + vel = vel * 5; //~push.padLight(row, col, 0, 0, false, 1); freq = Scale.major.degreeToFreq(col, 0.midicps, row+1); if (vel > ~amps[freq.cpsmidi.asInteger], { @@ -81,7 +83,7 @@ a = a.resamp1(500); var maxRatio = 1.5; ("initial "++vel).postln; if ((vel/amp) > maxRatio, { vel = amp * maxRatio; }); - ~notes[freq.cpsmidi.asInteger].set(\amp, vel); + ~notes[freq.cpsmidi.asInteger].set(\amp, vel*5); ("new "++vel).postln; }); }); @@ -347,3 +349,4 @@ s.waitForBoot{ SSampler(\reel).load([Quarks.folder ++ "/SuperSampler/Testcode/Sounds/Reel Palindruome_44.1kHz_int16.aiff"]); } ) +