diff --git a/release-packaging/ignore/Examples/GUI_examples/HPSS.scd b/release-packaging/ignore/Examples/GUI_examples/HPSS.scd new file mode 100755 index 0000000..8d6e07e --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/HPSS.scd @@ -0,0 +1,109 @@ +( +var win, soundFileView, freqSscope,loadButton, loopButton; +var harmSlider, percSlider, mixSlider; +var soundFile, buffer; +var synthDef, synth; +var makeSynthDef; + +Font.default = Font("Monaco", 16); +buffer = Buffer.new; +win = Window.new("HPSS", + Rect(200,200,800,450)).background_(Color.gray); + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)]]); + +loopButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Play", Color.grey, Color.grey(0.8)], + ["Stop", Color.grey, Color.grey(0.2)]] + ); + +harmSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +percSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +mixSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +freqSscope = FreqScopeView(win, server:Server.default); +freqSscope.active_(true); + +loadButton.action_{ + FileDialog({ |path| + path.postln; + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + buffer = Buffer.read(Server.default, path[0]); + buffer.bufnum.postln; + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + }); +}; + +loopButton.action_{|but| + if(but.value == 1, { + Routine{ + {makeSynthDef.value}.defer; + "hi".postln; + Server.default.sync; + synth = Synth(\hpssExtractionDemo, [\buffer, buffer.bufnum]); + synth.postln; + {mixSlider.action.value(mixSlider)}.defer; + }.play; + },{ + synth.free; + }); +}; + + +mixSlider.action_{|slider| + synth.set(\bal, ControlSpec(0, 1).map(slider.value)); +}; + + + +makeSynthDef = { + +synthDef = SynthDef(\hpssExtractionDemo, + {|buffer, bal = 0.5| + var player, fhpss, mix; + var harmSize = (2 * ControlSpec(1, 100, step:1).map(harmSlider.value)) - 1; + var percSize = (2 * ControlSpec(1,100, step:1).map(percSlider.value)) - 1; + player = PlayBuf.ar(1, buffer, loop:1); + fhpss = FluidHPSS.ar(in: player, harmFilterSize: harmSize, percFilterSize: percSize, maskingMode: 1, harmThreshFreq1: 0.1, harmThreshAmp1: 0, harmThreshFreq2: 0.5, harmThreshAmp2: 0, percThreshFreq1: 0.1, percThreshAmp1: 0, percThreshFreq2: 0.5, percThreshAmp2: 0, windowSize: 1024, hopSize: 256, fftSize: -1); + + + mix =(bal * fhpss[0]) + ((1 - bal) * fhpss[1]); + Out.ar(0,Pan2.ar(SinOsc.ar(200))); + } +).add; + +}; + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [loopButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("H Size ").minWidth_(100), harmSlider), + HLayout(StaticText(win).string_("P Size").minWidth_(100), percSlider), + HLayout(StaticText(win).string_("Mix").minWidth_(100), mixSlider) + ), stretch:5] + ), stretch:2 + ], + [freqSscope, stretch:2] + ) +); + +win.front; +) diff --git a/release-packaging/ignore/Examples/GUI_examples/NMF4.scd b/release-packaging/ignore/Examples/GUI_examples/NMF4.scd new file mode 100755 index 0000000..ab21f16 --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/NMF4.scd @@ -0,0 +1,114 @@ +( +var server; +var win, soundFileView, loadButton, loopButton; +var sliders; +var soundFile, audioBuffer, destBuffer; +var synthDef, synth; +var sl1, sl2, sl3, sl4; + +server = Server.default; +Font.default = Font("Monaco", 16); + +audioBuffer = Buffer.new; +destBuffer = Buffer.new; + + +synthDef = SynthDef(\nmfDemo,{|bufnum, a1, a2, a3, a4| + var p = PlayBuf.ar(4, bufnum, loop:1); + var mix = (a1*p[0]) + (a2 * p[1]) + (a3*p[2]) + (a4*p[3]); + Out.ar(0, Pan2.ar(mix)); +}).add; + + + +win = Window.new("NMF4", + Rect(200,200,800,450)).background_(Color.gray); + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)], + ["Wait", Color.grey, Color.grey(0.2)]] + ); + +loopButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Play", Color.grey, Color.grey(0.8)], + ["Stop", Color.grey, Color.grey(0.2)]] + ); + +sliders = Array.fill(4, {|i| + var s = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); + s.action_{ + var sym = ("a"++(i+1)).asSymbol; + synth.set(sym, ControlSpec(0, 1).map(s.value)); + } +}); + + +loadButton.action_{ + FileDialog({ |path| + path.postln; + + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + Routine{ + audioBuffer = Buffer.read(server, path[0]); + server.sync; + FluidBufNMF.process(server, + audioBuffer.bufnum,destination:destBuffer.bufnum, components:4 + ); + server.sync; + destBuffer.query; + server.sync; + {loadButton.value_(0)}.defer; + }.play; + }); +}; + +loopButton.action_{|but| + var a1 = ControlSpec(0, 1).map(sliders[0].value); + var a2 = ControlSpec(0, 1).map(sliders[1].value); + var a3 = ControlSpec(0, 1).map(sliders[2].value); + var a4 = ControlSpec(0, 1).map(sliders[3].value); + + if(but.value == 1, { + synth = Synth(\nmfDemo, + [\bufnum, destBuffer.bufnum, \a1, a1, \a2, a2, \a3, a3, \a4, a4]); + },{ + synth.free; + }); +}; + + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [loopButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("source 1 ").minWidth_(100), sliders[0]), + HLayout(StaticText(win).string_("source 2 ").minWidth_(100), sliders[1]), + HLayout(StaticText(win).string_("source 3 ").minWidth_(100), sliders[2]), + HLayout(StaticText(win).string_("source 4 ").minWidth_(100), sliders[3]) + ), stretch:5] + ), stretch:2 + ] + ) +); + +win.front; +) diff --git a/release-packaging/ignore/Examples/GUI_examples/NoveltySegmentation.scd b/release-packaging/ignore/Examples/GUI_examples/NoveltySegmentation.scd new file mode 100755 index 0000000..e0ca677 --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/NoveltySegmentation.scd @@ -0,0 +1,152 @@ +( +var server; +var win, soundFileView,loadButton, processButton; +var ksSlider, thSlider; +var soundFile, audioBuffer, slicesBuffer, slicesArray; +var addSelections, playFunc, stopFunc; +var synthDef, synth; +var synths; + +var playing, currentSelection, colors, prevColor; + +playing = Array.fill(10, {false}); +server = Server.default; +Font.default = Font("Monaco", 16); + +audioBuffer = Buffer.new; +slicesBuffer = Buffer.new; + +colors = Array.fill(64, {Color.rand}); +synths = Array.fill(10, {nil}); + +synthDef = SynthDef(\noveltySegDemo,{|buf, start, end| + Out.ar(0, BufRd.ar(1, buf, Phasor.ar(1, 1, start, end))); +}).add; + +playFunc = {|index| + var dur; + currentSelection = index; + if(playing[index].not){ + synths[index] = Synth(\noveltySegDemo, + [\buf, audioBuffer.bufnum, + \start, slicesArray[index], + \end, slicesArray[index+1] + ]); + playing[index] = true; + }; + soundFileView.setSelectionColor(currentSelection, Color.white); +}; + +stopFunc = {|index| synths[index].free; playing[index] = false; + soundFileView.setSelectionColor( + index, colors[index] + ); +}; + + +win = Window.new("NoveltySegmentation", + Rect(200,200,800,450)).background_(Color.gray); + +win.view.keyDownAction_{|view, char, modifiers, unicode, keycode, key| + if (char.isDecDigit){ + var digit = char.digit; + if(digit.notNil && slicesArray.notNil){ + playFunc.value(digit - 1); + } + } +}; + +win.view.keyUpAction_{|view, char| + if(char.isDecDigit){ + stopFunc.value(char.digit - 1); + } +}; + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)]]); + +processButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Process", Color.grey, Color.grey(0.8)], + ["Wait", Color.grey, Color.grey(0.2)]] + ); + +ksSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +thSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); + + +loadButton.action_{ + FileDialog({ |path| + path.postln; + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + audioBuffer = Buffer.read(server, path[0]); + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + }); +}; + +processButton.action_{|but| + var ks = 2*(ControlSpec(2, 100, step:1).map(ksSlider.value)) - 1; + var th = ControlSpec(0, 1).map(thSlider.value); + if(but.value == 1, { + Routine{ + FluidBufNoveltySlice.process( + server, + source:audioBuffer.bufnum, + indices:slicesBuffer.bufnum, + kernelSize:ks, + threshold: th + ); + server.sync; + slicesBuffer.loadToFloatArray(action:{|arr| + slicesArray = arr; + { processButton.value_(0); + addSelections.value(slicesArray) + }.defer; + + }); + }.play; + }); +}; + + + +addSelections = {|array| + var nSegments = min(array.size, soundFileView.selections.size) - 1; + soundFileView.selections.do({|sel, i| soundFileView.selectNone(i)}); + nSegments.do({|i| + soundFileView.setSelectionStart(i, array[i]); + soundFileView.setSelectionSize(i, array[i+1] - array[i]); + soundFileView.setSelectionColor(i, colors[i]); + }); +}; + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [processButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("Kernel ").minWidth_(100), ksSlider), + HLayout(StaticText(win).string_(" Threshold").minWidth_(100), thSlider) + ), stretch:5] + ), stretch:2 + ] + ) +); + +win.front; +) diff --git a/release-packaging/ignore/Examples/GUI_examples/SineExtraction.scd b/release-packaging/ignore/Examples/GUI_examples/SineExtraction.scd new file mode 100755 index 0000000..343d0c4 --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/SineExtraction.scd @@ -0,0 +1,109 @@ +( +var win, soundFileView, freqSscope,loadButton, loopButton; +var thresholdSlider, lenSlider, mixSlider; +var soundFile, buffer; +var synthDef, synth; + +Font.default = Font("Monaco", 16); +buffer = Buffer.new; +win = Window.new("SineExtraction", + Rect(200,200,800,450)).background_(Color.gray); + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)]]); + +loopButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Play", Color.grey, Color.grey(0.8)], + ["Stop", Color.grey, Color.grey(0.2)]] + ); + +thresholdSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +lenSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +mixSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +freqSscope = FreqScopeView(win, server:Server.default); +freqSscope.active_(true); + +loadButton.action_{ + FileDialog({ |path| + path.postln; + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + buffer = Buffer.read(Server.default, path[0]); + buffer.bufnum.postln; + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + }); +}; + +loopButton.action_{|but| + if(but.value == 1, { + synth = Synth(\sineExtractionDemo, [\buffer, buffer.bufnum]); + mixSlider.action.value(mixSlider); + thresholdSlider.action.value(thresholdSlider); + lenSlider.action.value(lenSlider); + },{ + synth.free; + }); +}; + + +mixSlider.action_{|slider| + synth.set(\bal, ControlSpec(0, 1).map(slider.value)); +}; + + +thresholdSlider.action_{|slider| + synth.set(\threshold, ControlSpec(-144, 0).map(slider.value)); +}; + + +lenSlider.action_{|slider| + synth.set(\minLength, ControlSpec(0, 30).map(slider.value)); +}; + + +synthDef = SynthDef(\sineExtractionDemo, + {|buffer, threshold = 0.9, minLength = 15, bal = 0.5| + var player, fse, mix; + player = PlayBuf.ar(1, buffer, loop:1); + fse = FluidSines.ar(in: player, bandwidth: 76, + detectionThreshold: threshold, minTrackLen: minLength, + windowSize: 2048, + hopSize: 512, fftSize: 8192 + ); + mix =(bal * fse[0]) + ((1 - bal) * fse[1]); + Out.ar(0,Pan2.ar(mix)); + } +).add; + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [loopButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("Threshold ").minWidth_(100), thresholdSlider), + HLayout(StaticText(win).string_("Min Length").minWidth_(100), lenSlider), + HLayout(StaticText(win).string_("Mix").minWidth_(100), mixSlider) + ), stretch:5] + ), stretch:2 + ], + [freqSscope, stretch:2] + ) +); + +win.front; +) diff --git a/release-packaging/ignore/Examples/GUI_examples/TransientExtraction.scd b/release-packaging/ignore/Examples/GUI_examples/TransientExtraction.scd new file mode 100755 index 0000000..83ea5c4 --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/TransientExtraction.scd @@ -0,0 +1,105 @@ +( +var win, soundFileView, freqSscope,loadButton, loopButton; +var fwSlider, bwSlider, mixSlider; +var soundFile, buffer; +var synthDef, synth; + +Font.default = Font("Monaco", 16); +buffer = Buffer.new; +win = Window.new("TransientExtraction", + Rect(200,200,800,450)).background_(Color.gray); + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)]]); + +loopButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Play", Color.grey, Color.grey(0.8)], + ["Stop", Color.grey, Color.grey(0.2)]] + ); + +fwSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +bwSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +mixSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +freqSscope = FreqScopeView(win, server:Server.default); +freqSscope.active_(true); + +loadButton.action_{ + FileDialog({ |path| + path.postln; + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + buffer = Buffer.read(Server.default, path[0]); + buffer.bufnum.postln; + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + }); +}; + +loopButton.action_{|but| + if(but.value == 1, { + synth = Synth(\transientExtractionDemo, [\buffer, buffer.bufnum]); + mixSlider.action.value(mixSlider); + fwSlider.action.value(fwSlider); + bwSlider.action.value(bwSlider); + },{ + synth.free; + }); +}; + + +mixSlider.action_{|slider| + synth.set(\bal, ControlSpec(0, 1).map(slider.value)); +}; + + +fwSlider.action_{|slider| + synth.set(\fw, ControlSpec(0, 5).map(slider.value)); +}; + + +bwSlider.action_{|slider| + synth.set(\bw, ControlSpec(0, 5).map(slider.value)); +}; + + +synthDef = SynthDef(\transientExtractionDemo, + {|buffer, fw = 3, bw = 1, bal = 0.5| + var player, fte, mix; + player = PlayBuf.ar(1, buffer, loop:1); + fte = FluidTransients.ar(in: player, threshFwd:fw, threshBack:bw, clumpLength:256); + mix =(bal * fte[0]) + ((1 - bal) * fte[1]); + Out.ar(0,Pan2.ar(mix)); + } +).add; + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [loopButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("Forward Th ").minWidth_(100), fwSlider), + HLayout(StaticText(win).string_("Backward Th").minWidth_(100), bwSlider), + HLayout(StaticText(win).string_("Mix").minWidth_(100), mixSlider) + ), stretch:5] + ), stretch:2 + ], + [freqSscope, stretch:2] + ) +); + +win.front; +) diff --git a/release-packaging/ignore/Examples/GUI_examples/TransientSegmentation.scd b/release-packaging/ignore/Examples/GUI_examples/TransientSegmentation.scd new file mode 100755 index 0000000..c025b94 --- /dev/null +++ b/release-packaging/ignore/Examples/GUI_examples/TransientSegmentation.scd @@ -0,0 +1,150 @@ +( +var server; +var win, soundFileView,loadButton, processButton; +var fwSlider, bwSlider, debounceSlider; +var soundFile, audioBuffer, slicesBuffer, slicesArray; +var addSelections, playFunc, stopFunc; +var synthDef, synth; + +var playing, currentSelection, colors, prevColor; + +playing = false; +server = Server.default; +Font.default = Font("Monaco", 16); + +audioBuffer = Buffer.new; +slicesBuffer = Buffer.new; + +colors = Array.fill(64, {Color.rand}); + +synthDef = SynthDef(\transientSegDemo,{|buf, start, end| + Out.ar(0, BufRd.ar(1, buf, Phasor.ar(1, 1, start, end))); +}).add; + +playFunc = {|index| + var dur; + currentSelection = index; + if(playing.not){ + synth = Synth(\transientSegDemo, + [\buf, audioBuffer.bufnum, + \start, slicesArray[index], + \end, slicesArray[index+1] + ]); + playing = true; + }; + soundFileView.setSelectionColor(currentSelection, Color.white); +}; + +stopFunc = {synth.free; playing = false; + soundFileView.setSelectionColor(currentSelection, colors[currentSelection]); + +}; + + +win = Window.new("TransientSegmentation", + Rect(200,200,800,450)).background_(Color.gray); + +win.view.keyDownAction_{|view, char, modifiers, unicode, keycode, key| + if (char.isDecDigit){ + var digit = char.digit; + if(slicesArray.notNil){ + playFunc.value(digit - 1); + } + } +}; + +win.view.keyUpAction_{stopFunc.value;}; + + + +soundFileView = SoundFileView.new(win) + .gridOn_(false) + .waveColors_([Color.white]); + +loadButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_([["Load", Color.grey, Color.grey(0.8)]]); + +processButton = Button(win, Rect(0, 0, 100, 100)) + .minHeight_(150) + .states_( + [["Process", Color.grey, Color.grey(0.8)], + ["Wait", Color.grey, Color.grey(0.2)]] + ); + +fwSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +bwSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); +debounceSlider = Slider(win, Rect(0, 0, 100, 10)).value_(0.5); + +loadButton.action_{ + FileDialog({ |path| + path.postln; + soundFile = SoundFile.new; + soundFile.openRead(path[0]); + audioBuffer = Buffer.read(server, path[0]); + soundFileView.soundfile = soundFile; + soundFileView.read(0, soundFile.numFrames); + }); +}; + +processButton.action_{|but| + var fw = ControlSpec(0, 5).map(fwSlider.value); + var bw = ControlSpec(0, 5).map(bwSlider.value); + var db = ControlSpec(1, 4410).map(debounceSlider.value); + if(but.value == 1, { + Routine{ + FluidBufTransientSlice.process( + server, + source:audioBuffer.bufnum, + indices:slicesBuffer.bufnum, + threshFwd: fw, + threshBack: bw, + clumpLength:db + ); + server.sync; + slicesBuffer.loadToFloatArray(action:{|arr| + slicesArray = arr; + { processButton.value_(0); + addSelections.value(slicesArray) + }.defer; + + }); + }.play; + }); +}; + + + +addSelections = {|array| + var nSegments = min(array.size, soundFileView.selections.size) - 1; + soundFileView.selections.do({|sel, i| soundFileView.selectNone(i)}); + nSegments.do({|i| + soundFileView.setSelectionStart(i, array[i]); + soundFileView.setSelectionSize(i, array[i+1] - array[i]); + soundFileView.setSelectionColor(i, colors[i]); + }); +}; + +win.layout_( + VLayout( + [ + HLayout( + [loadButton, stretch:1], + [soundFileView, stretch:5] + ), stretch:2 + ], + [ + HLayout( + [processButton, stretch:1], + [VLayout( + HLayout(StaticText(win).string_("Forward Th ").minWidth_(100), fwSlider), + HLayout(StaticText(win).string_("Backward Th").minWidth_(100), bwSlider), + HLayout(StaticText(win).string_("Debounce").minWidth_(100), debounceSlider) + ), stretch:5] + ), stretch:2 + ] + ) +); + +win.front; +)