Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Hysteresis Effect #106

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
6 changes: 5 additions & 1 deletion src/mruby-zest/example/ZynEffectGroup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ Widget {
return Qml::ZynDynFilter.new(db)
elsif(type == :sympathetic)
return Qml::ZynSympathetic.new(db)
elsif(type == :hysteresis)
return Qml::ZynHysteresis.new(db)
else
col = Qml::ColorBox.new(db)
col.bg = color(:red)
Expand All @@ -243,7 +245,8 @@ Widget {
6=>:distortion,
7=>:eq,
8=>:dynamicfilter,
9=>:sympathetic}
9=>:sympathetic,
10=>:hysteresis}
mapper[type]
}

Expand All @@ -257,6 +260,7 @@ Widget {
:echo => 1,
:phaser => 2,
:sympathetic => 1,
:hysteresis => 2,
:reverb => 1}
mapper[type]
}
Expand Down
99 changes: 99 additions & 0 deletions src/mruby-zest/example/ZynHysteresis.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Widget {
id: hysteresis
//label: "hysteresis"
//topSize: 0.2
function refresh_recur(x) {
#@@recur_level ||= 0
#@@recur_level += 1
#print " "*@@recur_level
#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
hysteresis.refresh_recur(xx)
end
#@@recur_level -= 1
}
function refresh() {
refresh_recur(self)
}
GroupHeader {
label: "Hysteresis"
extern: hysteresis.extern
copyable: true
}

Widget {
HysteresisView {
id: wave
extern: hysteresis.extern + "Hysteresis/waveform"
}
Widget {
ParModuleRow {
id: rw
layoutOpts: []
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 + "Ppanning"}
Knob { extern: hysteresis.extern + "Hysteresis/Plpf"}
Knob { extern: hysteresis.extern + "Hysteresis/Phpf"}
Knob { extern: hysteresis.extern + "Hysteresis/Plevel" }
}
ParModuleRow {
id: rw2
layoutOpts: []
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: "coerciv";
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
}
}

Col {
ToggleButton { extern: hysteresis.extern + "Hysteresis/Pprefiltering"}
ToggleButton { extern: hysteresis.extern + "Hysteresis/Pstereo"}
}

}
function layout(l, selfBox) {
Draw::Layout::vpack(l, selfBox, children)
}
}

function layout(l, selfBox) {
Draw::Layout::hpack(l, selfBox, children)
}
}
function layout(l, selfBox) {
Draw::Layout::vfill(l, selfBox, children, [0.15, 0.85])
}
}
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
Loading