Skip to content

Commit

Permalink
add x-y-plot to hysteresis effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedolino committed Apr 29, 2024
1 parent d11d0e5 commit f657e85
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 14 deletions.
21 changes: 21 additions & 0 deletions src/mruby-zest/example/HystDataView.qml
Original file line number Diff line number Diff line change
@@ -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?

}
}

58 changes: 58 additions & 0 deletions src/mruby-zest/example/HysteresisView.qml
Original file line number Diff line number Diff line change
@@ -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
}
}
53 changes: 39 additions & 14 deletions src/mruby-zest/example/ZynHysteresis.qml
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -25,30 +25,55 @@ Widget {
}

Widget {
WaveView {
HysteresisView {
id: wave
extern: hysteresis.extern + "Hysteresis/waveform"
}
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" }

}
Expand Down
39 changes: 39 additions & 0 deletions src/mruby-zest/mrblib/draw-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions src/osc-bridge/schema/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -10464,6 +10464,10 @@
{
"id" : 16,
"value" : "Square"
},
{
"id" : 17,
"value" : "DualTan"
}
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -13000,6 +13011,10 @@
{
"id" : 16,
"value" : "Square"
},
{
"id" : 17,
"value" : "DualTan"
}
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -14958,6 +14980,10 @@
{
"id" : 16,
"value" : "Square"
},
{
"id" : 17,
"value" : "DualTan"
}
]
},
Expand Down Expand Up @@ -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.",
Expand Down

0 comments on commit f657e85

Please sign in to comment.