fiddle_fluidsynth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +138 -0
- data/Rakefile +14 -0
- data/examples/enum.rb +30 -0
- data/examples/example.sf2 +0 -0
- data/examples/ffs_arpeggio.rb +252 -0
- data/examples/ffs_example.rb +47 -0
- data/examples/ffs_fx.rb +200 -0
- data/examples/ffs_metronome.rb +260 -0
- data/examples/ffs_midiplay.rb +122 -0
- data/examples/ffs_simple.rb +45 -0
- data/examples/ffs_test1.rb +41 -0
- data/examples/ffs_test3.rb +50 -0
- data/examples/fiddle-pointer.rb +18 -0
- data/examples/presets-each.rb +66 -0
- data/examples/presets-full_scan.rb +59 -0
- data/examples/settings-each.rb +106 -0
- data/exe/ffs_midiplay.rb +122 -0
- data/lib/fiddle_fluidsynth/audio_output/driver.rb +104 -0
- data/lib/fiddle_fluidsynth/audio_output/file_renderer.rb +84 -0
- data/lib/fiddle_fluidsynth/audio_output.rb +7 -0
- data/lib/fiddle_fluidsynth/command_interface/command_interface.rb +90 -0
- data/lib/fiddle_fluidsynth/command_interface/handler.rb +95 -0
- data/lib/fiddle_fluidsynth/command_interface/server.rb +79 -0
- data/lib/fiddle_fluidsynth/command_interface/shell.rb +76 -0
- data/lib/fiddle_fluidsynth/command_interface.rb +9 -0
- data/lib/fiddle_fluidsynth/core_ext/fiddle.rb +142 -0
- data/lib/fiddle_fluidsynth/core_ext/module.rb +123 -0
- data/lib/fiddle_fluidsynth/fiddle_fluidsynth.rb +172 -0
- data/lib/fiddle_fluidsynth/logging/logging.rb +82 -0
- data/lib/fiddle_fluidsynth/logging.rb +6 -0
- data/lib/fiddle_fluidsynth/midi_input/driver.rb +77 -0
- data/lib/fiddle_fluidsynth/midi_input/events.rb +255 -0
- data/lib/fiddle_fluidsynth/midi_input/midi_input.rb +70 -0
- data/lib/fiddle_fluidsynth/midi_input/player.rb +289 -0
- data/lib/fiddle_fluidsynth/midi_input/router.rb +225 -0
- data/lib/fiddle_fluidsynth/midi_input.rb +11 -0
- data/lib/fiddle_fluidsynth/misc/misc.rb +162 -0
- data/lib/fiddle_fluidsynth/misc.rb +6 -0
- data/lib/fiddle_fluidsynth/sequencer/events.rb +679 -0
- data/lib/fiddle_fluidsynth/sequencer/sequencer.rb +384 -0
- data/lib/fiddle_fluidsynth/sequencer.rb +7 -0
- data/lib/fiddle_fluidsynth/settings/settings.rb +465 -0
- data/lib/fiddle_fluidsynth/settings.rb +6 -0
- data/lib/fiddle_fluidsynth/soundfonts/generators.rb +128 -0
- data/lib/fiddle_fluidsynth/soundfonts/loader.rb +506 -0
- data/lib/fiddle_fluidsynth/soundfonts/modulators.rb +247 -0
- data/lib/fiddle_fluidsynth/soundfonts/soundfonts.rb +64 -0
- data/lib/fiddle_fluidsynth/soundfonts/voices.rb +178 -0
- data/lib/fiddle_fluidsynth/soundfonts.rb +11 -0
- data/lib/fiddle_fluidsynth/synth/audio_rendering.rb +100 -0
- data/lib/fiddle_fluidsynth/synth/effect/chorus.rb +269 -0
- data/lib/fiddle_fluidsynth/synth/effect/iir_filter.rb +81 -0
- data/lib/fiddle_fluidsynth/synth/effect/ladspa.rb +172 -0
- data/lib/fiddle_fluidsynth/synth/effect/reverb.rb +207 -0
- data/lib/fiddle_fluidsynth/synth/effect.rb +10 -0
- data/lib/fiddle_fluidsynth/synth/midi/messages.rb +292 -0
- data/lib/fiddle_fluidsynth/synth/midi/setup.rb +235 -0
- data/lib/fiddle_fluidsynth/synth/midi/tuning.rb +128 -0
- data/lib/fiddle_fluidsynth/synth/midi.rb +9 -0
- data/lib/fiddle_fluidsynth/synth/params/params.rb +200 -0
- data/lib/fiddle_fluidsynth/synth/params.rb +8 -0
- data/lib/fiddle_fluidsynth/synth/soundfont_management.rb +210 -0
- data/lib/fiddle_fluidsynth/synth/synth.rb +114 -0
- data/lib/fiddle_fluidsynth/synth/voice_control.rb +94 -0
- data/lib/fiddle_fluidsynth/synth.rb +18 -0
- data/lib/fiddle_fluidsynth/types/types.rb +131 -0
- data/lib/fiddle_fluidsynth/types.rb +10 -0
- data/lib/fiddle_fluidsynth/util/callback.rb +585 -0
- data/lib/fiddle_fluidsynth/util/interface/settings.rb +689 -0
- data/lib/fiddle_fluidsynth/util/interface/soundfont.rb +115 -0
- data/lib/fiddle_fluidsynth/util/interface/soundfont_preset.rb +69 -0
- data/lib/fiddle_fluidsynth/util/interface/soundfont_sample.rb +61 -0
- data/lib/fiddle_fluidsynth/util/interface.rb +11 -0
- data/lib/fiddle_fluidsynth/util/module_hier.rb +403 -0
- data/lib/fiddle_fluidsynth/util/util.rb +467 -0
- data/lib/fiddle_fluidsynth/util-after.rb +12 -0
- data/lib/fiddle_fluidsynth/util.rb +37 -0
- data/lib/fiddle_fluidsynth/version.rb +10 -0
- data/lib/fiddle_fluidsynth.rb +57 -0
- data/sig/fiddle_fluidsynth.rbs +4 -0
- metadata +128 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
#
|
2
|
+
# filename: fiddle-fluidstynth/command_interface/handler.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
# References
|
7
|
+
# - [API Reference](https://www.fluidsynth.org/api/modules.html)
|
8
|
+
#
|
9
|
+
class FiddleFluidSynth
|
10
|
+
|
11
|
+
# Handles text commands and reading of configuration files.
|
12
|
+
# ==== References
|
13
|
+
# - API References, Command Interface/[Command Handler](https://www.fluidsynth.org/api/group__command__handler.html)
|
14
|
+
# - [library fiddle](https://docs.ruby-lang.org/ja/latest/library/fiddle.html)
|
15
|
+
#
|
16
|
+
|
17
|
+
#
|
18
|
+
module C
|
19
|
+
|
20
|
+
# Lifecycle Functions.
|
21
|
+
#
|
22
|
+
#
|
23
|
+
|
24
|
+
# Create a new command handler.
|
25
|
+
extern 'fluid_cmd_handler_t* new_fluid_cmd_handler' +
|
26
|
+
'(fluid_synth_t*, fluid_midi_router_t*)'
|
27
|
+
|
28
|
+
# Create a new command handler.
|
29
|
+
extern 'fluid_cmd_handler_t* new_fluid_cmd_handler2' +
|
30
|
+
'(fluid_settings_t*, fluid_synth_t*,' +
|
31
|
+
' fluid_midi_router_t*, fluid_player_t*)'
|
32
|
+
|
33
|
+
# Delete a command handler.
|
34
|
+
extern 'void delete_fluid_cmd_handler(fluid_cmd_handler_t*)'
|
35
|
+
|
36
|
+
|
37
|
+
# Functions.
|
38
|
+
#
|
39
|
+
#
|
40
|
+
|
41
|
+
# Process a string command.
|
42
|
+
# extern 'int fluid_command(void*, void*, int)'
|
43
|
+
extern 'int fluid_command(fluid_cmd_handler_t*, char*, fluid_ostream_t)'
|
44
|
+
|
45
|
+
# Execute shell commands in a file.
|
46
|
+
extern 'int fluid_source(fluid_cmd_handler_t*, char*)'
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Lifecycle Functions.
|
54
|
+
#
|
55
|
+
#
|
56
|
+
class FiddleFluidSynth
|
57
|
+
|
58
|
+
def cmd_handler_new( synth=self.synth, router: )
|
59
|
+
ret = C.new_fluid_cmd_handler(synth, router)
|
60
|
+
ret
|
61
|
+
end
|
62
|
+
|
63
|
+
def cmd_handler_new2( settings=self.settings,
|
64
|
+
synth: , router: , player: )
|
65
|
+
ret = C.new_fluid_cmd_handler2(settings, synth, router, player)
|
66
|
+
ret
|
67
|
+
end
|
68
|
+
|
69
|
+
def cmd_handler_delete( cmd_handler )
|
70
|
+
ret = C.delete_fluid_cmd_handler(cmd_handler)
|
71
|
+
ret
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Functions.
|
78
|
+
#
|
79
|
+
#
|
80
|
+
class FiddleFluidSynth
|
81
|
+
|
82
|
+
def cmd_command( handler, cmd, out )
|
83
|
+
ret = C.fluid_command(handler, cmd, out)
|
84
|
+
ret
|
85
|
+
end
|
86
|
+
|
87
|
+
def cmd_source( handler, filename )
|
88
|
+
ret = C.fluid_source(handler, filename)
|
89
|
+
ret
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
#### endof filename: fiddle-fluidstynth/command_interface/handler.rb
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# filename: fiddle-fluidstynth/command_interface/server.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
# References
|
7
|
+
# - [API Reference](https://www.fluidsynth.org/api/modules.html)
|
8
|
+
#
|
9
|
+
class FiddleFluidSynth
|
10
|
+
|
11
|
+
# TCP socket server for a command handler.
|
12
|
+
# ==== References
|
13
|
+
# - API References, Command Interface/[Command Server](https://www.fluidsynth.org/api/group__command__server.html)
|
14
|
+
# - [library fiddle](https://docs.ruby-lang.org/ja/latest/library/fiddle.html)
|
15
|
+
#
|
16
|
+
|
17
|
+
#
|
18
|
+
module C
|
19
|
+
|
20
|
+
# Lifecycle Functions.
|
21
|
+
#
|
22
|
+
#
|
23
|
+
|
24
|
+
# Create a new TCP/IP command shell server.
|
25
|
+
extern 'fluid_server_t* new_fluid_server' +
|
26
|
+
'(fluid_settings_t*, fluid_synth_t*, fluid_midi_router_t*)'
|
27
|
+
|
28
|
+
# Create a new TCP/IP command shell server.
|
29
|
+
extern 'fluid_server_t* new_fluid_server2' +
|
30
|
+
'(fluid_settings_t*, fluid_synth_t*,' +
|
31
|
+
' fluid_midi_router_t*, fluid_player_t*)'
|
32
|
+
|
33
|
+
# Delete a TCP/IP shell server.
|
34
|
+
extern 'void delete_fluid_server(fluid_server_t*)'
|
35
|
+
|
36
|
+
# Join a shell server thread (wait until it quits).
|
37
|
+
extern 'int fluid_server_join(fluid_server_t*)'
|
38
|
+
|
39
|
+
|
40
|
+
# Functions.
|
41
|
+
#
|
42
|
+
#
|
43
|
+
|
44
|
+
# nothing.
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Lifecycle Functions.
|
51
|
+
#
|
52
|
+
#
|
53
|
+
class FiddleFluidSynth
|
54
|
+
|
55
|
+
def server_new( settings: , synth: , router: )
|
56
|
+
ret = C.new_fluid_server(synth, router)
|
57
|
+
ret
|
58
|
+
end
|
59
|
+
|
60
|
+
def server_new2( settings: , synth: , router: , player: )
|
61
|
+
ret = C.new_fluid_server2(settings, synth, router, player)
|
62
|
+
ret
|
63
|
+
end
|
64
|
+
|
65
|
+
def server_delete( server )
|
66
|
+
ret = C.delete_fluid_server(server)
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def server_join( server )
|
71
|
+
ret = C.fluid_server_join(server)
|
72
|
+
ret
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
#### endof filename: fiddle-fluidstynth/command_interface/server.rb
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# filename: fiddle-fluidstynth/command_interface/shell.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
# References
|
7
|
+
# - [API Reference](https://www.fluidsynth.org/api/modules.html)
|
8
|
+
#
|
9
|
+
class FiddleFluidSynth
|
10
|
+
|
11
|
+
# Interactive shell to control and configure a synthesizer instance.
|
12
|
+
# ==== References
|
13
|
+
# - API References, Command Interface/[Command Shell](https://www.fluidsynth.org/api/group__command__shell.html)
|
14
|
+
# - [library fiddle](https://docs.ruby-lang.org/ja/latest/library/fiddle.html)
|
15
|
+
#
|
16
|
+
|
17
|
+
#
|
18
|
+
module C
|
19
|
+
|
20
|
+
# Lifecycle Functions.
|
21
|
+
#
|
22
|
+
#
|
23
|
+
|
24
|
+
# Create a new FluidSynth command shell.
|
25
|
+
extern 'fluid_shell_t* new_fluid_shell' +
|
26
|
+
'(fluid_settings_t*, fluid_cmd_handler_t*,' +
|
27
|
+
' fluid_istream_t, fluid_ostream_t, int)'
|
28
|
+
|
29
|
+
# A convenience function to create a shell interfacing to standard
|
30
|
+
# input/output console streams.
|
31
|
+
extern 'void fluid_usershell(fluid_settings_t*, fluid_cmd_handler_t*)'
|
32
|
+
|
33
|
+
# Delete a FluidSynth command shell.
|
34
|
+
extern 'void delete_fluid_shell(fluid_shell_t*)'
|
35
|
+
|
36
|
+
# Functions.
|
37
|
+
#
|
38
|
+
#
|
39
|
+
|
40
|
+
# nothing.
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Lifecycle Functions.
|
48
|
+
#
|
49
|
+
#
|
50
|
+
class FiddleFluidSynth
|
51
|
+
|
52
|
+
# def cmd_shell_new( settings: , handler: , in: , out: , thread: )
|
53
|
+
def cmd_shell_new( settings=self.settings,
|
54
|
+
handler: , instm: , outstm: , thread: )
|
55
|
+
ret = C.new_fluid_shell(settings, handler, instm, outstm, thread)
|
56
|
+
ret
|
57
|
+
end
|
58
|
+
|
59
|
+
def cmd_usershell( settings=self.settings, handler: )
|
60
|
+
ret = C.fluid_usershell(settings, handler)
|
61
|
+
ret
|
62
|
+
end
|
63
|
+
|
64
|
+
def cmd_shell_delete( shell )
|
65
|
+
ret = C.delete_fluid_shell(shell)
|
66
|
+
ret
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# Functions.
|
72
|
+
#
|
73
|
+
#
|
74
|
+
|
75
|
+
|
76
|
+
#### endof filename: fiddle-fluidstynth/command_interface/shell.rb
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#
|
2
|
+
# filename: fiddle-fluidsynth/command_interface/command_interface.rb
|
3
|
+
#
|
4
|
+
require_relative "./command_interface/command_interface"
|
5
|
+
require_relative "./command_interface/handler"
|
6
|
+
require_relative "./command_interface/server"
|
7
|
+
require_relative "./command_interface/shell"
|
8
|
+
|
9
|
+
#### endof filename: fiddle-fluidsynth/command_interface/command_interface.rb
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
#
|
4
|
+
require 'fiddle'
|
5
|
+
|
6
|
+
# `'-'*Fiddle::SIZEOF_INT` is bad when string is frozen literal.
|
7
|
+
# So we introduce this Fiddle helper.
|
8
|
+
#
|
9
|
+
|
10
|
+
#
|
11
|
+
#
|
12
|
+
#
|
13
|
+
def Fiddle.SIZEOF_INT
|
14
|
+
Fiddle::SIZEOF_INT
|
15
|
+
end
|
16
|
+
def Fiddle.sizeof_int
|
17
|
+
self.SIZEOF_INT()
|
18
|
+
end
|
19
|
+
|
20
|
+
def Fiddle.SIZEOF_DOUBLE
|
21
|
+
Fiddle::SIZEOF_DOUBLE
|
22
|
+
end
|
23
|
+
def Fiddle.sizeof_dbl
|
24
|
+
self.SIZEOF_DOUBLE()
|
25
|
+
end
|
26
|
+
|
27
|
+
def Fiddle.SIZEOF_FLOAT
|
28
|
+
Fiddle::SIZEOF_FLOAT
|
29
|
+
end
|
30
|
+
def Fiddle.sizeof_flt
|
31
|
+
self.SIZEOF_FLOAT()
|
32
|
+
end
|
33
|
+
|
34
|
+
def Fiddle.SIZEOF_VOIDP
|
35
|
+
Fiddle::SIZEOF_VOIDP
|
36
|
+
end
|
37
|
+
def Fiddle.sizeof_voidp
|
38
|
+
self.SIZEOF_VOIDP()
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#
|
43
|
+
class Fiddle::Pointer
|
44
|
+
def self.malloc_n( sz: )
|
45
|
+
Fiddle::Pointer.malloc(sz)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
def self.malloc_int
|
50
|
+
self.malloc_n(sz: Fiddle.sizeof_int)
|
51
|
+
end
|
52
|
+
def self.malloc_i; self.malloc_int; end
|
53
|
+
|
54
|
+
#
|
55
|
+
def self.malloc_dbl
|
56
|
+
self.malloc_n(sz: Fiddle.sizeof_dbl)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
def self.malloc_flt
|
61
|
+
self.malloc_n(sz: Fiddle.sizeof_flt)
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
def self.malloc_voidp
|
66
|
+
self.malloc_n(sz: Fiddle.sizeof_voidp)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
def self.malloc_char_ptr2( str_ary )
|
71
|
+
ary_size = str_ary.size
|
72
|
+
self.malloc_n(sz: Fiddle.sizeof_voidp*ary_size)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
class Fiddle::Pointer
|
79
|
+
|
80
|
+
def self.set_int(ptr, v)
|
81
|
+
ptr[0, Fiddle.sizeof_int] = [v].pack("i")
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.set_dbl(ptr, v)
|
85
|
+
ptr[0, Fiddle.sizeof_dbl] = [v].pack("E")
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.set_flt(ptr, v)
|
89
|
+
ptr[0, Fiddle.sizeof_flt] = [v].pack("f")
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.set_voidp(ptr, v)
|
93
|
+
ptr[0, Fiddle.sizeof_voidp] = [v].pack("J")
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.set_char_ptr2(ptr2, str_ary)
|
97
|
+
atr_ary.each_with_index do |str, index|
|
98
|
+
tmp_ptr = Fiddle::Pointer.malloc(str.bytesize + 1)
|
99
|
+
tmp_ptr[0, str.bytesize+1] = "#{str}\0"
|
100
|
+
|
101
|
+
ptr2[index*Fiddle.sizeof_voidp,
|
102
|
+
Fiddle.sizeof_voidp] = [tmp_ptr.to_i].pack("Q")
|
103
|
+
end
|
104
|
+
|
105
|
+
ptr2
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
#
|
112
|
+
class Fiddle::Pointer
|
113
|
+
def self.unpack1( val: , fmt: )
|
114
|
+
val[0, val.size].unpack1(fmt)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
def self.decode1_int( val )
|
119
|
+
self.unpack1(val: val, fmt: 'i')
|
120
|
+
end
|
121
|
+
def self.decode1_i(val); decode1_int(val); end
|
122
|
+
def decode1_int
|
123
|
+
self.class.decode1_i(self)
|
124
|
+
end
|
125
|
+
alias decode1_i decode1_int
|
126
|
+
|
127
|
+
#
|
128
|
+
def self.decode1_dbl( val )
|
129
|
+
self.unpack1(val: val, fmt: 'E')
|
130
|
+
end
|
131
|
+
def decode1_dbl
|
132
|
+
self.class.decode1_dbl(self)
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
def self.decode_char_ptr2( ptr2 )
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
####
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#
|
2
|
+
# filename: module.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
#
|
6
|
+
#
|
7
|
+
#
|
8
|
+
class Module
|
9
|
+
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# ==== Example
|
13
|
+
# ```
|
14
|
+
# class Aclass
|
15
|
+
# define_module(:Foo) do |mod|
|
16
|
+
# mod.const_set(...)
|
17
|
+
# :
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
# ```
|
21
|
+
def define_module(name, &block)
|
22
|
+
# mod = Module.new(&block)
|
23
|
+
# const_set(name, mod)
|
24
|
+
unless const_defined?(name)
|
25
|
+
mod = Module.new
|
26
|
+
const_set(name, mod)
|
27
|
+
end
|
28
|
+
|
29
|
+
block.call(const_get(name))
|
30
|
+
end
|
31
|
+
|
32
|
+
# define enum constants and its module.
|
33
|
+
# ==== Args
|
34
|
+
# name:: name of the enumerator.
|
35
|
+
# debug_f:: debug mode.
|
36
|
+
# defs:: pairs of key and value of hash.
|
37
|
+
#
|
38
|
+
# ==== Example
|
39
|
+
# ```
|
40
|
+
# class AClass
|
41
|
+
# enum(:fluid_t,
|
42
|
+
# Foo: nil,
|
43
|
+
# Bar: 5,
|
44
|
+
# Car: nil,
|
45
|
+
# )
|
46
|
+
# end
|
47
|
+
# puts "AClass::Car: #{AClass::Foo}" => 0
|
48
|
+
# puts AClass::Enum_fluid_t::Car =>6
|
49
|
+
# puts AClass.Enum_fluid_t =>{Foo: 0, Bar: 5, Car: 6,}
|
50
|
+
# ```
|
51
|
+
#
|
52
|
+
|
53
|
+
#
|
54
|
+
#
|
55
|
+
#
|
56
|
+
def enum( name = "", debug_f: false, **defs )
|
57
|
+
# preprocess.
|
58
|
+
if name.is_a? Hash
|
59
|
+
defs = name
|
60
|
+
name = ""
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
if !(defs[:debug_f].nil?)
|
65
|
+
debug_f = defs[:debug_f]
|
66
|
+
defs.delete(:debug_f)
|
67
|
+
else
|
68
|
+
# $stderr.puts "(**) {#{__method__}} no options."
|
69
|
+
end
|
70
|
+
$stderr.puts "(**) defs: #{defs}" if debug_f
|
71
|
+
$stderr.puts "(**) name: #{name}, debug_f: #{debug_f}," +
|
72
|
+
" defs: #{defs}" if debug_f
|
73
|
+
|
74
|
+
# create a module when name is specified.
|
75
|
+
m_name = ""
|
76
|
+
if name.to_s != ""
|
77
|
+
m_name = "Enum_#{name}"
|
78
|
+
define_module(m_name){|_mod| } unless const_defined?(m_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
_cnt = 0
|
83
|
+
defs.each do |_k, _v|
|
84
|
+
#
|
85
|
+
raise "The head of `#{_k}' must be in Capital or you misspelled" +
|
86
|
+
" for an option...?" unless _k =~ /^[A-Z]/
|
87
|
+
|
88
|
+
#
|
89
|
+
if _v.is_a? Integer
|
90
|
+
puts "_k: #{_k} = #{_v}" if debug_f
|
91
|
+
const_set(_k, _v)
|
92
|
+
const_get(m_name).const_set(_k,_v) if m_name != ""
|
93
|
+
|
94
|
+
_cnt = _v
|
95
|
+
elsif _v.is_a? Symbol
|
96
|
+
__v = const_get(_v)
|
97
|
+
puts "_k: #{_k} = #{_v}, __v: #{__v}" if debug_f
|
98
|
+
const_set(_k, __v)
|
99
|
+
const_get(m_name).const_set(_k,__v) if m_name != ""
|
100
|
+
|
101
|
+
_cnt = __v
|
102
|
+
elsif _v.nil?
|
103
|
+
_v = _cnt
|
104
|
+
puts "_k: #{_k} = #{_v}" if debug_f
|
105
|
+
const_set(_k, _v)
|
106
|
+
const_get(m_name).const_set(_k,_v) if m_name != ""
|
107
|
+
|
108
|
+
defs[_k] = _v
|
109
|
+
else
|
110
|
+
raise "value:#{_v} must be an Integer."
|
111
|
+
end
|
112
|
+
|
113
|
+
_cnt += 1
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
defs
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#### endof filename: module.rb
|
@@ -0,0 +1,172 @@
|
|
1
|
+
#
|
2
|
+
# filename: fiddle_fluidsynth/fiddle_fluidsynth.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
#
|
6
|
+
require 'fiddle/import'
|
7
|
+
require 'rbconfig'
|
8
|
+
|
9
|
+
|
10
|
+
# References
|
11
|
+
# - fluidsynth.org, [API Reference](https://www.fluidsynth.org/api/modules.html)
|
12
|
+
#
|
13
|
+
class FiddleFluidSynth
|
14
|
+
module C
|
15
|
+
#
|
16
|
+
begin
|
17
|
+
lib_fluidsynth = self.full_path_for_lib('fluidsynth')
|
18
|
+
dlload lib_fluidsynth
|
19
|
+
rescue
|
20
|
+
raise LoadError, "Couldn't find the fluidsynth library."
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# ==== References
|
31
|
+
# - [Settings Reference](https://www.fluidsynth.org/api/fluidsettings.html)
|
32
|
+
#
|
33
|
+
#
|
34
|
+
class FiddleFluidSynth
|
35
|
+
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# ==== Args
|
39
|
+
# soundfont_name:: SoundFont file name. do NOT load when nil.
|
40
|
+
# reset_presets:: true then presets are updated immediately.
|
41
|
+
#
|
42
|
+
def initialize( soundfont_name: SOUNDFONT_NAME_DEFAULT,
|
43
|
+
soundfont_path: self.obtain_soundfont_path,
|
44
|
+
soundfont_full_path:
|
45
|
+
"#{soundfont_path}/#{soundfont_name}",
|
46
|
+
# gain: 0.2,
|
47
|
+
# samplerate: 44100.0,
|
48
|
+
# midi_channels: 256,
|
49
|
+
gain: nil,
|
50
|
+
samplerate: nil,
|
51
|
+
midi_channels: nil,
|
52
|
+
player_f: true,
|
53
|
+
audio_driver_f: true,
|
54
|
+
audio_driver_name: nil,
|
55
|
+
audio_driver_new2_f: false,
|
56
|
+
audio_driver_callback: nil,
|
57
|
+
reset_presets: true )
|
58
|
+
|
59
|
+
### prepare Settings.
|
60
|
+
@settings = self.settings_new
|
61
|
+
if self.settings.null?
|
62
|
+
$stderr.puts "(**) Failed to create settings."
|
63
|
+
self.delete
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
# TODO. in args.?
|
68
|
+
#
|
69
|
+
#
|
70
|
+
self.settings.
|
71
|
+
synth_gain = gain unless gain.nil?
|
72
|
+
self.settings.
|
73
|
+
synth_sample__rate = samplerate unless samplerate.nil?
|
74
|
+
self.settings.
|
75
|
+
synth_midi__channels = midi_channels unless midi_channels.nil?
|
76
|
+
|
77
|
+
### prepare Synthesizer.
|
78
|
+
@synth = self.synth_new(self.settings)
|
79
|
+
if self.synth.null?
|
80
|
+
$stderr.puts "(**) Failed to create synthesizer."
|
81
|
+
self.delete
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
### prepare SoundFont.
|
86
|
+
@soundfont_full_path = soundfont_full_path
|
87
|
+
@reset_presets = reset_presets
|
88
|
+
@sfid_ary = [] # set in sfont_sfload().
|
89
|
+
@sfid_latest = nil
|
90
|
+
|
91
|
+
#
|
92
|
+
unless soundfont_name.to_s == ""
|
93
|
+
tmp = self.synth_sfload(synth, filename: @soundfont_full_path,
|
94
|
+
reset_presets: @reset_presets,
|
95
|
+
verbose_f: true)
|
96
|
+
if FLUID_FAILED == tmp
|
97
|
+
$stderr.puts "(**) Failed to load the SoundFont."
|
98
|
+
self.delete
|
99
|
+
exit
|
100
|
+
end
|
101
|
+
else
|
102
|
+
$stderr.puts "(**) SoundFont has NOT been loaded in the initializer."
|
103
|
+
end
|
104
|
+
|
105
|
+
### prepare Player.
|
106
|
+
@player = nil
|
107
|
+
if player_f
|
108
|
+
@player = self.player_new(self.synth)
|
109
|
+
if self.player.null?
|
110
|
+
$stderr.puts "(**) Failed to create player."
|
111
|
+
self.delete
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
### prepare Audio Driver.
|
117
|
+
@audio_driver = nil
|
118
|
+
# self.audio_driver_prepare(
|
119
|
+
# audio_driver_name, settings: self.settings, synth: self.synth,
|
120
|
+
# new2_f: audio_driver_new2_f
|
121
|
+
# )
|
122
|
+
# if self.audio_driver.null?
|
123
|
+
# $stderr.puts "(**) Failed to prepare audio driver."
|
124
|
+
# self.delete
|
125
|
+
# exit
|
126
|
+
# end
|
127
|
+
if audio_driver_f
|
128
|
+
self.audio_driver_prepare(
|
129
|
+
audio_driver_name,
|
130
|
+
settings: self.settings, synth: self.synth,
|
131
|
+
new2_f: audio_driver_new2_f, cb_ptr: audio_driver_callback)
|
132
|
+
|
133
|
+
else
|
134
|
+
$stderr.puts "(**) Do prepare audio driver."
|
135
|
+
end
|
136
|
+
@file_renderer = nil
|
137
|
+
|
138
|
+
### create module hierarchy.
|
139
|
+
self.init_objects(self)
|
140
|
+
|
141
|
+
end
|
142
|
+
attr_reader :settings, :synth, :player
|
143
|
+
attr_reader :audio_driver
|
144
|
+
attr_reader :file_renderer
|
145
|
+
|
146
|
+
attr_reader :soundfont_full_path, :reset_preset
|
147
|
+
# attr_reader :sfid, :sfid_latest
|
148
|
+
attr_reader :sfid_ary, :sfid_latest
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
#
|
154
|
+
#
|
155
|
+
#
|
156
|
+
class FiddleFluidSynth
|
157
|
+
|
158
|
+
def delete
|
159
|
+
self.audio_driver_delete(self.audio_driver) if self.audio_driver &&
|
160
|
+
!(self.audio_driver.null?)
|
161
|
+
self.player_delete(self.player) if self.player &&
|
162
|
+
!(self.player.null?)
|
163
|
+
self.synth_delete(self.synth) if self.synth &&
|
164
|
+
!(self.synth.null?)
|
165
|
+
self.settings_delete(self.settings) if self.settings &&
|
166
|
+
!(self.settings.null?)
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
#### endof filename: fiddle_fluidsynth/iddle_fluidsynth.rb
|