void plugin_do_configure (PluginHandle * plugin) { g_return_if_fail (plugin_get_enabled (plugin)); Plugin * header = plugin_get_header (plugin); g_return_if_fail (header); if (PLUGIN_HAS_FUNC (header, configure)) header->configure (); else if (PLUGIN_HAS_FUNC (header, prefs)) plugin_make_config_window (plugin); }
void plugin_do_about (PluginHandle * plugin) { g_return_if_fail (plugin_get_enabled (plugin)); Plugin * header = plugin_get_header (plugin); g_return_if_fail (header); if (PLUGIN_HAS_FUNC (header, about)) header->about (); else if (PLUGIN_HAS_FUNC (header, about_text)) plugin_make_about_window (plugin); }
void interface_show (bool_t show) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, show)) current_interface->show (show); }
void interface_show_jump_to_track (void) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, show_jump_to_track)) current_interface->show_jump_to_track (); }
/* * bool_t play_button * TRUE - open files * FALSE - add files */ void interface_show_filebrowser (bool_t play_button) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, show_filebrowser)) current_interface->show_filebrowser (play_button); }
bool_t interface_is_focused (void) { g_return_val_if_fail (current_interface, FALSE); if (PLUGIN_HAS_FUNC (current_interface, is_focused)) return current_interface->is_focused (); return TRUE; }
Plugin * plugin_load (const char * filename) { AUDDBG ("Loading plugin: %s.\n", filename); GModule * module = g_module_open (filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (! module) { fprintf (stderr, " *** ERROR: %s could not be loaded: %s\n", filename, g_module_error ()); return NULL; } void * ptr; if (! g_module_symbol (module, "get_plugin_info", & ptr)) ptr = NULL; Plugin * (* func) (AudAPITable * table) = ptr; Plugin * header; if (! func || ! (header = func (& api_table)) || header->magic != _AUD_PLUGIN_MAGIC) { fprintf (stderr, " *** ERROR: %s is not a valid Audacious plugin.\n", filename); g_module_close (module); return NULL; } if (header->version < _AUD_PLUGIN_VERSION_MIN || header->version > _AUD_PLUGIN_VERSION) { fprintf (stderr, " *** ERROR: %s is not compatible with this version " "of Audacious.\n", filename); g_module_close (module); return NULL; } if (header->type == PLUGIN_TYPE_TRANSPORT || header->type == PLUGIN_TYPE_PLAYLIST || header->type == PLUGIN_TYPE_INPUT || header->type == PLUGIN_TYPE_EFFECT) { if (PLUGIN_HAS_FUNC (header, init) && ! header->init ()) { fprintf (stderr, " *** ERROR: %s failed to initialize.\n", filename); g_module_close (module); return NULL; } } pthread_mutex_lock (& mutex); LoadedModule * loaded = g_slice_new (LoadedModule); loaded->header = header; loaded->module = module; loaded_modules = g_list_prepend (loaded_modules, loaded); pthread_mutex_unlock (& mutex); return header; }
void interface_unload (void) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, cleanup)) current_interface->cleanup (); current_interface = NULL; }
void interface_uninstall_toolbar (void * widget) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, uninstall_toolbar)) current_interface->uninstall_toolbar (widget); else g_object_unref (widget); }
void interface_remove_plugin_widget (PluginHandle * plugin, GtkWidget * widget) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, stop_gtk_plugin)) current_interface->stop_gtk_plugin (widget); else gtk_widget_destroy (gtk_widget_get_parent (widget)); }
bool_t interface_load (PluginHandle * plugin) { IfacePlugin * i = plugin_get_header (plugin); g_return_val_if_fail (i, FALSE); if (PLUGIN_HAS_FUNC (i, init) && ! i->init ()) return FALSE; current_interface = i; return TRUE; }
int plugin_send_message (PluginHandle * plugin, const char * code, const void * data, int size) { if (! plugin_get_enabled (plugin)) return ENOSYS; Plugin * header = plugin_get_header (plugin); if (! header || ! PLUGIN_HAS_FUNC (header, take_message)) return ENOSYS; return header->take_message (code, data, size); }
void effect_flush (void) { pthread_mutex_lock (& mutex); for (GList * node = running_effects; node != NULL; node = node->next) { if (PLUGIN_HAS_FUNC (((RunningEffect *) node->data)->header, flush)) ((RunningEffect *) node->data)->header->flush (); } pthread_mutex_unlock (& mutex); }
static void plugin2_unload (LoadedModule * loaded) { Plugin * header = loaded->header; switch (header->type) { case PLUGIN_TYPE_TRANSPORT: case PLUGIN_TYPE_PLAYLIST: case PLUGIN_TYPE_INPUT: case PLUGIN_TYPE_EFFECT: if (PLUGIN_HAS_FUNC (header, settings)) plugin_preferences_cleanup (header->settings); if (PLUGIN_HAS_FUNC (header, cleanup)) header->cleanup (); break; } pthread_mutex_lock (& mutex); g_module_close (loaded->module); g_slice_free (LoadedModule, loaded); pthread_mutex_unlock (& mutex); }
int effect_adjust_delay (int delay) { pthread_mutex_lock (& mutex); for (GList * node = g_list_last (running_effects); node != NULL; node = node->prev) { if (PLUGIN_HAS_FUNC (((RunningEffect *) node->data)->header, adjust_delay)) delay = ((RunningEffect *) node->data)->header->adjust_delay (delay); } pthread_mutex_unlock (& mutex); return delay; }
int effect_output_to_decoder_time (int time) { pthread_mutex_lock (& mutex); for (GList * node = g_list_last (running_effects); node != NULL; node = node->prev) { if (PLUGIN_HAS_FUNC (((RunningEffect *) node->data)->header, output_to_decoder_time)) time = ((RunningEffect *) node->data)->header->output_to_decoder_time (time); } pthread_mutex_unlock (& mutex); return time; }
int effect_decoder_to_output_time (int time) { pthread_mutex_lock (& mutex); for (GList * node = running_effects; node != NULL; node = node->next) { if (PLUGIN_HAS_FUNC (((RunningEffect *) node->data)->header, decoder_to_output_time)) time = ((RunningEffect *) node->data)->header->decoder_to_output_time (time); } pthread_mutex_unlock (& mutex); return time; }
bool_t playlist_save (int list, const char * filename) { AUDDBG ("Saving playlist %s.\n", filename); PluginHandle * plugin = get_plugin (filename, TRUE); if (! plugin) return FALSE; PlaylistPlugin * pp = plugin_get_header (plugin); g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE); bool_t fast = get_bool (NULL, "metadata_on_play"); VFSFile * file = vfs_fopen (filename, "w"); if (! file) return FALSE; char * title = playlist_get_title (list); int entries = playlist_entry_count (list); Index * filenames = index_new (); index_allocate (filenames, entries); Index * tuples = index_new (); index_allocate (tuples, entries); for (int i = 0; i < entries; i ++) { index_append (filenames, playlist_entry_get_filename (list, i)); index_append (tuples, playlist_entry_get_tuple (list, i, fast)); } bool_t success = pp->save (filename, file, title, filenames, tuples); vfs_fclose (file); str_unref (title); for (int i = 0; i < entries; i ++) { str_unref (index_get (filenames, i)); Tuple * tuple = index_get (tuples, i); if (tuple) tuple_unref (tuple); } index_free (filenames); index_free (tuples); return success; }
void interface_add_plugin_widget (PluginHandle * plugin, GtkWidget * widget) { g_return_if_fail (current_interface); if (PLUGIN_HAS_FUNC (current_interface, run_gtk_plugin)) current_interface->run_gtk_plugin (widget, plugin_get_name (plugin)); else { GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title ((GtkWindow *) window, plugin_get_name (plugin)); gtk_window_set_default_size ((GtkWindow *) window, 300, 200); gtk_container_add ((GtkContainer *) window, widget); g_signal_connect (window, "delete-event", (GCallback) delete_cb, plugin); gtk_widget_show_all (window); } }
bool_t playlist_load (const char * filename, char * * title, Index * * filenames_p, Index * * tuples_p) { AUDDBG ("Loading playlist %s.\n", filename); PluginHandle * plugin = get_plugin (filename, FALSE); if (! plugin) return FALSE; PlaylistPlugin * pp = plugin_get_header (plugin); g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE); VFSFile * file = vfs_fopen (filename, "r"); if (! file) return FALSE; Index * filenames = index_new (); Index * tuples = index_new (); bool_t success = pp->load (filename, file, title, filenames, tuples); vfs_fclose (file); if (! success) { index_free (filenames); index_free (tuples); return FALSE; } if (index_count (tuples)) g_return_val_if_fail (index_count (tuples) == index_count (filenames), FALSE); else { index_free (tuples); tuples = NULL; } * filenames_p = filenames; * tuples_p = tuples; return TRUE; }
static void plugin2_process (Plugin * header, GModule * module, const char * filename) { if (header->magic != _AUD_PLUGIN_MAGIC) { fprintf (stderr, " *** ERROR: %s is not a valid MLPlayer plugin.\n", filename); g_module_close (module); return; } if (header->version < _AUD_PLUGIN_VERSION_MIN || header->version > _AUD_PLUGIN_VERSION) { fprintf (stderr, " *** ERROR: %s is not compatible with this version of MLPlayer.\n", filename); g_module_close (module); return; } switch (header->type) { case PLUGIN_TYPE_TRANSPORT: case PLUGIN_TYPE_PLAYLIST: case PLUGIN_TYPE_INPUT: case PLUGIN_TYPE_EFFECT: if (PLUGIN_HAS_FUNC (header, init) && ! header->init ()) { fprintf (stderr, " *** ERROR: %s failed to initialize.\n", filename); g_module_close (module); return; } break; } pthread_mutex_lock (& mutex); LoadedModule * loaded = g_slice_new (LoadedModule); loaded->header = header; loaded->module = module; loaded_modules = g_list_prepend (loaded_modules, loaded); pthread_mutex_unlock (& mutex); plugin_register_loaded (filename, header); }
static void plugin2_unload (LoadedModule * loaded) { Plugin * header = loaded->header; switch (header->type) { case PLUGIN_TYPE_TRANSPORT: case PLUGIN_TYPE_PLAYLIST: case PLUGIN_TYPE_INPUT: case PLUGIN_TYPE_EFFECT: if (PLUGIN_HAS_FUNC (header, cleanup)) header->cleanup (); break; } pthread_mutex_lock (& mutex); #ifndef VALGRIND_FRIENDLY g_module_close (loaded->module); #endif g_slice_free (LoadedModule, loaded); pthread_mutex_unlock (& mutex); }
static bool_t error_idle_func (void * unused) { pthread_mutex_lock (& error_mutex); char * message; while ((message = g_queue_pop_head (& error_queue))) { pthread_mutex_unlock (& error_mutex); if (current_interface && PLUGIN_HAS_FUNC (current_interface, show_error)) current_interface->show_error (message); else fprintf (stderr, "ERROR: %s\n", message); g_free (message); pthread_mutex_lock (& error_mutex); } error_source = 0; pthread_mutex_unlock (& error_mutex); return FALSE; }