Menu

plugin

Attachments
AGS_plugin.png (133034 bytes)

Plugin interface to do abstraction

The AgsPlugin interface defines some elementary functions like get_name() or set_name() and therefor get_version(), set_version(), get_build_id() and set_build_id(). Further it contains functions used to persist it using XML. This would be get_xml_type(), set_xml_type(), read() and write(). And get_ports() and set_ports() to allow thread safe communication between the different layers of Advanced Gtk+ Sequencer but to be said those functions accomplish for persisting and restoring.

Diagram

Hands-on

The following example illustrates the usage of AgsPluginInterface with ags-echo effect.

First you need to tell object type system to use the AgsPluginInterface this is normally done in the classes get_type() function.

GType
ags_echo_channel_get_type()
{
  static GType ags_type_echo_channel = 0;

  if(!ags_type_echo_channel){
    static const GTypeInfo ags_echo_channel_info = {
      sizeof (AgsEchoChannelClass),
      NULL, /* base_init */
      NULL, /* base_finalize */
      (GClassInitFunc) ags_echo_channel_class_init,
      NULL, /* class_finalize */
      NULL, /* class_channel */
      sizeof (AgsEchoChannel),
      0,    /* n_preallocs */
      (GInstanceInitFunc) ags_echo_channel_init,
    };

    static const GInterfaceInfo ags_plugin_interface_info = {
      (GInterfaceInitFunc) ags_echo_channel_plugin_interface_init,
      NULL, /* interface_finalize */
      NULL, /* interface_data */
    };

    ags_type_echo_channel = g_type_register_static(AGS_TYPE_RECALL_CHANNEL,
                                                  "AgsEchoChannel\0",
                                                  &ags_echo_channel_info,
                                                  0);

    g_type_add_interface_static(ags_type_echo_channel,
                                AGS_TYPE_PLUGIN,
                                &ags_plugin_interface_info);
  }

  return(ags_type_echo_channel);
}

Implement its set_ports() function.

void
ags_echo_channel_plugin_interface_init(AgsPluginInterface *plugin)
{
  ags_echo_channel_parent_plugin_interface = g_type_interface_peek_parent(plugin);


  plugin->set_ports = ags_echo_channel_set_ports;
}

Finally load the ports restored of XML file.

ags_echo_channel_set_ports(AgsPlugin *plugin, GList *port)
{
  while(port != NULL){
    if(!strncmp(AGS_PORT(port->data)->specifier,
                "./delay[0]\0",
                10)){
      g_object_set(G_OBJECT(plugin),
                   "delay\0", AGS_PORT(port->data),
                   NULL);
    }else if(!strncmp(AGS_PORT(port->data)->specifier,
                      "./repeat[0]\0",
                      11)){
      g_object_set(G_OBJECT(plugin),
                   "repeat\0", AGS_PORT(port->data),
                   NULL);
    }else if(!strncmp(AGS_PORT(port->data)->specifier,
                      "./fade[0]\0",
                      9)){
      g_object_set(G_OBJECT(plugin),
                   "fade\0", AGS_PORT(port->data),
                   NULL);
    }else if(!strncmp(AGS_PORT(port->data)->specifier,
                      "./dry[0]\0",
                      8)){
      g_object_set(G_OBJECT(plugin),
                   "dry\0", AGS_PORT(port->data),
                   NULL);
    }

    port = port->next;
  }
}

Wow that's all.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.