libui_paradise 0.2.48
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of libui_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +2064 -0
- data/doc/README.gen +1923 -0
- data/doc/SNIPPETS.md +94 -0
- data/doc/todo/todo.md +16 -0
- data/lib/libui_paradise/autoinclude.rb +9 -0
- data/lib/libui_paradise/base/base.rb +154 -0
- data/lib/libui_paradise/colours/colours.rb +14 -0
- data/lib/libui_paradise/domain_specific_language/README.md +5 -0
- data/lib/libui_paradise/domain_specific_language/button.yml +7 -0
- data/lib/libui_paradise/examples/complex/001_hbox_example.rb +17 -0
- data/lib/libui_paradise/examples/complex/002_tabs_example.rb +25 -0
- data/lib/libui_paradise/examples/complex/003_open_file_button_example.rb +38 -0
- data/lib/libui_paradise/examples/complex/004_font_button.rb +41 -0
- data/lib/libui_paradise/examples/complex/005_search_entry_example.rb +18 -0
- data/lib/libui_paradise/examples/complex/006_coloured_boxes_example.rb +22 -0
- data/lib/libui_paradise/examples/complex/007_slider_example.rb +31 -0
- data/lib/libui_paradise/examples/complex/008_radio_button_example.rb +23 -0
- data/lib/libui_paradise/examples/complex/009_separator_example.rb +25 -0
- data/lib/libui_paradise/examples/complex/010_table_example.rb +55 -0
- data/lib/libui_paradise/examples/complex/011_two_buttons_showing_how_to_enable_and_disable_them.rb +32 -0
- data/lib/libui_paradise/examples/complex/012_password_entry_example.rb +29 -0
- data/lib/libui_paradise/examples/complex/013_form_example.rb +38 -0
- data/lib/libui_paradise/examples/complex/014_text_example.rb +18 -0
- data/lib/libui_paradise/examples/complex/015_text_view_example.rb +16 -0
- data/lib/libui_paradise/examples/complex/016_grid_example.rb +31 -0
- data/lib/libui_paradise/examples/complex/017_unicode_text_example.rb +30 -0
- data/lib/libui_paradise/examples/complex/018_spinbutton_example.rb +33 -0
- data/lib/libui_paradise/examples/complex/019_combo_box_example.rb +50 -0
- data/lib/libui_paradise/examples/complex/020_checkbox_example.rb +81 -0
- data/lib/libui_paradise/examples/complex/021_font_example.rb +115 -0
- data/lib/libui_paradise/examples/complex/022_simple_notepad_example.rb +25 -0
- data/lib/libui_paradise/examples/complex/023_msg_box_error.rb +27 -0
- data/lib/libui_paradise/examples/complex/024_parse_config_file_example.config +6 -0
- data/lib/libui_paradise/examples/complex/024_parse_config_file_example.rb +15 -0
- data/lib/libui_paradise/examples/complex/025_colour_button.rb +53 -0
- data/lib/libui_paradise/examples/complex/026_basic_table_image.rb +96 -0
- data/lib/libui_paradise/examples/complex/027_basic_button_example.rb +19 -0
- data/lib/libui_paradise/examples/complex/028_try_for_automatic_button_press_event_after_a_delay.rb +47 -0
- data/lib/libui_paradise/examples/complex/029_progressbar_example.rb +116 -0
- data/lib/libui_paradise/examples/complex/030_entry_responds_to_comment_as_synonymous_to_the_enter_key_pressed_example.rb +140 -0
- data/lib/libui_paradise/examples/complex/031_notification_functionality_example.rb +96 -0
- data/lib/libui_paradise/examples/complex/032_simple_window_example.rb +69 -0
- data/lib/libui_paradise/examples/complex/033_daemonize_and_exit_after_delay_example.rb +91 -0
- data/lib/libui_paradise/examples/simple/001_open_file_example.rb +35 -0
- data/lib/libui_paradise/examples/simple/002_histogram_example.rb +207 -0
- data/lib/libui_paradise/examples/simple/003_fancy_text_example.rb +220 -0
- data/lib/libui_paradise/examples/simple/004_date_time_picker.rb +52 -0
- data/lib/libui_paradise/examples/simple/005_text_drawing_example.rb +185 -0
- data/lib/libui_paradise/examples/simple/006_midi_player.rb +96 -0
- data/lib/libui_paradise/examples/simple/007_control_gallery.rb +191 -0
- data/lib/libui_paradise/examples/simple/008_basic_area_example.rb +56 -0
- data/lib/libui_paradise/examples/simple/009_spectrum.rb +107 -0
- data/lib/libui_paradise/examples/simple/README.md +7 -0
- data/lib/libui_paradise/experimental/dsl.rb +17 -0
- data/lib/libui_paradise/extensions/counters.rb +58 -0
- data/lib/libui_paradise/extensions/extensions.rb +29 -0
- data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +150 -0
- data/lib/libui_paradise/extensions/misc.rb +754 -0
- data/lib/libui_paradise/fiddle/pointer.rb +1157 -0
- data/lib/libui_paradise/generic_window/README.md +9 -0
- data/lib/libui_paradise/generic_window/generic_window.rb +79 -0
- data/lib/libui_paradise/images/LIBUI_PARADISE_LOGO.png +0 -0
- data/lib/libui_paradise/images/README.md +2 -0
- data/lib/libui_paradise/images/form_example.png +0 -0
- data/lib/libui_paradise/libui_classes/box.rb +156 -0
- data/lib/libui_paradise/libui_classes/grid.rb +55 -0
- data/lib/libui_paradise/libui_classes/libui_classes.rb +1610 -0
- data/lib/libui_paradise/project/project.rb +28 -0
- data/lib/libui_paradise/prototype/README.md +3 -0
- data/lib/libui_paradise/prototype/prototype.rb +107 -0
- data/lib/libui_paradise/requires/require_the_libui_classes.rb +29 -0
- data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +12 -0
- data/lib/libui_paradise/toplevel_methods/misc.rb +13 -0
- data/lib/libui_paradise/version/version.rb +17 -0
- data/lib/libui_paradise.rb +1 -0
- data/libui_paradise.gemspec +49 -0
- data/test/testing_generic_window.rb +19 -0
- metadata +156 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui'
|
6
|
+
|
7
|
+
LibUI.init
|
8
|
+
|
9
|
+
UI = LibUI
|
10
|
+
|
11
|
+
music_directory = File.expand_path(ARGV[0] || '~/Music/')
|
12
|
+
midi_files = Dir.glob(File.join(music_directory, '**/*.mid'))
|
13
|
+
.sort_by { |path| File.basename(path) }
|
14
|
+
VERSION = '0.0.1'.freeze
|
15
|
+
|
16
|
+
@pid = nil
|
17
|
+
|
18
|
+
play_midi = proc do
|
19
|
+
if @pid.nil? && @selected_file
|
20
|
+
begin
|
21
|
+
@pid = spawn "timidity #{@selected_file}"
|
22
|
+
@th = Process.detach @pid
|
23
|
+
rescue Errno::ENOENT => _error
|
24
|
+
warn 'Timidty++ was not found. Please install Timidity++.'
|
25
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
31
|
+
stop_midi = proc do
|
32
|
+
if @pid
|
33
|
+
if @th.alive?
|
34
|
+
Process.kill(:SIGKILL, @pid)
|
35
|
+
@pid = nil
|
36
|
+
else
|
37
|
+
@pid = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
help_menu = LibUI.new_menu('Help')
|
43
|
+
version_item = LibUI.menu_append_item(help_menu, 'Version')
|
44
|
+
|
45
|
+
LibUI.new_window('Tiny Midi Player', 200, 50, 1).tap do |main_window|
|
46
|
+
LibUI.menu_item_on_clicked(version_item) {
|
47
|
+
LibUI.msg_box(main_window,
|
48
|
+
'Tiny Midi Player',
|
49
|
+
"Written in Ruby\n" \
|
50
|
+
"https://github.com/kojix2/libui\n Version #{VERSION}"
|
51
|
+
)
|
52
|
+
0
|
53
|
+
}
|
54
|
+
|
55
|
+
LibUI.window_on_closing(main_window) {
|
56
|
+
LibUI.control_destroy(main_window)
|
57
|
+
LibUI.quit
|
58
|
+
0
|
59
|
+
}
|
60
|
+
|
61
|
+
LibUI.new_horizontal_box.tap do |hbox|
|
62
|
+
LibUI.new_vertical_box.tap do |vbox|
|
63
|
+
LibUI.new_button('▶').tap { |button1|
|
64
|
+
LibUI.button_on_clicked(button1, play_midi)
|
65
|
+
LibUI.box_append(vbox, button1, 1)
|
66
|
+
}
|
67
|
+
LibUI.new_button('■').tap { |button2|
|
68
|
+
LibUI.button_on_clicked(button2, stop_midi)
|
69
|
+
at_exit(&stop_midi)
|
70
|
+
LibUI.box_append(vbox, button2, 0)
|
71
|
+
}
|
72
|
+
LibUI.box_append(hbox, vbox, 0)
|
73
|
+
end
|
74
|
+
LibUI.window_set_child(main_window, hbox)
|
75
|
+
|
76
|
+
LibUI.new_combobox.tap do |cbox|
|
77
|
+
midi_files.each { |path|
|
78
|
+
name = File.basename(path)
|
79
|
+
LibUI.combobox_append(cbox, name)
|
80
|
+
}
|
81
|
+
LibUI.combobox_on_selected(cbox) { |ptr|
|
82
|
+
@selected_file = midi_files[UI.combobox_selected(ptr)]
|
83
|
+
if @th && @th.alive?
|
84
|
+
stop_midi.call
|
85
|
+
play_midi.call
|
86
|
+
end
|
87
|
+
0
|
88
|
+
}
|
89
|
+
LibUI.box_append(hbox, cbox, 1)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
LibUI.control_show(main_window)
|
93
|
+
end
|
94
|
+
|
95
|
+
LibUI.main
|
96
|
+
LibUI.quit
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# require '007_control_gallery.rb'
|
2
|
+
require 'libui'
|
3
|
+
UI = LibUI
|
4
|
+
|
5
|
+
UI.init
|
6
|
+
|
7
|
+
should_quit = proc do
|
8
|
+
puts 'Bye Bye'
|
9
|
+
UI.control_destroy(MAIN_WINDOW)
|
10
|
+
UI.quit
|
11
|
+
0
|
12
|
+
end
|
13
|
+
|
14
|
+
# File menu
|
15
|
+
menu = UI.new_menu('File')
|
16
|
+
open_menu_item = UI.menu_append_item(menu, 'Open')
|
17
|
+
UI.menu_item_on_clicked(open_menu_item) do
|
18
|
+
pt = UI.open_file(MAIN_WINDOW)
|
19
|
+
puts pt unless pt.null?
|
20
|
+
end
|
21
|
+
save_menu_item = UI.menu_append_item(menu, 'Save')
|
22
|
+
UI.menu_item_on_clicked(save_menu_item) do
|
23
|
+
pt = UI.save_file(MAIN_WINDOW)
|
24
|
+
puts pt unless pt.null?
|
25
|
+
end
|
26
|
+
|
27
|
+
UI.menu_append_quit_item(menu)
|
28
|
+
UI.on_should_quit(should_quit)
|
29
|
+
|
30
|
+
# Edit menu
|
31
|
+
edit_menu = UI.new_menu('Edit')
|
32
|
+
UI.menu_append_check_item(edit_menu, 'Checkable Item_')
|
33
|
+
UI.menu_append_separator(edit_menu)
|
34
|
+
disabled_item = UI.menu_append_item(edit_menu, 'Disabled Item_')
|
35
|
+
UI.menu_item_disable(disabled_item)
|
36
|
+
|
37
|
+
preferences = UI.menu_append_preferences_item(menu)
|
38
|
+
|
39
|
+
# Help menu
|
40
|
+
help_menu = UI.new_menu('Help')
|
41
|
+
UI.menu_append_item(help_menu, 'Help')
|
42
|
+
UI.menu_append_about_item(help_menu)
|
43
|
+
|
44
|
+
# Main Window
|
45
|
+
MAIN_WINDOW = UI.new_window('Control Gallery', 600, 500, 1)
|
46
|
+
UI.window_set_margined(MAIN_WINDOW, 1)
|
47
|
+
UI.window_on_closing(MAIN_WINDOW, should_quit)
|
48
|
+
|
49
|
+
vbox = UI.new_vertical_box
|
50
|
+
UI.window_set_child(MAIN_WINDOW, vbox)
|
51
|
+
hbox = UI.new_horizontal_box
|
52
|
+
UI.box_set_padded(vbox, 1)
|
53
|
+
UI.box_set_padded(hbox, 1)
|
54
|
+
|
55
|
+
UI.box_append(vbox, hbox, 1)
|
56
|
+
|
57
|
+
# Group - Basic Controls
|
58
|
+
group = UI.new_group('Basic Controls')
|
59
|
+
UI.group_set_margined(group, 1)
|
60
|
+
UI.box_append(hbox, group, 1) # OSX bug?
|
61
|
+
|
62
|
+
inner = UI.new_vertical_box
|
63
|
+
UI.box_set_padded(inner, 1)
|
64
|
+
UI.group_set_child(group, inner)
|
65
|
+
|
66
|
+
# Button
|
67
|
+
button = UI.new_button('Button')
|
68
|
+
UI.button_on_clicked(button) do
|
69
|
+
UI.msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
|
70
|
+
end
|
71
|
+
UI.box_append(inner, button, 0)
|
72
|
+
|
73
|
+
# Checkbox
|
74
|
+
checkbox = UI.new_checkbox('Checkbox')
|
75
|
+
UI.checkbox_on_toggled(checkbox) do |ptr|
|
76
|
+
checked = UI.checkbox_checked(ptr) == 1
|
77
|
+
UI.window_set_title(MAIN_WINDOW, "Checkbox is #{checked}")
|
78
|
+
UI.checkbox_set_text(ptr, "I am the checkbox (#{checked})")
|
79
|
+
end
|
80
|
+
UI.box_append(inner, checkbox, 0)
|
81
|
+
|
82
|
+
# Label
|
83
|
+
UI.box_append(inner, UI.new_label('Label'), 0)
|
84
|
+
|
85
|
+
# Separator
|
86
|
+
UI.box_append(inner, UI.new_horizontal_separator, 0)
|
87
|
+
|
88
|
+
# Date Picker
|
89
|
+
UI.box_append(inner, UI.new_date_picker, 0)
|
90
|
+
|
91
|
+
# Time Picker
|
92
|
+
UI.box_append(inner, UI.new_time_picker, 0)
|
93
|
+
|
94
|
+
# Date Time Picker
|
95
|
+
UI.box_append(inner, UI.new_date_time_picker, 0)
|
96
|
+
|
97
|
+
# Font Button
|
98
|
+
UI.box_append(inner, UI.new_font_button, 0)
|
99
|
+
|
100
|
+
# Color Button
|
101
|
+
UI.box_append(inner, UI.new_color_button, 0)
|
102
|
+
|
103
|
+
inner2 = UI.new_vertical_box
|
104
|
+
UI.box_set_padded(inner2, 1)
|
105
|
+
UI.box_append(hbox, inner2, 1)
|
106
|
+
|
107
|
+
# Group - Numbers
|
108
|
+
group = UI.new_group('Numbers')
|
109
|
+
UI.group_set_margined(group, 1)
|
110
|
+
UI.box_append(inner2, group, 0)
|
111
|
+
|
112
|
+
inner = UI.new_vertical_box
|
113
|
+
UI.box_set_padded(inner, 1)
|
114
|
+
UI.group_set_child(group, inner)
|
115
|
+
|
116
|
+
# Spinbox
|
117
|
+
spinbox = UI.new_spinbox(0, 100)
|
118
|
+
UI.spinbox_set_value(spinbox, 42)
|
119
|
+
UI.spinbox_on_changed(spinbox) do |ptr|
|
120
|
+
puts "New Spinbox value: #{UI.spinbox_value(ptr)}"
|
121
|
+
end
|
122
|
+
UI.box_append(inner, spinbox, 0)
|
123
|
+
|
124
|
+
# Slider
|
125
|
+
slider = UI.new_slider(0, 100)
|
126
|
+
UI.box_append(inner, slider, 0)
|
127
|
+
|
128
|
+
# Progressbar
|
129
|
+
progressbar = UI.new_progress_bar
|
130
|
+
UI.box_append(inner, progressbar, 0)
|
131
|
+
|
132
|
+
UI.slider_on_changed(slider) do |ptr|
|
133
|
+
v = UI.slider_value(ptr)
|
134
|
+
puts "New Slider value: #{v}"
|
135
|
+
UI.progress_bar_set_value(progressbar, v)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Group - Lists
|
139
|
+
group = UI.new_group('Lists')
|
140
|
+
UI.group_set_margined(group, 1)
|
141
|
+
UI.box_append(inner2, group, 0)
|
142
|
+
|
143
|
+
inner = UI.new_vertical_box
|
144
|
+
UI.box_set_padded(inner, 1)
|
145
|
+
UI.group_set_child(group, inner)
|
146
|
+
|
147
|
+
# Combobox
|
148
|
+
cbox = UI.new_combobox
|
149
|
+
UI.combobox_append(cbox, 'combobox Item 1')
|
150
|
+
UI.combobox_append(cbox, 'combobox Item 2')
|
151
|
+
UI.combobox_append(cbox, 'combobox Item 3')
|
152
|
+
UI.box_append(inner, cbox, 0)
|
153
|
+
UI.combobox_on_selected(cbox) do |ptr|
|
154
|
+
puts "New combobox selection: #{UI.combobox_selected(ptr)}"
|
155
|
+
end
|
156
|
+
|
157
|
+
# Editable Combobox
|
158
|
+
ebox = UI.new_editable_combobox
|
159
|
+
UI.editable_combobox_append(ebox, 'Editable Item 1')
|
160
|
+
UI.editable_combobox_append(ebox, 'Editable Item 2')
|
161
|
+
UI.editable_combobox_append(ebox, 'Editable Item 3')
|
162
|
+
UI.box_append(inner, ebox, 0)
|
163
|
+
|
164
|
+
# Radio Buttons
|
165
|
+
rb = UI.new_radio_buttons
|
166
|
+
UI.radio_buttons_append(rb, 'Radio Button 1')
|
167
|
+
UI.radio_buttons_append(rb, 'Radio Button 2')
|
168
|
+
UI.radio_buttons_append(rb, 'Radio Button 3')
|
169
|
+
UI.box_append(inner, rb, 1)
|
170
|
+
|
171
|
+
# Tab
|
172
|
+
tab = UI.new_tab
|
173
|
+
hbox1 = UI.new_horizontal_box
|
174
|
+
hbox2 = UI.new_horizontal_box
|
175
|
+
UI.tab_append(tab, 'Page 1', hbox1)
|
176
|
+
UI.tab_append(tab, 'Page 2', hbox2)
|
177
|
+
UI.tab_append(tab, 'Page 3', UI.new_horizontal_box)
|
178
|
+
UI.box_append(inner2, tab, 1)
|
179
|
+
|
180
|
+
# Text Entry
|
181
|
+
text_entry = UI.new_entry
|
182
|
+
UI.entry_set_text text_entry, 'Please enter your feelings'
|
183
|
+
UI.entry_on_changed(text_entry) do |ptr|
|
184
|
+
puts "Current textbox data: '#{UI.entry_text(ptr)}'"
|
185
|
+
end
|
186
|
+
UI.box_append(hbox1, text_entry, 1)
|
187
|
+
|
188
|
+
UI.control_show(MAIN_WINDOW)
|
189
|
+
|
190
|
+
LibUI.main
|
191
|
+
LibUI.quit
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui'
|
6
|
+
|
7
|
+
UI = LibUI
|
8
|
+
UI.init
|
9
|
+
|
10
|
+
handler = UI::FFI::AreaHandler.malloc
|
11
|
+
handler.to_ptr.free = Fiddle::RUBY_FREE
|
12
|
+
area = UI.new_area(handler)
|
13
|
+
brush = UI::FFI::DrawBrush.malloc
|
14
|
+
brush.to_ptr.free = Fiddle::RUBY_FREE
|
15
|
+
|
16
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
|
17
|
+
path = UI.draw_new_path(0)
|
18
|
+
UI.draw_path_add_rectangle(path, 0, 0, 500, 500)
|
19
|
+
UI.draw_path_end(path)
|
20
|
+
brush.Type = 0
|
21
|
+
# Define the colour in use:
|
22
|
+
brush.R = 0.2
|
23
|
+
brush.G = 0.4
|
24
|
+
brush.B = 0.8
|
25
|
+
brush.A = 1.0
|
26
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
|
27
|
+
UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
|
28
|
+
UI.draw_free_path(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
do_nothing = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
32
|
+
key_event = Fiddle::Closure::BlockCaller.new(1, [0]) { 0 }
|
33
|
+
|
34
|
+
handler.Draw = handler_draw_event
|
35
|
+
handler.MouseEvent = do_nothing
|
36
|
+
handler.MouseCrossed = do_nothing
|
37
|
+
handler.DragBroken = do_nothing
|
38
|
+
handler.KeyEvent = key_event
|
39
|
+
|
40
|
+
box = UI.new_vertical_box
|
41
|
+
UI.box_set_padded(box, 1)
|
42
|
+
UI.box_append(box, area, 1)
|
43
|
+
|
44
|
+
main_window = UI.new_window('Basic Area', 800, 500, 1)
|
45
|
+
UI.window_set_margined(main_window, 1)
|
46
|
+
UI.window_set_child(main_window, box)
|
47
|
+
|
48
|
+
UI.window_on_closing(main_window) {
|
49
|
+
UI.control_destroy(main_window)
|
50
|
+
UI.quit
|
51
|
+
0
|
52
|
+
}
|
53
|
+
UI.control_show(main_window)
|
54
|
+
|
55
|
+
UI.main
|
56
|
+
UI.quit
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# =========================================================================== #
|
3
|
+
require 'libui'
|
4
|
+
require 'ffi-portaudio' # https://github.com/nanki/ffi-portaudio
|
5
|
+
require 'numo/pocketfft' # https://github.com/yoshoku/numo-pocketfft
|
6
|
+
|
7
|
+
# =========================================================================== #
|
8
|
+
# === FFTStream
|
9
|
+
# =========================================================================== #
|
10
|
+
class FFTStream < FFI::PortAudio::Stream
|
11
|
+
def process(input, _output, frame_count, _time_info, _status_flags, _user_data)
|
12
|
+
i = Numo::Int16.cast(input.read_array_of_int16(frame_count))
|
13
|
+
@spec = (Numo::Pocketfft.rfft(i)[0..511].abs / 1000.0).to_a
|
14
|
+
:paContinue
|
15
|
+
end
|
16
|
+
|
17
|
+
def spec
|
18
|
+
@spec || [0] * 512
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
FFI::PortAudio::API.Pa_Initialize
|
23
|
+
|
24
|
+
input = FFI::PortAudio::API::PaStreamParameters.new
|
25
|
+
input[:device] = FFI::PortAudio::API.Pa_GetDefaultInputDevice
|
26
|
+
input[:channelCount] = 1
|
27
|
+
input[:sampleFormat] = FFI::PortAudio::API::Int16
|
28
|
+
input[:suggestedLatency] = 0
|
29
|
+
input[:hostApiSpecificStreamInfo] = nil
|
30
|
+
stream = FFTStream.new
|
31
|
+
stream.open(input, nil, 44_100, 1024)
|
32
|
+
stream.start
|
33
|
+
|
34
|
+
|
35
|
+
UI = LibUI
|
36
|
+
|
37
|
+
UI.init
|
38
|
+
|
39
|
+
handler = UI::FFI::AreaHandler.malloc
|
40
|
+
area = UI.new_area(handler)
|
41
|
+
|
42
|
+
brush = UI::FFI::DrawBrush.malloc.tap do |b|
|
43
|
+
b.Type = 0
|
44
|
+
b.R = 0.9
|
45
|
+
b.G = 0.2
|
46
|
+
b.B = 0.6
|
47
|
+
b.A = 1.0
|
48
|
+
end
|
49
|
+
|
50
|
+
dashes = Fiddle::Pointer.malloc(8, Fiddle::RUBY_FREE)
|
51
|
+
stroke_params = UI::FFI::DrawStrokeParams.malloc.tap do |sp|
|
52
|
+
sp.Cap = UI::DrawLineCapFlat
|
53
|
+
sp.Join = UI::DrawLineJoinMiter
|
54
|
+
sp.MiterLimit = 10
|
55
|
+
sp.Dashes = dashes
|
56
|
+
sp.NumDashes = 0
|
57
|
+
sp.DashPhase = 0
|
58
|
+
sp.Thickness = 1.0
|
59
|
+
end
|
60
|
+
|
61
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
|
62
|
+
UI.draw_new_path(UI::DrawFillModeWinding).then do |path|
|
63
|
+
stream.spec.each.with_index do |i, j|
|
64
|
+
UI.draw_path_new_figure(path, 10 + j, 121)
|
65
|
+
UI.draw_path_line_to(path, 10 + j, 120 - [i, 120].min)
|
66
|
+
end
|
67
|
+
UI.draw_path_end(path)
|
68
|
+
|
69
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
|
70
|
+
UI.draw_stroke(area_draw_params.Context, path, brush.to_ptr, stroke_params)
|
71
|
+
UI.draw_free_path(path)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
handler.Draw = handler_draw_event
|
76
|
+
do_nothing = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
77
|
+
key_event = Fiddle::Closure::BlockCaller.new(1, [0]) { 0 }
|
78
|
+
handler.MouseEvent = do_nothing
|
79
|
+
handler.MouseCrossed = do_nothing
|
80
|
+
handler.DragBroken = do_nothing
|
81
|
+
handler.KeyEvent = key_event
|
82
|
+
|
83
|
+
box = UI.new_vertical_box
|
84
|
+
UI.box_set_padded(box, 1)
|
85
|
+
UI.box_append(box, area, 1)
|
86
|
+
|
87
|
+
main_window = UI.new_window('SPECTRUM', 560, 150, 1)
|
88
|
+
UI.window_set_margined(main_window, 1)
|
89
|
+
UI.window_set_child(main_window, box)
|
90
|
+
|
91
|
+
UI.window_on_closing(main_window) do
|
92
|
+
UI.control_destroy(main_window)
|
93
|
+
UI.quit
|
94
|
+
stream.close
|
95
|
+
::FFI::PortAudio::API.Pa_Terminate
|
96
|
+
0
|
97
|
+
end
|
98
|
+
UI.control_show(main_window)
|
99
|
+
|
100
|
+
UI.queue_main do
|
101
|
+
UI.timer(100) do
|
102
|
+
UI.area_queue_redraw_all(area)
|
103
|
+
1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
UI.main
|
107
|
+
UI.quit
|
@@ -0,0 +1,7 @@
|
|
1
|
+
This directory contains examples that are only allowed to use
|
2
|
+
vanilla-code for kojix2' libui. If you want to tap into the
|
3
|
+
code that the libui_paradise gem makes available then you
|
4
|
+
should look at the complex/ subdirectory instead.
|
5
|
+
|
6
|
+
External dependencies are permissible, if kojix2' makes use
|
7
|
+
of them in the examples he provides.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui_paradise/autoinclude'
|
6
|
+
|
7
|
+
def do_call_this_method
|
8
|
+
e 'Hello World!'
|
9
|
+
end
|
10
|
+
|
11
|
+
window {
|
12
|
+
|
13
|
+
button {
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'libui_paradise/extensions/counters.rb
|
6
|
+
# =========================================================================== #
|
7
|
+
module LibuiParadise
|
8
|
+
|
9
|
+
# =========================================================================== #
|
10
|
+
# === @counter_left
|
11
|
+
# =========================================================================== #
|
12
|
+
@counter_left = 0
|
13
|
+
|
14
|
+
# =========================================================================== #
|
15
|
+
# === LibuiParadise.counter_left?
|
16
|
+
# =========================================================================== #
|
17
|
+
def self.counter_left?
|
18
|
+
@counter_left
|
19
|
+
end; self.instance_eval { alias counter_left counter_left? } # === LibuiParadise.counter_left
|
20
|
+
self.instance_eval { alias left_counter counter_left? } # === LibuiParadise.left_counter
|
21
|
+
self.instance_eval { alias left_counter? counter_left? } # === LibuiParadise.left_counter?
|
22
|
+
|
23
|
+
# =========================================================================== #
|
24
|
+
# === LibuiParadise.counter_left=
|
25
|
+
# =========================================================================== #
|
26
|
+
def self.counter_left=(i = 1)
|
27
|
+
@counter_left = i
|
28
|
+
end
|
29
|
+
|
30
|
+
# =========================================================================== #
|
31
|
+
# === @counter_top
|
32
|
+
# =========================================================================== #
|
33
|
+
@counter_top = 0
|
34
|
+
|
35
|
+
# =========================================================================== #
|
36
|
+
# === LibuiParadise.counter_top?
|
37
|
+
# =========================================================================== #
|
38
|
+
def self.counter_top?
|
39
|
+
@counter_top
|
40
|
+
end; self.instance_eval { alias counter_top counter_top? } # === LibuiParadise.counter_top
|
41
|
+
self.instance_eval { alias top_counter counter_top? } # === LibuiParadise.top_counter
|
42
|
+
self.instance_eval { alias top_counter? counter_top? } # === LibuiParadise.top_counter?
|
43
|
+
|
44
|
+
# =========================================================================== #
|
45
|
+
# === LibuiParadise.counter_top=
|
46
|
+
# =========================================================================== #
|
47
|
+
def self.counter_top=(i = 1)
|
48
|
+
@counter_top = i
|
49
|
+
end
|
50
|
+
|
51
|
+
# =========================================================================== #
|
52
|
+
# === LibuiParadise.counters?
|
53
|
+
# =========================================================================== #
|
54
|
+
def self.counters?
|
55
|
+
return [@counter_left, @counter_top]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === LibuiParadise::Extensions
|
6
|
+
#
|
7
|
+
# This .rb file is primarly used to "extend" libui in a convenient
|
8
|
+
# way. That way we only have to require this file and the rest will
|
9
|
+
# be set up correctly for us.
|
10
|
+
# =========================================================================== #
|
11
|
+
# require 'libui_paradise/extensions/extensions.rb
|
12
|
+
# include Libuiparadise::Extensions
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'libui' # Mandatory require-call.
|
15
|
+
|
16
|
+
module LibuiParadise
|
17
|
+
|
18
|
+
module Extensions # === LibuiParadise::Extensions
|
19
|
+
|
20
|
+
require 'libui_paradise/fiddle/pointer.rb'
|
21
|
+
require 'libui_paradise/extensions/hash_fiddle_pointer_widgets.rb'
|
22
|
+
require 'libui_paradise/extensions/misc.rb'
|
23
|
+
require 'libui_paradise/libui_classes/libui_classes.rb'
|
24
|
+
|
25
|
+
end; end
|
26
|
+
|
27
|
+
alias e puts
|
28
|
+
|
29
|
+
LibuiParadise::Extensions.initializer # Make UI known here.
|