Skip to content

Commit c5779af

Browse files
committed
Prepare for v1.2.0
1 parent df49fbd commit c5779af

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v1.2.0
4+
5+
- Update libfluidsynth to 2.0.2 (using [fluidsynth-emscripten v2.0.2-em-fix1](https://github.com/jet2jet/fluidsynth-emscripten/releases/tag/v2.0.2-em-fix1))
6+
- Add 'midiProgramSelect' API for synthesizer
7+
- Add APIs for hooking MIDI events from player
8+
- Add APIs for handling event data from sequencer (as 'sequencer client')
9+
- Fix handling errors on the audio worklet
10+
311
## v1.1.1
412

513
- Fix missing destination for sequencer

README.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ npm install --save fluid-js
1515

1616
### From main thread
1717

18-
Copies `dist/fluid.js` (or `dist/fluid.min.js`) and `externals/libfluidsynth-2.0.1.js` (libfluidsynth JS file) to your project, and writes `<script>` tags as following order:
18+
Copies `dist/fluid.js` (or `dist/fluid.min.js`) and `externals/libfluidsynth-2.0.2.js` (libfluidsynth JS file) to your project, and writes `<script>` tags as following order:
1919

2020
```html
21-
<script src="libfluidsynth-2.0.1.js"></script>
21+
<script src="libfluidsynth-2.0.2.js"></script>
2222
<script src="fluid.js"></script>
2323
```
2424

@@ -73,7 +73,7 @@ fluid-js supports AudioWorklet process via `dist/fluid.worklet.js` (or `dist/flu
7373

7474
```js
7575
var context = new AudioContext();
76-
context.audioWorklet.addModule('libfluidsynth-2.0.1.js')
76+
context.audioWorklet.addModule('libfluidsynth-2.0.2.js')
7777
.then(function () {
7878
return context.audioWorklet.addModule('fluid.worklet.js');
7979
})
@@ -104,7 +104,7 @@ fluid-js and libfluidsynth can be executed on a Web Worker. Executing on a Web W
104104
To use fluid-js on a Web Worker, simply call `importScripts` as followings:
105105

106106
```js
107-
self.importScripts('libfluidsynth-2.0.1.js');
107+
self.importScripts('libfluidsynth-2.0.2.js');
108108
self.importScripts('fluid.js');
109109
```
110110

@@ -138,6 +138,65 @@ The `Sequencer` instance is created only via following methods:
138138
* `Fluid.AudioWorkletNodeSynthesizer.prototype.createSequencer` (instance method)
139139
* Returns the Promise object that resolves with `Fluid.ISequencer` instance. The instance can be used with `Fluid.AudioWorkletNodeSynthesizer` instances which handled `createSequencer` calls.
140140

141+
### Using hook / handle MIDI-related event data with user-defined calllback
142+
143+
NOTE: `libfluidsynth-2.0.2.js` (or above) is necessary to use this feature.
144+
145+
From v1.2.0, you can hook MIDI events posted by player. For `Fluid.Synthesizer` instance, use `hookPlayerMIDIEvents` method as followings:
146+
147+
```js
148+
syn.hookPlayerMIDIEvents(function (s, type, event) {
149+
// hook '0xC0' event (Program Change event)
150+
if (type === 0xC0) {
151+
// if the 'program' value is 0, use another SoundFont
152+
if (event.getProgram() === 0) {
153+
syn.midiProgramSelect(event.getChannel(), secondSFont, 0, 0);
154+
return true;
155+
}
156+
}
157+
// return false to use default processings for other events
158+
return false;
159+
});
160+
```
161+
162+
For `Fluid.AudioWorkletNodeSynthesizer` instance, use `hookPlayerMIDIEventsByName` as followings:
163+
164+
* worklet.js
165+
166+
```js
167+
// We must add method to AudioWorkletGlobalScope to pass to another module.
168+
AudioWorkletGlobalScope.myHookPlayerEvents = function (s, type, event, data) {
169+
if (type === 0xC0) {
170+
if (event.getProgram() === 0) {
171+
// 'secondSFont' will be passed from 'hookPlayerMIDIEventsByName'
172+
s.midiProgramSelect(event.getChannel(), data.secondSFont, 0, 0);
173+
return true;
174+
}
175+
}
176+
return false;
177+
};
178+
```
179+
180+
* main.js
181+
182+
```js
183+
// before use this, 'worklet.js' above must be loaded as AudioWorklet completely, and
184+
// syn.createAudioNode must be called to activate worklet.
185+
186+
// The first parameter is the method name added to 'AudioWorkletGlobalScope'.
187+
// The second parameter will be passed to the worklet.
188+
syn.hookPlayerMIDIEventsByName('myHookPlayerEvents', { secondSFont: secondSFont });
189+
```
190+
191+
The sequencer also supports 'user-defined client' to handle event data.
192+
193+
* For sequncer instance created by `Synthesizer.createSequencer`, use `Synthesizer.registerSequencerClient` static method.
194+
* You can use `Synthesizer.sendEventNow` static method to event data processed by the synthesizer or another clients.
195+
* For sequncer instance created by `createSequencer` of `AudioWorkletNodeSynthesizer`, use `registerSequencerClientByName` instance method.
196+
* The callback function must be added to 'AudioWorkletGlobalScope' like `hookPlayerMIDIEventsByName`'s callback.
197+
* To re-send event data, use `Synthesizer.sendEventNow` in the worklet. `Synthesizer` constructor is available via `AudioWorkletGlobalScope.Fluid.Synthesizer`.
198+
* You can rewrite event data passed to the callback, with using `Fluid.rewriteEventData` (`AudioWorkletGlobalScope.Fluid.rewriteEventData` for worklet).
199+
141200
### `Fluid` methods
142201

143202
#### `waitForReady`

0 commit comments

Comments
 (0)