-
Notifications
You must be signed in to change notification settings - Fork 321
/
GTKUI.jl
110 lines (98 loc) · 3.81 KB
/
GTKUI.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ************************************************************************
# FAUST Architecture File
# Copyright (C) 2021 GRAME, Centre National de Creation Musicale
# ---------------------------------------------------------------------
# This is sample code. This file is provided as an example of minimal
# FAUST architecture file. Redistribution and use in source and binary
# forms, with or without modification, in part or in full are permitted.
# In particular you can create a derived work of this FAUST architecture
# and distribute that work under terms of your choice.
# This sample code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# ************************************************************************
# Architectures files
include("/usr/local/share/faust/julia/dsp/dsp.jl")
include("/usr/local/share/faust/julia/gui/UI.jl")
using Gtk4, GtkObservables
# GTKUI: a basic GUI developed using the GtkObservables package
mutable struct GTKUI <: UI
GTKUI(dsp::dsp) = begin
gtk_ui = new()
gtk_ui.dsp = dsp
gtk_ui.box = GtkBox(:v)
gtk_ui.window = GtkWindow("Faust Program", 400, 200)
gtk_ui
end
dsp::dsp
window
box
end
function run!(ui_interface::GTKUI)
show(ui_interface.window)
#=
if !isinteractive()
@async Gtk.gtk_main()
Gtk.waitforsignal(ui_interface.window, :destroy)
end =#
if !isinteractive()
c = Condition()
signal_connect(ui_interface.window, :destroy) do widget
notify(c)
end
@async Gtk.gtk_main()
wait(c)
end
end
# -- active widgets
function addButton!(ui_interface::GTKUI, label::String, param::Symbol)
button = GtkObservables.button(label)
obs_func = on(observable(button)) do val
setproperty!(ui_interface.dsp, param, FAUSTFLOAT(1.0))
# Hack to make it work...
sleep(0.1)
setproperty!(ui_interface.dsp, param, FAUSTFLOAT(0.0))
end
push!(ui_interface.box, button)
end
function addCheckButton!(ui_interface::GTKUI, label::String, param::Symbol)
checkbox = GtkObservables.checkbox()
obs_func = on(observable(checkbox)) do val
setproperty!(ui_interface.dsp, param, FAUSTFLOAT(val))
end
push!(ui_interface.box, checkbox)
end
function addHorizontalSlider!(ui_interface::GTKUI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT)
slider = GtkObservables.slider(min:max, value=init, orientation="horizontal")
label_str = GtkObservables.label(label)
obs_func = on(observable(slider)) do val
setproperty!(ui_interface.dsp, param, val)
end
box = GtkBox(:h)
push!(box, slider)
push!(box, label_str)
push!(ui_interface.box, box)
end
function addVerticalSlider!(ui_interface::GTKUI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT)
slider = GtkObservables.slider(min:max, value=init, orientation="vertical")
set_gtk_property!(slider, :expand, true)
label_str = GtkObservables.label(label)
obs_func = on(observable(slider)) do val
setproperty!(ui_interface.dsp, param, val)
end
box = GtkBox(:v)
push!(box, slider)
push!(box, label_str)
push!(ui_interface.box, box)
end
function addNumEntry!(ui_interface::GTKUI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT)
nentry = GtkObservables.textbox(FAUSTFLOAT; range=min:max, value=string(init))
label_str = GtkObservables.label(label)
obs_func = on(observable(nentry)) do val
setproperty!(ui_interface.dsp, param, val)
end
box = GtkBox(:h)
push!(box, nentry)
push!(box, label_str)
push!(ui_interface.box, box)
end