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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
/*
* gstfluidsynth - fluidsynth plugin for gstreamer
*
* Copyright 2013 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-fluidsynth
* @see_also: timidity, wildmidi
*
* This element renders midi-events as audio streams using
* <ulink url="http://fluidsynth.sourceforge.net//">Fluidsynth</ulink>.
* It offers better sound quality compared to the timidity or wildmidi element.
*
* <refsect2>
* <title>Example pipeline</title>
* |[
* gst-launch-1.0 filesrc location=song.mid ! midiparse ! fluidsynth ! pulsesink
* ]| This example pipeline will parse the midi and render to raw audio which is
* played via pulseaudio.
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#define FLUIDSYNTH_RATE 44100
#define FLUIDSYNTH_BPS (4 * 2)
#include <gst/gst.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gst/audio/audio.h>
#include "gstfluidsynth.h"
GST_DEBUG_CATEGORY_STATIC (gst_fluidsynth_debug);
#define GST_CAT_DEFAULT gst_fluidsynth_debug
enum
{
/* FILL ME */
LAST_SIGNAL
};
#define SOUNDFONT_PATH "/usr/share/sounds/sf2/"
#define DEFAULT_SOUNDFONT NULL
#define DEFAULT_SYNTH_CHORUS TRUE
#define DEFAULT_SYNTH_REVERB TRUE
#define DEFAULT_SYNTH_GAIN 0.2
#define DEFAULT_SYNTH_POLYPHONY 256
enum
{
PROP_0,
PROP_SOUNDFONT,
PROP_SYNTH_CHORUS,
PROP_SYNTH_REVERB,
PROP_SYNTH_GAIN,
PROP_SYNTH_POLYPHONY
};
static void gst_fluidsynth_finalize (GObject * object);
static gboolean gst_fluidsynth_sink_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static GstStateChangeReturn gst_fluidsynth_change_state (GstElement * element,
GstStateChange transition);
static GstFlowReturn gst_fluidsynth_chain (GstPad * sinkpad, GstObject * parent,
GstBuffer * buffer);
static void gst_fluidsynth_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_fluidsynth_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-midi-event")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (F32) ", "
"rate = (int) " G_STRINGIFY (FLUIDSYNTH_RATE) ", "
"channels = (int) 2, " "layout = (string) interleaved"));
#define parent_class gst_fluidsynth_parent_class
G_DEFINE_TYPE (GstFluidsynth, gst_fluidsynth, GST_TYPE_ELEMENT);
/* fluid_synth log handler */
static void
gst_fluid_synth_error_log_function (int level, char *message, void *data)
{
GST_ERROR ("%s", message);
}
static void
gst_fluid_synth_warning_log_function (int level, char *message, void *data)
{
GST_WARNING ("%s", message);
}
static void
gst_fluid_synth_info_log_function (int level, char *message, void *data)
{
GST_INFO ("%s", message);
}
static void
gst_fluid_synth_debug_log_function (int level, char *message, void *data)
{
GST_DEBUG ("%s", message);
}
/* initialize the plugin's class */
static void
gst_fluidsynth_class_init (GstFluidsynthClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gobject_class->finalize = gst_fluidsynth_finalize;
gobject_class->set_property = gst_fluidsynth_set_property;
gobject_class->get_property = gst_fluidsynth_get_property;
g_object_class_install_property (gobject_class, PROP_SOUNDFONT,
g_param_spec_string ("soundfont",
"Soundfont", "the filename of a soundfont (NULL for default)",
DEFAULT_SOUNDFONT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNTH_CHORUS,
g_param_spec_boolean ("synth-chorus",
"Synth Chorus", "Turn the chorus on or off",
DEFAULT_SYNTH_CHORUS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNTH_REVERB,
g_param_spec_boolean ("synth-reverb",
"Synth Reverb", "Turn the reverb on or off",
DEFAULT_SYNTH_REVERB, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNTH_GAIN,
g_param_spec_double ("synth-gain",
"Synth Gain", "Set the master gain", 0.0, 10.0,
DEFAULT_SYNTH_GAIN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNTH_POLYPHONY,
g_param_spec_int ("synth-polyphony",
"Synth Polyphony", "The number of simultaneous voices", 1, 65535,
DEFAULT_SYNTH_POLYPHONY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sink_factory));
gst_element_class_set_static_metadata (gstelement_class, "Fluidsynth",
"Codec/Decoder/Audio",
"Midi Synthesizer Element", "Wim Taymans <wim.taymans@gmail.com>");
gstelement_class->change_state = gst_fluidsynth_change_state;
#ifndef GST_DISABLE_GST_DEBUG
fluid_set_log_function (FLUID_PANIC, gst_fluid_synth_error_log_function,
NULL);
fluid_set_log_function (FLUID_ERR, gst_fluid_synth_warning_log_function,
NULL);
fluid_set_log_function (FLUID_WARN, gst_fluid_synth_warning_log_function,
NULL);
fluid_set_log_function (FLUID_INFO, gst_fluid_synth_info_log_function, NULL);
fluid_set_log_function (FLUID_DBG, gst_fluid_synth_debug_log_function, NULL);
#else
fluid_set_log_function (FLUID_PANIC, NULL, NULL);
fluid_set_log_function (FLUID_ERR, NULL, NULL);
fluid_set_log_function (FLUID_WARN, NULL, NULL);
fluid_set_log_function (FLUID_INFO, NULL, NULL);
fluid_set_log_function (FLUID_DBG, NULL, NULL);
#endif
}
/* initialize the new element
* instantiate pads and add them to element
* set functions
* initialize structure
*/
static void
gst_fluidsynth_init (GstFluidsynth * filter)
{
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
gst_pad_set_event_function (filter->sinkpad, gst_fluidsynth_sink_event);
gst_pad_set_chain_function (filter->sinkpad, gst_fluidsynth_chain);
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
gst_pad_use_fixed_caps (filter->srcpad);
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
filter->soundfont = g_strdup (DEFAULT_SOUNDFONT);
filter->synth_chorus = DEFAULT_SYNTH_CHORUS;
filter->synth_reverb = DEFAULT_SYNTH_REVERB;
filter->synth_gain = DEFAULT_SYNTH_GAIN;
filter->synth_polyphony = DEFAULT_SYNTH_POLYPHONY;
filter->settings = new_fluid_settings ();
filter->synth = new_fluid_synth (filter->settings);
filter->sf = -1;
fluid_synth_set_chorus_on (filter->synth, filter->synth_chorus);
fluid_synth_set_reverb_on (filter->synth, filter->synth_reverb);
fluid_synth_set_gain (filter->synth, filter->synth_gain);
fluid_synth_set_polyphony (filter->synth, filter->synth_polyphony);
}
static void
gst_fluidsynth_finalize (GObject * object)
{
GstFluidsynth *fluidsynth = GST_FLUIDSYNTH (object);
delete_fluid_synth (fluidsynth->synth);
delete_fluid_settings (fluidsynth->settings);
g_free (fluidsynth->soundfont);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
#if 0
static GstBuffer *
gst_fluidsynth_clip_buffer (GstFluidsynth * fluidsynth, GstBuffer * buffer)
{
guint64 start, stop;
guint64 new_start, new_stop;
gint64 offset, length;
/* clipping disabled for now */
return buffer;
start = GST_BUFFER_OFFSET (buffer);
stop = GST_BUFFER_OFFSET_END (buffer);
if (!gst_segment_clip (&fluidsynth->segment, GST_FORMAT_DEFAULT,
start, stop, &new_start, &new_stop)) {
gst_buffer_unref (buffer);
return NULL;
}
if (start == new_start && stop == new_stop)
return buffer;
offset = new_start - start;
length = new_stop - new_start;
buffer = gst_buffer_make_writable (buffer);
gst_buffer_resize (buffer, offset, length);
GST_BUFFER_OFFSET (buffer) = new_start;
GST_BUFFER_OFFSET_END (buffer) = new_stop;
GST_BUFFER_TIMESTAMP (buffer) =
gst_util_uint64_scale_int (new_start, GST_SECOND, FLUIDSYNTH_RATE);
GST_BUFFER_DURATION (buffer) =
gst_util_uint64_scale_int (new_stop, GST_SECOND, FLUIDSYNTH_RATE) -
GST_BUFFER_TIMESTAMP (buffer);
return buffer;
}
#endif
static void
gst_fluidsynth_reset (GstFluidsynth * fluidsynth)
{
fluid_synth_system_reset (fluidsynth->synth);
fluidsynth->last_pts = GST_CLOCK_TIME_NONE;
}
static gboolean
gst_fluidsynth_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
gboolean res;
GstFluidsynth *fluidsynth = GST_FLUIDSYNTH (parent);
GST_DEBUG_OBJECT (pad, "%s event received", GST_EVENT_TYPE_NAME (event));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS:
{
GstCaps *caps;
caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, GST_AUDIO_NE (F32),
"rate", G_TYPE_INT, FLUIDSYNTH_RATE,
"channels", G_TYPE_INT, 2,
"layout", G_TYPE_STRING, "interleaved", NULL);
fluid_synth_set_sample_rate (fluidsynth->synth, FLUIDSYNTH_RATE);
res = gst_pad_push_event (fluidsynth->srcpad, gst_event_new_caps (caps));
gst_caps_unref (caps);
break;
}
case GST_EVENT_SEGMENT:
gst_event_copy_segment (event, &fluidsynth->segment);
GST_DEBUG_OBJECT (fluidsynth, "configured segment %" GST_SEGMENT_FORMAT,
fluidsynth->segment);
res = gst_pad_event_default (pad, parent, event);
break;
case GST_EVENT_FLUSH_STOP:
gst_fluidsynth_reset (fluidsynth);
res = gst_pad_event_default (pad, parent, event);
break;
case GST_EVENT_EOS:
/* FIXME, push last samples */
res = gst_pad_event_default (pad, parent, event);
break;
default:
res = gst_pad_event_default (pad, parent, event);
break;
}
return res;
}
static GstFlowReturn
produce_samples (GstFluidsynth * fluidsynth, GstClockTime pts, guint64 sample)
{
GstClockTime duration, timestamp;
guint64 samples, offset;
GstMapInfo info;
GstBuffer *outbuf;
samples = sample - fluidsynth->last_sample;
duration = pts - fluidsynth->last_pts;
offset = fluidsynth->last_sample;
timestamp = fluidsynth->last_pts;
fluidsynth->last_pts = pts;
fluidsynth->last_sample = sample;
if (samples == 0)
return GST_FLOW_OK;
GST_DEBUG_OBJECT (fluidsynth, "duration %" GST_TIME_FORMAT
", samples %u", GST_TIME_ARGS (duration), samples);
outbuf = gst_buffer_new_allocate (NULL, samples * FLUIDSYNTH_BPS, NULL);
gst_buffer_map (outbuf, &info, GST_MAP_WRITE);
fluid_synth_write_float (fluidsynth->synth, samples, info.data, 0, 2,
info.data, 1, 2);
gst_buffer_unmap (outbuf, &info);
GST_BUFFER_DTS (outbuf) = timestamp;
GST_BUFFER_PTS (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = duration;
GST_BUFFER_OFFSET (outbuf) = offset;
GST_BUFFER_OFFSET_END (outbuf) = offset + samples;
if (fluidsynth->discont) {
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
fluidsynth->discont = FALSE;
}
return gst_pad_push (fluidsynth->srcpad, outbuf);
}
static void
handle_buffer (GstFluidsynth * fluidsynth, GstBuffer * buffer)
{
GstMapInfo info;
guint8 event;
gst_buffer_map (buffer, &info, GST_MAP_READ);
event = info.data[0];
switch (event & 0xf0) {
case 0xf0:
switch (event) {
case 0xff:
GST_DEBUG_OBJECT (fluidsynth, "system reset");
fluid_synth_system_reset (fluidsynth->synth);
break;
case 0xf0:
case 0xf7:
GST_DEBUG_OBJECT (fluidsynth, "sysex 0x%02x", event);
GST_MEMDUMP_OBJECT (fluidsynth, "bytes ", info.data + 1,
info.size - 1);
fluid_synth_sysex (fluidsynth->synth, (char *) info.data + 1,
info.size - 1, NULL, NULL, NULL, 0);
break;
case 0xf9:
GST_LOG_OBJECT (fluidsynth, "midi tick");
break;
default:
GST_WARNING_OBJECT (fluidsynth, "unhandled event 0x%02x", event);
break;
}
break;
default:
{
guint8 channel, p1, p2;
channel = event & 0x0f;
p1 = info.size > 1 ? info.data[1] & 0x7f : 0;
p2 = info.size > 2 ? info.data[2] & 0x7f : 0;
GST_DEBUG_OBJECT (fluidsynth, "event 0x%02x channel %d, 0x%02x 0x%02x",
event, channel, p1, p2);
switch (event & 0xf0) {
case 0x80:
fluid_synth_noteoff (fluidsynth->synth, channel, p1);
break;
case 0x90:
fluid_synth_noteon (fluidsynth->synth, channel, p1, p2);
break;
case 0xA0:
/* aftertouch */
break;
case 0xB0:
fluid_synth_cc (fluidsynth->synth, channel, p1, p2);
break;
case 0xC0:
fluid_synth_program_change (fluidsynth->synth, channel, p1);
break;
case 0xD0:
fluid_synth_channel_pressure (fluidsynth->synth, channel, p1);
break;
case 0xE0:
fluid_synth_pitch_bend (fluidsynth->synth, channel, (p2 << 7) | p1);
break;
default:
break;
}
break;
}
}
gst_buffer_unmap (buffer, &info);
}
static GstFlowReturn
gst_fluidsynth_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buffer)
{
GstFlowReturn res = GST_FLOW_OK;
GstFluidsynth *fluidsynth;
GstClockTime pts;
fluidsynth = GST_FLUIDSYNTH (parent);
if (GST_BUFFER_IS_DISCONT (buffer)) {
fluidsynth->discont = TRUE;
}
pts = GST_BUFFER_PTS (buffer);
if (pts != GST_CLOCK_TIME_NONE) {
guint64 sample =
gst_util_uint64_scale_int (pts, FLUIDSYNTH_RATE, GST_SECOND);
if (fluidsynth->last_pts == GST_CLOCK_TIME_NONE) {
fluidsynth->last_pts = pts;
fluidsynth->last_sample = sample;
} else if (fluidsynth->last_pts < pts) {
/* generate samples for the elapsed time */
res = produce_samples (fluidsynth, pts, sample);
}
}
if (res == GST_FLOW_OK) {
handle_buffer (fluidsynth, buffer);
}
gst_buffer_unref (buffer);
return res;
}
static gboolean
gst_fluidsynth_open (GstFluidsynth * fluidsynth)
{
GDir *dir;
GError *error = NULL;
if (fluidsynth->sf != -1)
return TRUE;
if (fluidsynth->soundfont) {
GST_DEBUG_OBJECT (fluidsynth, "loading soundfont file %s",
fluidsynth->soundfont);
fluidsynth->sf = fluid_synth_sfload (fluidsynth->synth,
fluidsynth->soundfont, 1);
if (fluidsynth->sf == -1)
goto load_failed;
GST_DEBUG_OBJECT (fluidsynth, "loaded soundfont file %s",
fluidsynth->soundfont);
} else {
dir = g_dir_open (SOUNDFONT_PATH, 0, &error);
if (dir == NULL)
goto open_dir_failed;
while (TRUE) {
const gchar *name;
gchar *filename;
if ((name = g_dir_read_name (dir)) == NULL)
break;
filename = g_build_filename (SOUNDFONT_PATH, name, NULL);
GST_DEBUG_OBJECT (fluidsynth, "loading soundfont file %s", filename);
fluidsynth->sf = fluid_synth_sfload (fluidsynth->synth, filename, 1);
if (fluidsynth->sf != -1) {
GST_DEBUG_OBJECT (fluidsynth, "loaded soundfont file %s", filename);
break;
}
GST_DEBUG_OBJECT (fluidsynth, "could not load soundfont file %s",
filename);
}
g_dir_close (dir);
if (fluidsynth->sf == -1)
goto no_soundfont;
}
return TRUE;
/* ERRORS */
load_failed:
{
GST_ELEMENT_ERROR (fluidsynth, RESOURCE, OPEN_READ,
("Can't open soundfont %s", fluidsynth->soundfont),
("failed to open soundfont file %s for reading",
fluidsynth->soundfont));
return FALSE;
}
open_dir_failed:
{
GST_ELEMENT_ERROR (fluidsynth, RESOURCE, OPEN_READ,
("Can't open directory %s", SOUNDFONT_PATH),
("failed to open directory %s for reading: %s", SOUNDFONT_PATH,
error->message));
g_error_free (error);
return FALSE;
}
no_soundfont:
{
GST_ELEMENT_ERROR (fluidsynth, RESOURCE, OPEN_READ,
("Can't find soundfont file in directory %s", SOUNDFONT_PATH),
("No usable soundfont files found in %s", SOUNDFONT_PATH));
return FALSE;
}
}
static gboolean
gst_fluidsynth_close (GstFluidsynth * fluidsynth)
{
if (fluidsynth->sf) {
fluid_synth_sfunload (fluidsynth->synth, fluidsynth->sf, 1);
fluidsynth->sf = -1;
}
return TRUE;
}
static GstStateChangeReturn
gst_fluidsynth_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstFluidsynth *fluidsynth = GST_FLUIDSYNTH (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_fluidsynth_open (fluidsynth))
goto open_failed;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_fluidsynth_reset (fluidsynth);
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_NULL:
gst_fluidsynth_close (fluidsynth);
break;
default:
break;
}
return ret;
/* ERRORS */
open_failed:
{
GST_ERROR_OBJECT (fluidsynth, "could not open");
return GST_STATE_CHANGE_FAILURE;
}
}
static void
gst_fluidsynth_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstFluidsynth *fluidsynth = GST_FLUIDSYNTH (object);
switch (prop_id) {
case PROP_SOUNDFONT:
g_free (fluidsynth->soundfont);
fluidsynth->soundfont = g_value_dup_string (value);
break;
case PROP_SYNTH_CHORUS:
fluidsynth->synth_chorus = g_value_get_boolean (value);
fluid_synth_set_chorus_on (fluidsynth->synth, fluidsynth->synth_chorus);
break;
case PROP_SYNTH_REVERB:
fluidsynth->synth_reverb = g_value_get_boolean (value);
fluid_synth_set_reverb_on (fluidsynth->synth, fluidsynth->synth_reverb);
break;
case PROP_SYNTH_GAIN:
fluidsynth->synth_gain = g_value_get_double (value);
fluid_synth_set_gain (fluidsynth->synth, fluidsynth->synth_gain);
break;
case PROP_SYNTH_POLYPHONY:
fluidsynth->synth_polyphony = g_value_get_int (value);
fluid_synth_set_polyphony (fluidsynth->synth,
fluidsynth->synth_polyphony);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_fluidsynth_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstFluidsynth *fluidsynth = GST_FLUIDSYNTH (object);
switch (prop_id) {
case PROP_SOUNDFONT:
g_value_set_string (value, fluidsynth->soundfont);
break;
case PROP_SYNTH_CHORUS:
g_value_set_boolean (value, fluidsynth->synth_chorus);
break;
case PROP_SYNTH_REVERB:
g_value_set_boolean (value, fluidsynth->synth_reverb);
break;
case PROP_SYNTH_GAIN:
g_value_set_double (value, fluidsynth->synth_gain);
break;
case PROP_SYNTH_POLYPHONY:
g_value_set_int (value, fluidsynth->synth_polyphony);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_fluidsynth_debug, "fluidsynth",
0, "Fluidsynth plugin");
return gst_element_register (plugin, "fluidsynth",
GST_RANK_SECONDARY, GST_TYPE_FLUIDSYNTH);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
fluidsynth,
"Fluidsynth Plugin",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|