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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c99ccb1af07194f305ce99f260dc9b7aea453c6174834ac54187f12146954e9e
|
4
|
+
data.tar.gz: 9da5f79bbca05c80a9f54ec04552f792ee4020c23ba25f9421c6244f754a4012
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 584e30be468d722a13c8846a6a7832f750ecedc426ec8b9b02383eddb315e7e2be77ea55647eff948a7fef9c1c937aa30e5f685a5fe1a70e4014363cdc767b8c
|
7
|
+
data.tar.gz: cb248bcbad970e06c6d5b5ffeda8b308ee144fcb9269e3c6aa87267b87354237f3ff993451a1256424df10ccb20374ecefd095b8d7991186058516ce1963f8a3
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 YAMAMOTO, Masayuki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# FiddleFluidsynth
|
2
|
+
|
3
|
+
A `fiddle` (`ffi` is partially used) wrapped [`libfluidsynth`](https://www.fluidsynth.org/). We can program/play the music from our code with this.
|
4
|
+
|
5
|
+
To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
`libfluidsynth` is required.
|
11
|
+
|
12
|
+
In macOS, do `brew install fluidsynth` and make symbolic link
|
13
|
+
`default.sf2` in `/opt/homebrew/share/fluid-synth/sf2/` for the default
|
14
|
+
SoundFont.
|
15
|
+
|
16
|
+
As for the default soundfont, I recommend GeneralUser GS 2.0.2 (`GeneralUser-GS.sf2`), created by S. Christian Collins. We can download it from [his site](https://www.schristiancollins.com/generaluser.php). This package includes some MIDI files for demo.
|
17
|
+
|
18
|
+
[FluidR3 GM](https://musical-artifacts.com/artifacts/738) soundfont by Frank Wen and Toby Smithe is also great. We can download them on [Musical Artifact](https://musical-artifacts.com/).
|
19
|
+
|
20
|
+
Other soundfont resources are listed in the FluidSynth User Manual Wiki, [SoundFont](https://github.com/FluidSynth/fluidsynth/wiki/SoundFont) chapter.
|
21
|
+
|
22
|
+
## Developed Environment
|
23
|
+
|
24
|
+
Developed/Tested environments are as follows:
|
25
|
+
|
26
|
+
- libfluidsynth 2.4.6
|
27
|
+
- Ruby 3.3.0
|
28
|
+
- macOS 15.5
|
29
|
+
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
34
|
+
|
35
|
+
Install the gem and add to the application's Gemfile by executing:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
39
|
+
```
|
40
|
+
|
41
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
See `examples/` directory.
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
## Technical info
|
55
|
+
|
56
|
+
`fiddle` is used to wrap and `ffi` is partially used (for callback functions).
|
57
|
+
|
58
|
+
|
59
|
+
The Structure of classes/modules is:
|
60
|
+
|
61
|
+
- FiddleFluidSynth (class) top.
|
62
|
+
- (class/)instance methods are defined. These are almost one-to-one
|
63
|
+
mapping with C-functions, but little bit ruby-fied.
|
64
|
+
- utility methods for shortcuts.
|
65
|
+
- ~~`FiddleFluidSynth#object` (this might be removed...?)
|
66
|
+
the method for referencing to the instance hierarchy~~.
|
67
|
+
- FiddleFluidSynth::C (module) direct mapping for C-functions.
|
68
|
+
|
69
|
+
|
70
|
+
Ruby-fication is actually not enough and work in progress...
|
71
|
+
|
72
|
+
|
73
|
+
### Attention on callback functions
|
74
|
+
|
75
|
+
If we use the callbacks of FiddleFluidSynth, including `each_something{ ... }`-
|
76
|
+
code blocks, we have to have special attention to our codes.
|
77
|
+
|
78
|
+
Because the code blocks of them are out of our Ruby code once,
|
79
|
+
we could not catch Exceptions correctly.
|
80
|
+
|
81
|
+
__I highly recommend that code blocks for the callbacks should be
|
82
|
+
short as far as we can, or use methods which are tested well.__
|
83
|
+
|
84
|
+
__and also do `FiddleFluidSynth.#raise_error_in_callback` after
|
85
|
+
some main routine to get the errors in callback function.__
|
86
|
+
|
87
|
+
|
88
|
+
- Settings
|
89
|
+
- `fluid_settings_foreach()`
|
90
|
+
- `fluid_settings_foreach_option()`
|
91
|
+
- =>`#each_setting()`, `#each_option_of()`
|
92
|
+
- Synthesizer
|
93
|
+
- `fluid_synth_tuning_iteration_start()`, `fluid_synth_tuning_iteration_next()`
|
94
|
+
- Not Yet.
|
95
|
+
- SoundFont
|
96
|
+
- `fluid_sfont_iteration_start()`, `fluid_sfont_iteration_next()`
|
97
|
+
- =>`#each_preset()`
|
98
|
+
|
99
|
+
- callback sample programs are `example/{ffs_fx, ffs_metronome, ffs_arpeggio, ffs_midiplay}.rb`.
|
100
|
+
- `each_*` sample programs are `example/{presets-each, settings}.rb`, etc.
|
101
|
+
|
102
|
+
|
103
|
+
## `libfluidsynth` and other MIDI/SoundFont-related apps and resources
|
104
|
+
|
105
|
+
- [libfluidsynth](https://www.fluidsynth.org/)
|
106
|
+
- [User Documentation](https://www.fluidsynth.org/documentation/)
|
107
|
+
- [Developper Documentation](https://www.fluidsynth.org/api/)
|
108
|
+
- [API Reference](https://www.fluidsynth.org/api/modules.html)
|
109
|
+
- [Setting Reference](https://www.fluidsynth.org/api/fluidsettings.html)
|
110
|
+
|
111
|
+
- [PolyPhone](https://www.polyphone.io/) - the SoundFont editor. `brew install polyphone`
|
112
|
+
- [Sonic Pi](https://sonic-pi.net/) - awesome DAW environment. Sonic Pi has nice tutorial and documents. We can write score and play in Ruby. `brew install sonic-pi`.
|
113
|
+
|
114
|
+
|
115
|
+
## Development
|
116
|
+
|
117
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
118
|
+
|
119
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
120
|
+
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
Bug reports and pull requests are welcome on GitHub at `https://github.com/mephistobooks/fiddle_fluidsynth`.
|
125
|
+
|
126
|
+
|
127
|
+
## License
|
128
|
+
|
129
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
130
|
+
|
131
|
+
|
132
|
+
## DISCLAIMER
|
133
|
+
|
134
|
+
SoundFont® is a registered trademark of Creative Technology Ltd.
|
135
|
+
|
136
|
+
|
137
|
+
---
|
138
|
+
end.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "standard/rake"
|
13
|
+
|
14
|
+
task default: %i[test standard]
|
data/examples/enum.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
|
6
|
+
# List all enumerations defined for fiddle_fluidsynth.
|
7
|
+
#
|
8
|
+
#
|
9
|
+
require_relative '../lib/fiddle_fluidsynth'
|
10
|
+
# require 'fiddle_fluidsynth'
|
11
|
+
|
12
|
+
|
13
|
+
#
|
14
|
+
FiddleFluidSynth.constants.grep(/^Enum/).sort.each_with_index do |_enum, _i|
|
15
|
+
|
16
|
+
puts "#{_i+1}. #{_enum}:"
|
17
|
+
puts FiddleFluidSynth.const_get(_enum).constants.map{|e|
|
18
|
+
v = FiddleFluidSynth.const_get(_enum).const_get(e)
|
19
|
+
|
20
|
+
[e, v]
|
21
|
+
}.sort_by{|e| e.last}.map.with_index{|e,_i|
|
22
|
+
"(#{_i+1}) FiddleFluidSynth::#{_enum}::#{e.first} = #{e.last}" +
|
23
|
+
" = FiddleFluidSynth::#{e.first} (#{FiddleFluidSynth.const_get(e.first)})"
|
24
|
+
}
|
25
|
+
puts
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
#### end.
|
Binary file
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
#
|
4
|
+
|
5
|
+
# Original comments:
|
6
|
+
# FluidSynth Arpeggio - Sequencer API example
|
7
|
+
#
|
8
|
+
# This code is in the public domain.
|
9
|
+
#
|
10
|
+
# To compile:
|
11
|
+
# gcc -o fluidsynth_arpeggio -lfluidsynth fluidsynth_arpeggio.c
|
12
|
+
#
|
13
|
+
# To run:
|
14
|
+
# fluidsynth_arpeggio soundfont [steps [duration]]
|
15
|
+
#
|
16
|
+
# [Pedro Lopez-Cabanillas <plcl@users.sf.net>]
|
17
|
+
|
18
|
+
# fiddle_fluidsynth comments:
|
19
|
+
# `ffs_arpeggio.rb` is fiddle_fluidsynth version of `fluidsynth_arpeggio.c`.
|
20
|
+
# This code is also in the public domain.
|
21
|
+
#
|
22
|
+
# [YAMAMOTO, Masayuki, https://github.com/mephistobooks]
|
23
|
+
|
24
|
+
#
|
25
|
+
require_relative '../lib/fiddle_fluidsynth'
|
26
|
+
#require 'fiddle_fluidsynth'
|
27
|
+
|
28
|
+
|
29
|
+
#
|
30
|
+
FFS = FiddleFluidSynth
|
31
|
+
@seq = nil
|
32
|
+
|
33
|
+
#
|
34
|
+
@synth_dest, @client_dest = nil, nil
|
35
|
+
@time_marker = nil
|
36
|
+
|
37
|
+
# duration of the pattern in ticks.
|
38
|
+
@duration = 1440
|
39
|
+
|
40
|
+
# notes of the arpeggio.
|
41
|
+
@notes = [ 60, 64, 67, 72, 76, 79, 84, 79, 76, 72, 67, 64, ]
|
42
|
+
|
43
|
+
# number of notes in one pattern.
|
44
|
+
@pattern_size = 4
|
45
|
+
|
46
|
+
|
47
|
+
### schedule a note on message.
|
48
|
+
def schedule_noteon( ch, key, ticks )
|
49
|
+
|
50
|
+
# ev = FFS.event_new
|
51
|
+
FFS.seq_event(:noteon, ch: ch, key: key, vel: 127){|ev|
|
52
|
+
# FFS.event_set_src(ev, src: -1)
|
53
|
+
# FFS.event_set_dest(ev, dest: @synth_dest)
|
54
|
+
ev.src = -1
|
55
|
+
ev.dst = @synth_dest
|
56
|
+
# ev.noteon(ch: ch, key: key, vel: 127)
|
57
|
+
# tmp = @seq.send_at(event: ev, time: ticks, absolute: 1)
|
58
|
+
if @seq.send_at(event: ev, time: ticks, absolute: 1) == FFS::FLUID_FAILED
|
59
|
+
$stderr.puts "(**) {#{__method__}} seq. send_at(): failed."
|
60
|
+
end
|
61
|
+
|
62
|
+
#if FFS::FLUID_FAILED == tmp
|
63
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): failed (#{tmp})."
|
64
|
+
#else
|
65
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): succeeded (#{tmp})."
|
66
|
+
#end
|
67
|
+
# FFS.event_delete(ev)
|
68
|
+
}
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
### schedule a note off message.
|
73
|
+
def schedule_noteoff( ch, key, ticks )
|
74
|
+
|
75
|
+
# ev = FFS.event_new
|
76
|
+
FFS.seq_event(:noteoff, ch: ch, key: key){|ev|
|
77
|
+
# FFS.event_set_src(ev, src: -1)
|
78
|
+
# FFS.event_set_dest(ev, dest: @synth_dest)
|
79
|
+
# FFS.event_noteoff(ev, ch: ch, key: key)
|
80
|
+
ev.src = -1
|
81
|
+
ev.dst = @synth_dest
|
82
|
+
# ev.noteoff(ch: ch, key: key)
|
83
|
+
# tmp = FFS.sequencer_send_at(@seq, event: ev, time: ticks, absolute: 1)
|
84
|
+
# tmp = @seq.send_at(event: ev, time: ticks, absolute: 1)
|
85
|
+
if @seq.send_at(event: ev, time: ticks, absolute: 1) == FFS::FLUID_FAILED
|
86
|
+
$stderr.puts "(**) {#{__method__}} seq. send_at(): failed."
|
87
|
+
end
|
88
|
+
|
89
|
+
# if FFS::FLUID_FAILED == tmp
|
90
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): failed (#{tmp})."
|
91
|
+
# else
|
92
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): succeeded (#{tmp})."
|
93
|
+
# end
|
94
|
+
# FFS.event_delete(ev)
|
95
|
+
}
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
# schedule a timer event (shall trigger the callback).
|
100
|
+
#
|
101
|
+
#
|
102
|
+
def schedule_timer_event
|
103
|
+
|
104
|
+
# ev = FFS.event_new
|
105
|
+
FFS.seq_event(:timer, data: nil){|ev|
|
106
|
+
# FFS.event_set_src(ev, src: -1)
|
107
|
+
# FFS.event_set_dest(ev, dest: @client_dest)
|
108
|
+
# FFS.event_timer(ev, data: nil)
|
109
|
+
ev.src = -1
|
110
|
+
ev.dst = @client_dest
|
111
|
+
# ev.timer(data: nil)
|
112
|
+
|
113
|
+
# tmp = FFS.sequencer_send_at(@seq, event: ev, time: @time_marker, absolute: 1)
|
114
|
+
# tmp = @seq.send_at(event: ev, time: @time_marker, absolute: 1)
|
115
|
+
if @seq.send_at(event: ev, time: @time_marker, absolute: 1) == \
|
116
|
+
FFS::FLUID_FAILED
|
117
|
+
$stderr.puts "(**) {#{__method__}} seq. send_at(): failed (#{tmp})."
|
118
|
+
end
|
119
|
+
|
120
|
+
# if FFS::FLUID_FAILED == tmp
|
121
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): failed (#{tmp})."
|
122
|
+
# else
|
123
|
+
# $stderr.puts "(**) {#{__method__}} seq. send_at(): succeeded (#{tmp})."
|
124
|
+
# end
|
125
|
+
# FFS.event_delete(ev)
|
126
|
+
}
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
# schedule the arpeggio's notes.
|
132
|
+
#
|
133
|
+
#
|
134
|
+
def schedule_pattern
|
135
|
+
#
|
136
|
+
note_time = @time_marker
|
137
|
+
note_duration = @duration/@pattern_size
|
138
|
+
|
139
|
+
#
|
140
|
+
(0...@pattern_size).each do |_i|
|
141
|
+
schedule_noteon(0, @notes[_i], note_time)
|
142
|
+
note_time += note_duration
|
143
|
+
schedule_noteoff(0, @notes[_i], note_time)
|
144
|
+
end
|
145
|
+
|
146
|
+
@time_marker += @duration
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
@seq_cb_ptr = FFS.define_event_callback{|time, ev, seq, data|
|
151
|
+
#
|
152
|
+
schedule_timer_event()
|
153
|
+
schedule_pattern()
|
154
|
+
}
|
155
|
+
|
156
|
+
def usage( prog_name = __FILE__ )
|
157
|
+
puts "Usage: #{prog_name} [soundfont] [steps [duration]]"
|
158
|
+
puts "\t(optional) steps: number of pattern notes, from 2" +
|
159
|
+
" to #{@pattern_size}"
|
160
|
+
puts "\t(optional) duration: of the pattern in ticks, default #{@duration}"
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
### main.
|
165
|
+
|
166
|
+
# n = nil
|
167
|
+
# if ARGV.size < 1
|
168
|
+
if ARGV[0] == '-h' || ARGV[0] == '--help'
|
169
|
+
usage()
|
170
|
+
exit 1
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
opt_idx = 0
|
175
|
+
fs = if File.exist?(ARGV[0].to_s)
|
176
|
+
opt_idx += 1
|
177
|
+
FiddleFluidSynth.new(soundfont_full_path: ARGV[0], player_f: false)
|
178
|
+
else
|
179
|
+
FiddleFluidSynth.new(player_f: false)
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
@seq = fs.sequencer_new2
|
184
|
+
if @seq.null?
|
185
|
+
raise "Cannot prepare the sequencer!"
|
186
|
+
end
|
187
|
+
puts "#seq. clients: #{@seq.count_clients}"
|
188
|
+
|
189
|
+
### register the synthesizer to the sequencer.
|
190
|
+
# @synth_dest = fs.sequencer_register_fluidsynth(@seq, fs.synth)
|
191
|
+
@synth_dest = @seq.register_fluidsynth(fs.synth)
|
192
|
+
if FFS::FLUID_FAILED == @synth_dest
|
193
|
+
raise "Client (synth) registsteration failed."
|
194
|
+
end
|
195
|
+
puts "seq_id: #{@synth_dest}, #seq. clients:" +
|
196
|
+
" #{@seq.count_clients}"
|
197
|
+
|
198
|
+
### register the sequencer client.
|
199
|
+
# @client_dest = fs.sequencer_register_client(
|
200
|
+
# @seq, name: 'ffs_metronome',
|
201
|
+
# event_callback: @seq_cb_ptr,
|
202
|
+
# data: nil)
|
203
|
+
@client_dest = @seq.register_client(
|
204
|
+
name: 'ffs_metronome',
|
205
|
+
event_callback: @seq_cb_ptr, data: nil)
|
206
|
+
if FFS::FLUID_FAILED == @client_dest
|
207
|
+
raise "Client registsteration failed."
|
208
|
+
end
|
209
|
+
puts "seq_id: #{@client_dest}, #seq. clients:" +
|
210
|
+
" #{@seq.count_clients}"
|
211
|
+
|
212
|
+
#
|
213
|
+
if ARGV.size >= 1 && ARGV[opt_idx]
|
214
|
+
n = ARGV[opt_idx].to_i
|
215
|
+
@pattern_size = n if n > 1 && (n < @pattern_size)
|
216
|
+
opt_idx += 1
|
217
|
+
end
|
218
|
+
|
219
|
+
if ARGV.size >= 2 && ARGV[opt_idx]
|
220
|
+
n = ARGV[opt_idx].to_i
|
221
|
+
@duration = n if n > 0
|
222
|
+
opt_idx += 1
|
223
|
+
end
|
224
|
+
$stderr.puts "@pattern_size: #{@pattern_size}, @duration: #{@duration}"
|
225
|
+
|
226
|
+
|
227
|
+
#
|
228
|
+
# @audiodriver = fs.audio_driver_prepare
|
229
|
+
|
230
|
+
# get the current time in ticks.
|
231
|
+
@time_marker = @seq.tick
|
232
|
+
|
233
|
+
# schedule patterns.
|
234
|
+
schedule_pattern()
|
235
|
+
schedule_timer_event()
|
236
|
+
schedule_pattern()
|
237
|
+
|
238
|
+
|
239
|
+
# wait for user input.
|
240
|
+
print 'Press "Enter" to stop: '
|
241
|
+
$stdin.getc
|
242
|
+
fs.raise_error_in_callback
|
243
|
+
puts "done."
|
244
|
+
|
245
|
+
#
|
246
|
+
puts "Cleaning up..."
|
247
|
+
fs.delete
|
248
|
+
puts "fs.deleted."
|
249
|
+
puts "Done. Exiting program."
|
250
|
+
|
251
|
+
|
252
|
+
#### end.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
|
6
|
+
# Original comments:
|
7
|
+
# An example of how to use FluidSynth.
|
8
|
+
#
|
9
|
+
# To compile it on Linux:
|
10
|
+
# $ gcc -o example example.c `pkg-config fluidsynth --libs`
|
11
|
+
#
|
12
|
+
# To compile it on Windows:
|
13
|
+
# ...
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Author: Peter Hanappe.
|
17
|
+
# This code is in the public domain. Use it as you like.
|
18
|
+
#
|
19
|
+
|
20
|
+
# `ffs_example.rb` is fiddle_fluidsynth version of `example.c`
|
21
|
+
# This code is also in the public domain.
|
22
|
+
#
|
23
|
+
# [YAMAMOTO, Masayuki]
|
24
|
+
require_relative '../lib/fiddle_fluidsynth'
|
25
|
+
#require 'fiddle_fluidsynth'
|
26
|
+
|
27
|
+
#
|
28
|
+
fs = FiddleFluidSynth.new(player_f: false)
|
29
|
+
srand(Process.pid)
|
30
|
+
|
31
|
+
#
|
32
|
+
12.times do |i|
|
33
|
+
key = 60 + 12.0 * rand(0.0..1.0)
|
34
|
+
# fs.noteon(0, key, 80)
|
35
|
+
# fs.synth_noteon(ch: 0, key: key, vel: 80)
|
36
|
+
fs.noteon(0, key, 80)
|
37
|
+
sleep(1)
|
38
|
+
# fs.noteoff(0, key)
|
39
|
+
# fs.synth_noteoff(ch: 0, key: key)
|
40
|
+
fs.noteoff(0, key)
|
41
|
+
end
|
42
|
+
|
43
|
+
fs.raise_error_in_callback
|
44
|
+
fs.delete
|
45
|
+
|
46
|
+
|
47
|
+
#### end.
|