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 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
|
/* GSequencer - Advanced GTK Sequencer
* Copyright (C) 2005-2020 Joël Krähemann
*
* This file is part of GSequencer.
*
* GSequencer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GSequencer 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GSequencer. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ags/plugin/ags_dssi_plugin.h>
#include <ags/plugin/ags_plugin_port.h>
#if defined(AGS_W32API)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <ags/i18n.h>
void ags_dssi_plugin_class_init(AgsDssiPluginClass *dssi_plugin);
void ags_dssi_plugin_init (AgsDssiPlugin *dssi_plugin);
void ags_dssi_plugin_set_property(GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *param_spec);
void ags_dssi_plugin_get_property(GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *param_spec);
void ags_dssi_plugin_finalize(GObject *gobject);
gpointer ags_dssi_plugin_instantiate(AgsBasePlugin *base_plugin,
guint samplerate, guint buffer_size);
void ags_dssi_plugin_connect_port(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
guint port_index,
gpointer data_location);
void ags_dssi_plugin_activate(AgsBasePlugin *base_plugin,
gpointer plugin_handle);
void ags_dssi_plugin_deactivate(AgsBasePlugin *base_plugin,
gpointer plugin_handle);
void ags_dssi_plugin_run(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
snd_seq_event_t *seq_event,
guint frame_count);
void ags_dssi_plugin_load_plugin(AgsBasePlugin *base_plugin);
void ags_dssi_plugin_real_change_program(AgsDssiPlugin *dssi_plugin,
gpointer ladspa_handle,
guint bank_index,
guint program_index);
/**
* SECTION:ags_dssi_plugin
* @short_description: The dssi plugin class
* @title: AgsDssiPlugin
* @section_id:
* @include: ags/plugin/ags_dssi_plugin.h
*
* The #AgsDssiPlugin loads/unloads a Dssi plugin.
*/
enum{
PROP_0,
PROP_UNIQUE_ID,
PROP_PROGRAM,
};
enum{
CHANGE_PROGRAM,
LAST_SIGNAL,
};
static gpointer ags_dssi_plugin_parent_class = NULL;
static guint dssi_plugin_signals[LAST_SIGNAL];
GType
ags_dssi_plugin_get_type (void)
{
static gsize g_define_type_id__static = 0;
if(g_once_init_enter(&g_define_type_id__static)){
GType ags_type_dssi_plugin = 0;
static const GTypeInfo ags_dssi_plugin_info = {
sizeof (AgsDssiPluginClass),
NULL, /* dssi_init */
NULL, /* dssi_finalize */
(GClassInitFunc) ags_dssi_plugin_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (AgsDssiPlugin),
0, /* n_preallocs */
(GInstanceInitFunc) ags_dssi_plugin_init,
};
ags_type_dssi_plugin = g_type_register_static(AGS_TYPE_BASE_PLUGIN,
"AgsDssiPlugin",
&ags_dssi_plugin_info,
0);
g_once_init_leave(&g_define_type_id__static, ags_type_dssi_plugin);
}
return(g_define_type_id__static);
}
void
ags_dssi_plugin_class_init(AgsDssiPluginClass *dssi_plugin)
{
AgsBasePluginClass *base_plugin;
GObjectClass *gobject;
GParamSpec *param_spec;
ags_dssi_plugin_parent_class = g_type_class_peek_parent(dssi_plugin);
/* GObjectClass */
gobject = (GObjectClass *) dssi_plugin;
gobject->set_property = ags_dssi_plugin_set_property;
gobject->get_property = ags_dssi_plugin_get_property;
gobject->finalize = ags_dssi_plugin_finalize;
/* properties */
/**
* AgsDssiPlugin:unique-id:
*
* The assigned unique-id.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_uint("unique-id",
i18n_pspec("unique-id of the plugin"),
i18n_pspec("The unique-id this plugin is assigned with"),
0,
G_MAXUINT,
0,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_UNIQUE_ID,
param_spec);
/**
* AgsBasePlugin:program:
*
* The assigned program.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("program",
i18n_pspec("program of the plugin"),
i18n_pspec("The program this plugin is located in"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_PROGRAM,
param_spec);
/* AgsBasePluginClass */
base_plugin = (AgsBasePluginClass *) dssi_plugin;
base_plugin->instantiate = ags_dssi_plugin_instantiate;
base_plugin->connect_port = ags_dssi_plugin_connect_port;
base_plugin->activate = ags_dssi_plugin_activate;
base_plugin->deactivate = ags_dssi_plugin_deactivate;
base_plugin->run = ags_dssi_plugin_run;
base_plugin->load_plugin = ags_dssi_plugin_load_plugin;
/* AgsDssiPluginClass */
dssi_plugin->change_program = ags_dssi_plugin_real_change_program;
/**
* AgsDssiPlugin::change-program:
* @dssi_plugin: the plugin to change-program
* @ladspa_handle: the LADSPA handle
* @bank: the bank number
* @program: the program number
*
* The ::change-program signal creates a new instance of plugin.
*
* Since: 3.0.0
*/
dssi_plugin_signals[CHANGE_PROGRAM] =
g_signal_new("change-program",
G_TYPE_FROM_CLASS (dssi_plugin),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (AgsDssiPluginClass, change_program),
NULL, NULL,
ags_cclosure_marshal_VOID__POINTER_UINT_UINT,
G_TYPE_NONE, 3,
G_TYPE_POINTER,
G_TYPE_UINT,
G_TYPE_UINT);
}
void
ags_dssi_plugin_init(AgsDssiPlugin *dssi_plugin)
{
ags_base_plugin_set_flags(AGS_BASE_PLUGIN(dssi_plugin),
AGS_BASE_PLUGIN_IS_INSTRUMENT);
dssi_plugin->unique_id = 0;
dssi_plugin->program = NULL;
}
void
ags_dssi_plugin_set_property(GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *param_spec)
{
AgsDssiPlugin *dssi_plugin;
GRecMutex *base_plugin_mutex;
dssi_plugin = AGS_DSSI_PLUGIN(gobject);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(dssi_plugin);
switch(prop_id){
case PROP_UNIQUE_ID:
{
g_rec_mutex_lock(base_plugin_mutex);
dssi_plugin->unique_id = g_value_get_uint(value);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_PROGRAM:
{
gchar *program;
program = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(dssi_plugin->program == program){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(dssi_plugin->program != NULL){
g_free(dssi_plugin->program);
}
dssi_plugin->program = g_strdup(program);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
break;
}
}
void
ags_dssi_plugin_get_property(GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *param_spec)
{
AgsDssiPlugin *dssi_plugin;
GRecMutex *base_plugin_mutex;
dssi_plugin = AGS_DSSI_PLUGIN(gobject);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(dssi_plugin);
switch(prop_id){
case PROP_UNIQUE_ID:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_uint(value, dssi_plugin->unique_id);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_PROGRAM:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, dssi_plugin->program);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
break;
}
}
void
ags_dssi_plugin_finalize(GObject *gobject)
{
AgsDssiPlugin *dssi_plugin;
dssi_plugin = AGS_DSSI_PLUGIN(gobject);
g_free(dssi_plugin->program);
/* call parent */
G_OBJECT_CLASS(ags_dssi_plugin_parent_class)->finalize(gobject);
}
gpointer
ags_dssi_plugin_instantiate(AgsBasePlugin *base_plugin,
guint samplerate, guint buffer_size)
{
LADSPA_Descriptor *ladspa_descriptor;
gpointer ptr;
LADSPA_Handle (*instantiate)(const struct _LADSPA_Descriptor *descriptor,
unsigned long ramplerate);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get instantiate */
g_rec_mutex_lock(base_plugin_mutex);
ladspa_descriptor = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin;
instantiate = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->instantiate;
g_rec_mutex_unlock(base_plugin_mutex);
/* instantiate */
ptr = NULL;
if(instantiate != NULL){
ptr = instantiate(ladspa_descriptor,
(unsigned long) samplerate);
}
return(ptr);
}
void
ags_dssi_plugin_connect_port(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
guint port_index,
gpointer data_location)
{
void (*connect_port)(LADSPA_Handle instance,
unsigned long port_index,
LADSPA_Data *data_location);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get connect port */
g_rec_mutex_lock(base_plugin_mutex);
connect_port = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->connect_port;
g_rec_mutex_unlock(base_plugin_mutex);
/* connect port */
if(plugin_handle != NULL){
connect_port((LADSPA_Handle) plugin_handle,
(unsigned long) port_index,
(LADSPA_Data *) data_location);
}
}
void
ags_dssi_plugin_activate(AgsBasePlugin *base_plugin,
gpointer plugin_handle)
{
void (*activate)(LADSPA_Handle instance);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* activate */
g_rec_mutex_lock(base_plugin_mutex);
activate = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->activate;
g_rec_mutex_unlock(base_plugin_mutex);
if(plugin_handle != NULL &&
activate != NULL){
activate((LADSPA_Handle) plugin_handle);
}
}
void
ags_dssi_plugin_deactivate(AgsBasePlugin *base_plugin,
gpointer plugin_handle)
{
void (*deactivate)(LADSPA_Handle instance);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* deactivate */
g_rec_mutex_lock(base_plugin_mutex);
deactivate = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->deactivate;
g_rec_mutex_unlock(base_plugin_mutex);
if(plugin_handle != NULL &&
deactivate != NULL){
deactivate((LADSPA_Handle) plugin_handle);
}
}
void
ags_dssi_plugin_run(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
snd_seq_event_t *seq_event,
guint frame_count)
{
void (*run_synth)(LADSPA_Handle instance,
unsigned long sample_count,
snd_seq_event_t *events,
unsigned long event_count);
void (*run)(LADSPA_Handle instance,
unsigned long sample_count);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* run */
g_rec_mutex_lock(base_plugin_mutex);
run_synth = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->run_synth;
run = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->run;
g_rec_mutex_unlock(base_plugin_mutex);
if(plugin_handle != NULL){
if(run_synth != NULL){
run_synth((LADSPA_Handle) plugin_handle,
(unsigned long) frame_count,
seq_event,
(unsigned long) 1);
}else{
run((LADSPA_Handle) plugin_handle,
(unsigned long) frame_count);
}
}
}
void
ags_dssi_plugin_load_plugin(AgsBasePlugin *base_plugin)
{
AgsDssiPlugin *dssi_plugin;
AgsPluginPort *current_plugin_port;
GList *plugin_port;
gchar *str;
DSSI_Descriptor_Function dssi_descriptor;
LADSPA_PortDescriptor *port_descriptor;
LADSPA_PortRangeHint *range_hint;
LADSPA_PortRangeHintDescriptor hint_descriptor;
unsigned long effect_index;
unsigned long port_count;
unsigned long i;
gboolean success;
GRecMutex *base_plugin_mutex;
dssi_plugin = AGS_DSSI_PLUGIN(base_plugin);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* dlopen */
g_rec_mutex_lock(base_plugin_mutex);
#ifdef AGS_W32API
base_plugin->plugin_so = LoadLibrary(base_plugin->filename);
#else
base_plugin->plugin_so = dlopen(base_plugin->filename,
RTLD_NOW|RTLD_GLOBAL);
#endif
if(base_plugin->plugin_so == NULL){
g_warning("ags_dssi_plugin.c - failed to load static object file");
#ifndef AGS_W32API
dlerror();
#endif
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
success = FALSE;
#ifdef AGS_W32API
base_plugin->plugin_handle =
dssi_descriptor = (DSSI_Descriptor_Function) GetProcAddress(base_plugin->plugin_so,
"dssi_descriptor");
success = (!dssi_descriptor) ? FALSE: TRUE;
#else
base_plugin->plugin_handle =
dssi_descriptor = (DSSI_Descriptor_Function) dlsym(base_plugin->plugin_so,
"dssi_descriptor");
success = (dlerror() == NULL) ? TRUE: FALSE;
#endif
g_rec_mutex_unlock(base_plugin_mutex);
if(success && dssi_descriptor){
gpointer plugin_descriptor;
guint unique_id;
g_rec_mutex_lock(base_plugin_mutex);
effect_index = base_plugin->effect_index;
plugin_descriptor =
base_plugin->plugin_descriptor = dssi_descriptor(effect_index);
g_rec_mutex_unlock(base_plugin_mutex);
if(plugin_descriptor != NULL){
g_rec_mutex_lock(base_plugin_mutex);
unique_id = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->UniqueID;
port_count = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->PortCount;
port_descriptor = AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->PortDescriptors;
g_rec_mutex_unlock(base_plugin_mutex);
g_object_set(base_plugin,
"unique-id", unique_id,
NULL);
plugin_port = NULL;
for(i = 0; i < port_count; i++){
/* create plugin port */
current_plugin_port = ags_plugin_port_new();
g_object_ref(current_plugin_port);
plugin_port = g_list_prepend(plugin_port,
current_plugin_port);
g_rec_mutex_lock(base_plugin_mutex);
/* set flags */
if(LADSPA_IS_PORT_INPUT(port_descriptor[i])){
current_plugin_port->flags |= AGS_PLUGIN_PORT_INPUT;
}else if(LADSPA_IS_PORT_OUTPUT(port_descriptor[i])){
current_plugin_port->flags |= AGS_PLUGIN_PORT_OUTPUT;
}
if(LADSPA_IS_PORT_CONTROL(port_descriptor[i])){
current_plugin_port->flags |= AGS_PLUGIN_PORT_CONTROL;
}else if(LADSPA_IS_PORT_AUDIO(port_descriptor[i])){
current_plugin_port->flags |= AGS_PLUGIN_PORT_AUDIO;
}
/* set index and name */
current_plugin_port->port_index = i;
current_plugin_port->port_name = g_strdup(AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->PortNames[i]);
range_hint = &(AGS_DSSI_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->LADSPA_Plugin->PortRangeHints[i]);
hint_descriptor = range_hint->HintDescriptor;
g_value_init(current_plugin_port->default_value,
G_TYPE_FLOAT);
g_value_init(current_plugin_port->lower_value,
G_TYPE_FLOAT);
g_value_init(current_plugin_port->upper_value,
G_TYPE_FLOAT);
g_value_set_float(current_plugin_port->default_value,
0.0);
if(LADSPA_IS_HINT_TOGGLED(hint_descriptor)){
/* is toggled */
current_plugin_port->flags |= AGS_PLUGIN_PORT_TOGGLED;
/* set default */
if(LADSPA_IS_HINT_DEFAULT_0(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
0.0);
}else if(LADSPA_IS_HINT_DEFAULT_1(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
1.0);
}
}else{
/* set lower */
g_value_set_float(current_plugin_port->lower_value,
range_hint->LowerBound);
/* set upper */
g_value_set_float(current_plugin_port->upper_value,
range_hint->UpperBound);
/* set default */
g_value_set_float(current_plugin_port->default_value,
range_hint->LowerBound);
/* bounds */
if(LADSPA_IS_HINT_BOUNDED_BELOW(hint_descriptor)){
if(LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)){
current_plugin_port->flags |= (AGS_PLUGIN_PORT_SAMPLERATE |
AGS_PLUGIN_PORT_BOUNDED_BELOW);
g_value_set_float(current_plugin_port->lower_value,
range_hint->LowerBound);
}
}
if(LADSPA_IS_HINT_BOUNDED_ABOVE(hint_descriptor)){
if(LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)){
current_plugin_port->flags |= (AGS_PLUGIN_PORT_SAMPLERATE |
AGS_PLUGIN_PORT_BOUNDED_ABOVE);
g_value_set_float(current_plugin_port->upper_value,
range_hint->UpperBound);
}
}
/* integer */
if(LADSPA_IS_HINT_INTEGER(hint_descriptor)){
current_plugin_port->flags |= AGS_PLUGIN_PORT_INTEGER;
current_plugin_port->scale_steps = range_hint->UpperBound - range_hint->LowerBound;
}
/* logarithmic */
if(LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)){
current_plugin_port->flags |= AGS_PLUGIN_PORT_LOGARITHMIC;
}
/* set default value */
if(LADSPA_IS_HINT_DEFAULT_0(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
0.0);
}else if(LADSPA_IS_HINT_DEFAULT_1(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
1.0);
}else if(LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
range_hint->LowerBound);
}else if(LADSPA_IS_HINT_DEFAULT_LOW(hint_descriptor)){
float default_value;
default_value = 0.75 * range_hint->LowerBound + 0.25 * range_hint->UpperBound;
g_value_set_float(current_plugin_port->default_value,
default_value);
}else if(LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_descriptor)){
float default_value;
default_value = (0.5 * range_hint->LowerBound) + (0.5 * range_hint->UpperBound);
g_value_set_float(current_plugin_port->default_value,
default_value);
}else if(LADSPA_IS_HINT_DEFAULT_HIGH(hint_descriptor)){
float default_value;
default_value = 0.25 * range_hint->LowerBound + 0.75 * range_hint->UpperBound;
g_value_set_float(current_plugin_port->default_value,
default_value);
}else if(LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
range_hint->UpperBound);
}else if(LADSPA_IS_HINT_DEFAULT_100(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
100.0);
}else if(LADSPA_IS_HINT_DEFAULT_440(hint_descriptor)){
g_value_set_float(current_plugin_port->default_value,
440.0);
}
}
g_rec_mutex_unlock(base_plugin_mutex);
}
base_plugin->plugin_port = g_list_reverse(plugin_port);
}
}
}
void
ags_dssi_plugin_real_change_program(AgsDssiPlugin *dssi_plugin,
gpointer ladspa_handle,
guint bank_index,
guint program_index)
{
void (*select_program)(LADSPA_Handle instance,
unsigned long bank,
unsigned long program);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(dssi_plugin);
/* get change program */
g_rec_mutex_lock(base_plugin_mutex);
select_program = AGS_DSSI_PLUGIN_DESCRIPTOR(AGS_BASE_PLUGIN(dssi_plugin)->plugin_descriptor)->select_program;
g_rec_mutex_unlock(base_plugin_mutex);
/* change program */
if(ladspa_handle != NULL &&
select_program != NULL){
select_program((void *) ladspa_handle,
(unsigned long) bank_index,
(unsigned long) program_index);
}
}
void
ags_dssi_plugin_change_program(AgsDssiPlugin *dssi_plugin,
gpointer ladspa_handle,
guint bank_index,
guint program_index)
{
g_return_if_fail(AGS_IS_DSSI_PLUGIN(dssi_plugin));
g_object_ref(G_OBJECT(dssi_plugin));
g_signal_emit(G_OBJECT(dssi_plugin),
dssi_plugin_signals[CHANGE_PROGRAM], 0,
ladspa_handle,
bank_index,
program_index);
g_object_unref(G_OBJECT(dssi_plugin));
}
/**
* ags_dssi_plugin_new:
* @filename: the plugin .so
* @effect: the effect's string representation
* @effect_index: the effect's index
*
* Create a new instance of #AgsDssiPlugin
*
* Returns: the new #AgsDssiPlugin
*
* Since: 3.0.0
*/
AgsDssiPlugin*
ags_dssi_plugin_new(gchar *filename, gchar *effect, guint effect_index)
{
AgsDssiPlugin *dssi_plugin;
dssi_plugin = (AgsDssiPlugin *) g_object_new(AGS_TYPE_DSSI_PLUGIN,
"filename", filename,
"effect", effect,
"effect-index", effect_index,
NULL);
return(dssi_plugin);
}
|