diff --git a/src/mruby-zest/example/HystDataView.qml b/src/mruby-zest/example/HystDataView.qml new file mode 100644 index 00000000..609fb13b --- /dev/null +++ b/src/mruby-zest/example/HystDataView.qml @@ -0,0 +1,21 @@ +Widget { + layer: 1 + property Array data: nil; + property Bool normal: false + property Float pad: 1.0/32 + property Float fixedpad: 0 + property Bool under_highlight: false + + function class_name() { "HystDataView" } + + function draw(vg) + { + pad2 = (1-2*pad) + box = Rect.new(w*pad + fixedpad, h*pad + fixedpad, + w*pad2 - 2*fixedpad, h*pad2 - 2*fixedpad) + + Draw::WaveForm::plotHyst(vg, self.data, box, normal, 0, under_highlight) if not self.data.nil? + + } +} + diff --git a/src/mruby-zest/example/HysteresisView.qml b/src/mruby-zest/example/HysteresisView.qml new file mode 100644 index 00000000..bd3815a8 --- /dev/null +++ b/src/mruby-zest/example/HysteresisView.qml @@ -0,0 +1,58 @@ +Widget { + id: hyst_view + property Bool grid: true; + property Bool draw_borders: false + property Object valueRef: nil + property Float pad: 1.0/32 + function class_name() { "HysteresisView" } + + onExtern: { + data = OSC::RemoteParam.new($remote, hyst_view.extern) + data.callback = lambda {|x| + hystdata_view.data = x + hystdata_view.damage_self + } + + hyst_view.valueRef = [data] + + } + + HystDataView { + id: hystdata_view + } + + function draw(vg) + { + pad2 = (1-2*pad) + box = Rect.new(w*pad, h*pad, w*pad2, h*pad2) + background Theme::VisualBackground + + if(grid) + Draw::Grid::linear_x(vg,0,10,box, 1.0) + Draw::Grid::linear_y(vg,0,10,box, 1.0) + end + + if(draw_borders) + vg.translate(0.5, 0.5) + vg.path do |v| + v.stroke_width = 1 + v.stroke_color = Theme::GridLine + v.rounded_rect(box.x.round(), box.y.round(), box.w.round(), box.h.round(), 2) + v.stroke() + end + vg.translate(-0.5, -0.5) + end + + if(extern.nil? || extern.empty?) + Draw::WaveForm::sin(vg, box, 128) + end + } + + function refresh() + { + return if self.valueRef.nil? + self.valueRef.each do |v| + v.refresh + end + } +} diff --git a/src/mruby-zest/example/ZynHysteresis.qml b/src/mruby-zest/example/ZynHysteresis.qml index 9c616ba3..78e3cb99 100644 --- a/src/mruby-zest/example/ZynHysteresis.qml +++ b/src/mruby-zest/example/ZynHysteresis.qml @@ -1,17 +1,17 @@ Widget { id: hysteresis - label: "hysteresis" - topSize: 0.2 + //label: "hysteresis" + //topSize: 0.2 function refresh_recur(x) { #@@recur_level ||= 0 #@@recur_level += 1 #print " "*@@recur_level - #puts "Distort refresh = {#{x.class}} of {#{dst.class}}" + #puts "hysteresis refresh = {#{x.class}} of {#{hysteresis.class}}" x.children.each do |xx| #print " "*(@@recur_level+1) #puts "child = #{xx.class}" xx.refresh() if xx.respond_to? :refresh - dst.refresh_recur(xx) + hysteresis.refresh_recur(xx) end #@@recur_level -= 1 } @@ -25,7 +25,7 @@ Widget { } Widget { - WaveView { + HysteresisView { id: wave extern: hysteresis.extern + "Hysteresis/waveform" } @@ -33,22 +33,47 @@ Widget { ParModuleRow { id: rw layoutOpts: [] - Selector { - layoutOpts: [:long_mode] - extern: hysteresis.extern + "Hysteresis/preset" - whenValue: lambda { hysteresis.refresh } + Knob { extern: hysteresis.extern + "Pvolume" + whenValue: lambda {wave.refresh}; + function setValue(v) { + valuator.value = lim(v, 0.0, 1.0); + valuator.whenValue.call; + valuator.damage_self + } } - Knob { extern: hysteresis.extern + "Pvolume"} Knob { extern: hysteresis.extern + "Ppanning"} ToggleButton { label: "Stereo"; extern: hysteresis.extern + "Hysteresis/PStereo" } - } ParModuleRow { id: rw2 layoutOpts: [] - Knob { extern: hysteresis.extern + "Hysteresis/Pdrive" } - Knob { extern: hysteresis.extern + "Hysteresis/Pcoercivity" } - Knob { extern: hysteresis.extern + "Hysteresis/Premanence" } + Knob { extern: hysteresis.extern + "Hysteresis/Pdrive" + whenValue: lambda {wave.refresh}; + function setValue(v) { + valuator.value = lim(v, 0.0, 1.0); + valuator.whenValue.call; + valuator.damage_self + } + } + Knob { + extern: hysteresis.extern + "Hysteresis/Pcoercivity"; label: "coercivity"; + whenValue: lambda {wave.refresh}; + function setValue(v) { + valuator.value = lim(v, 0.0, 1.0); + valuator.whenValue.call; + valuator.damage_self + } + } + + Knob { + extern: hysteresis.extern + "Hysteresis/Premanence"; label: "remanence"; + whenValue: lambda {wave.refresh}; + function setValue(v) { + valuator.value = lim(v, 0.0, 1.0); + valuator.whenValue.call; + valuator.damage_self + } + } Knob { extern: hysteresis.extern + "Hysteresis/Plevel" } } diff --git a/src/mruby-zest/mrblib/draw-common.rb b/src/mruby-zest/mrblib/draw-common.rb index 5ace95f6..5732977d 100644 --- a/src/mruby-zest/mrblib/draw-common.rb +++ b/src/mruby-zest/mrblib/draw-common.rb @@ -47,6 +47,45 @@ def self.plot(vg, ypts, bb, do_norm=true, phase=0, under_highlight=false) v.stroke end end + + def self.plotHyst(vg, ypts, bb, do_norm=true, phase=0, under_highlight=false) + ypts = DSP::normalize(ypts) if do_norm + vg.path do |v| + + x_m = bb.w + x_b = bb.x + + y_m = -bb.h/2 + y_b = bb.y+bb.h/2 + mx = bb.y+bb.h + mn = bb.y + + ypos = y_m*ypts[0] + y_b + ypos = [mn, [ypos, mx].min].max + xpos = x_m/2 + x_b + puts "ypts[0]: " + ypts[0].to_s + puts "i: 0 x: " + (xpos - x_b).to_s + " y: " + (ypos - y_b).to_s + vg.move_to(xpos, ypos) + + n = ypts.length + (1...n).each do |pt| + ii = pt + ypos = y_m*ypts[ii] + y_b + ypos = mx if ypos > mx + ypos = mn if ypos < mn + + xpos = x_m/2 + x_m/2*(pt-256)/64 + x_b + xpos = x_m - x_m/2*(pt-64) /64 + x_b if pt < 192 + xpos = x_m/2 + x_m/2*pt /64 + x_b if pt < 64 + #puts "i: " + pt.to_s + " x: " + (xpos - x_b).to_s + " y:" + (ypos - y_b).to_s + + vg.line_to(xpos, ypos) + end + v.stroke_color Theme::VisualLine + v.stroke_width 2.0 + v.stroke + end + end def self.bar(vg, data, bb, bar_color, xx=nil) Draw::opt_bar(vg, data, bb, bar_color, xx) diff --git a/src/osc-bridge/schema/test.json b/src/osc-bridge/schema/test.json index 216870be..152b61a6 100644 --- a/src/osc-bridge/schema/test.json +++ b/src/osc-bridge/schema/test.json @@ -10464,6 +10464,10 @@ { "id" : 16, "value" : "Square" + }, + { + "id" : 17, + "value" : "DualTan" } ] }, @@ -11514,6 +11518,13 @@ "type" : "i", "range" : [0,127] }, + { + "path" : "/part[0,15]/partefx[0,2]/Hysteresis/Pstereo", + "shortname": "stereo", + "name" : "Pstereo", + "tooltip" : "Stereo", + "type" : "t" + }, { "path" : "/part[0,15]/ctl/panning.depth", "shortname": "pan.d", @@ -13000,6 +13011,10 @@ { "id" : 16, "value" : "Square" + }, + { + "id" : 17, + "value" : "DualTan" } ] }, @@ -14050,6 +14065,13 @@ "type" : "i", "range" : [0,127] }, + { + "path" : "/sysefx[0,3]/Hysteresis/Pstereo", + "shortname": "stereo", + "name" : "Pstereo", + "tooltip" : "Stereo", + "type" : "t" + }, { "path" : "/insefx[0,7]/preset", "name" : "preset", @@ -14958,6 +14980,10 @@ { "id" : 16, "value" : "Square" + }, + { + "id" : 17, + "value" : "DualTan" } ] }, @@ -16008,6 +16034,13 @@ "type" : "i", "range" : [0,127] }, + { + "path" : "/insefx[0,7]/Hysteresis/Pstereo", + "shortname": "stereo", + "name" : "Pstereo", + "tooltip" : "Stereo", + "type" : "t" + }, { "path" : "/microtonal/Pinvertupdown", "shortname": "inv.",