Skip to content

ENVnext #107

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions build_config.rb
Original file line number Diff line number Diff line change
@@ -83,6 +83,9 @@
# Use Object class extension
conf.gem :core => "mruby-object-ext"

# Use Enum class extension
conf.gem :core => "mruby-enum-ext"

# Use toplevel object (main) methods extension
conf.gem :core => "mruby-toplevel-ext"

4 changes: 2 additions & 2 deletions src/mruby-zest/example/ZynEnvEdit.qml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ Widget {
return if env.selected == nil
return if !free.value
path = self.extern + "addPoint"
$remote.action(path, env.selected)
$remote.action(path, env.selected/3)
env.refresh
}
function del_point()
@@ -16,7 +16,7 @@ Widget {
return if env.selected == nil
return if !free.value
path = self.extern + "delPoint"
$remote.action(path, env.selected)
$remote.action(path, env.selected/3)
env.refresh
}

135 changes: 118 additions & 17 deletions src/mruby-zest/mrblib/draw-common.rb
Original file line number Diff line number Diff line change
@@ -180,35 +180,100 @@ def self.lfo_plot(vg, bb, dat, stroke)
vg.stroke_width 1.0
end

def self.env_plot(vg, bb, dat, stroke, selected)
def self.env_plot(vg, bb, dat, stroke, selected, emode)
n = dat.length
pts = 32
vg.path do
vg.move_to(bb.x + bb.w*dat[0].x,
bb.y + bb.h/2*(1-dat[0].y))
(0...n).each do |i|
vg.line_to(bb.x + bb.w*dat[i].x,
bb.y + bb.h/2*(1-dat[i].y))

(1...n).each_slice(3) do |i,j,k|
h = i-1
a = dat[h].y # starting point
b = dat[i].y # bezier control point
c = dat[j].y # bezier control point 2
d = dat[k].y # end point
vg.move_to(bb.x + bb.w*dat[i-1].x,
bb.y + bb.h/2*(1-a))
(1...pts).each do |pt|
w2 = pt.to_f/pts.to_f # weight of end point
w1 = 1.0-w2 # weight of starting point

if (h==0) # treatment for "first segment linear" in envout_dB for ADSR_dB
case emode
when 1, 2 # ADSR_lin or ADSR_dB
v1 = (10.0**((a))-0.01)/0.99
v2 = (10.0**((d))-0.01)/0.99
rap = v1 + (v2 - v1) * w2
y = (Math.log10((rap) * 0.99 + 0.01))
when 3 # ASR_freqlfo
v1 = (2.0**(6.0 * a.abs )-1)
if (a<0)
v1 = -v1
end

v2 = (2.0**(6.0 * d.abs )-1)
if (c<0)
v2 = -v2
end

rap = v1 + (v2 - v1) * w2

y = (rap>=0) ? ((Math.log(rap + 1.0) / (6.0 * Math.log(2.0))) ) : (-(Math.log(1.0 - rap) / (6.0 * Math.log(2.0))) )

else # ADSR_filter = 4; ASR_bw = 5;

y = a + (d - a) * w2

end

vg.line_to(bb.x+bb.w*dat[i-1].x + bb.w*(dat[k].x-dat[i-1].x)*w2,
bb.y + bb.h/2.0 * (1.0-y))

else
vg.line_to(bb.x+bb.w*dat[h].x + bb.w*(dat[k].x-dat[h].x)*w2,
bb.y + bb.h/2.0 * (1.0-(w1*w1*w1*a + 3*w1*w1*w2*b + 3*w1*w2*w2*c + w2*w2*w2*d)))
end
end
vg.line_to(bb.x + bb.w*dat[k].x,
bb.y + bb.h/2.0*(1.0-d))

end
vg.line_join NVG::ROUND
vg.stroke_width 2.0
vg.stroke_color stroke
vg.stroke
end
vg.stroke_width 1.0

sel_color = Theme::VisualSelect
bright = Theme::VisualBright
(0...n).each do |i|
xx = bb.x + bb.w*dat[i].x;
yy = bb.y + bb.h/2*(1-dat[i].y);
scale = 3
vg.stroke_color sel_color if(selected == i)
vg.stroke_color bright if(selected != i)
vg.fill_color Theme::EnvelopePoint
Draw::WaveForm::env_marker(vg, xx, yy, scale)
end

def self.env_draw_markers(vg, bb, dat, stroke, selected, emode)
n = dat.length
vg.path do
vg.stroke_width 1.0

sel_color = Theme::VisualSelect
bright = Theme::VisualBright
bright2 = Theme::VisualBright2
(0...n).each do |i|
next if([1,2].include?(i))
xx = bb.x + bb.w*dat[i].x;
yy = bb.y + bb.h/2*(1-dat[i].y);
scale = 3
if(selected == i)
vg.stroke_color sel_color
elsif (i % 3 == 0)
vg.stroke_color bright
else
vg.stroke_color bright2
end
vg.fill_color Theme::EnvelopePoint
Draw::WaveForm::env_marker(vg, xx, yy, scale)
end
end
end


def self.env_marker(vg, x, y, scale)
vg.path do
vg.translate(0.5, 0.5)
@@ -279,7 +344,7 @@ def self.log_y(vg, min, max, bb)
(0...10).each do |shift|
delta = Math.log((shift+1)*1.0)/(log10*(max_-min_))
dy = bb.h*(base+delta);

next if(dy < 0 || dy > bb.h)
vg.path do |v|
v.move_to(bb.x, bb.y+dy);
@@ -362,7 +427,7 @@ def self.linear_y(vg, min, max, bb, thick=1.0, c=40)
med_fill = Theme::GridLine
light_fill = Theme::GridLine
c = max

x = (bb.x).floor
y = (bb.y).floor
w = (bb.w).floor
@@ -696,6 +761,40 @@ def self.zipToPos(x,y)
o
end

def self.zipToPosEnv(x,y,c)
o = []
n = [x.length, y.length, c.length/2].min
o << Pos.new(x[0], y[0])
(1...n).each do |i|
xcp1 = (x[i]+3*x[i-1])/4
ycp1 = (y[i]+3*y[i-1])/4 + 2*c[i*2-1]
o << Pos.new(xcp1, ycp1)
xcp2 = (3*x[i]+x[i-1])/4
ycp2 = (3*y[i]+y[i-1])/4 + 2*c[i*2]
o << Pos.new(xcp2, ycp2)

o << Pos.new(x[i], y[i])
end
o
end

def self.zipToPosCP(x,y,c)
o = []
n = [x.length, y.length, c.length/2].min
o << Pos.new(x[0], y[0])
(1...n).each do |i|
xcp1 = (x[i]+3*x[i-1])/4
ycp1 = (y[i]+3*y[i-1])/4 + 1*c[i*2-1]
o << Pos.new(xcp1, ycp1)
xcp2 = (3*x[i]+x[i-1])/4
ycp2 = (3*y[i]+y[i-1])/4 + 1*c[i*2]
o << Pos.new(xcp2, ycp2)

o << Pos.new(x[i], y[i])
end
o
end

def self.toPos(p)
o = []
n = p.length/2
@@ -774,6 +873,7 @@ module Theme

SustainPoint = color("005f8a")
EnvelopePoint = color("232c36")
EnvelopeCPoint = color("23362c")

#Keyboard Widget
KeyWhiteGrad1 = color("B0B7C0")
@@ -790,6 +890,7 @@ module Theme
VisualStroke = color("014767")
VisualLightFill = color("014767",55)
VisualBright = color("3ac5ec")
VisualBright2 = color("3ac560")
VisualDim = color("143644")
VisualDimTrans = color("143644", 155)
VisualSelect = color("00ff00")
Loading