Created
May 14, 2018 20:49
-
-
Save saivert/e44a1ab34151c65958cfb8000015639a to your computer and use it in GitHub Desktop.
deadbeef plugin written in D broken sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Example misc plugin for the DeaDBeeF audio player | |
written using the D programming language | |
Copyright (C) 2017 Nicolai Syvertsen <saivert@gmail.com> | |
This program 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 2 | |
of the License, or (at your option) any later version. | |
This program 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 this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
*/ | |
import core.runtime; | |
import deadbeef.api; | |
import deadbeef.gtkui; | |
import gtk.MessageDialog; | |
import gtkc.glib; | |
import headerbarui; | |
import std.stdio; | |
import std.string; | |
import std.experimental.logger; | |
static DB_functions_t *deadbeefapi; | |
HeaderbarUI ui; | |
struct Flags { | |
bool disable; | |
bool embed_menubar; | |
bool show_seek_bar; | |
bool seekbar_minimized; | |
bool hide_seekbar_on_streaming; | |
bool combined_playpause; | |
bool show_preferences_button; | |
int button_spacing; | |
} | |
Flags headerbarui_flags; | |
bool headerbar_stoptimer; | |
uint headerbar_timer; | |
void | |
printmsg(string a) { | |
deadbeefapi.log("some-dlang-plugin: %s\n", a.toStringz()); | |
} | |
void | |
headerbarui_getconfig() | |
{ | |
trace(""); | |
headerbarui_flags.disable = !!deadbeefapi.conf_get_int ("headerbarui.disable", 0); | |
headerbarui_flags.embed_menubar = !!deadbeefapi.conf_get_int ("headerbarui.embed_menubar", 0); | |
headerbarui_flags.show_seek_bar = !!deadbeefapi.conf_get_int ("headerbarui.show_seek_bar", 1); | |
if (headerbarui_flags.show_seek_bar) | |
headerbarui_flags.hide_seekbar_on_streaming = !!deadbeefapi.conf_get_int ("headerbarui.hide_seekbar_on_streaming", 0); | |
else | |
headerbarui_flags.hide_seekbar_on_streaming = false; | |
headerbarui_flags.combined_playpause = !!deadbeefapi.conf_get_int ("headerbarui.combined_playpause", 1); | |
headerbarui_flags.show_preferences_button = !!deadbeefapi.conf_get_int ("headerbarui.show_preferences_button", 0); | |
headerbarui_flags.button_spacing = !!deadbeefapi.conf_get_int ("headerbarui.button_spacing", 6); | |
} | |
int | |
gtkui_get_gui_refresh_rate () { | |
int fps = deadbeefapi.conf_get_int ("gtkui.refresh_rate", 10); | |
if (fps < 1) { | |
fps = 1; | |
} | |
else if (fps > 30) { | |
fps = 30; | |
} | |
return fps; | |
} | |
extern (C) { | |
int | |
plugin_connect() { | |
trace(""); | |
return 0; | |
} | |
int | |
headerbarui_update_seekbar_cb(void* userdata) { | |
return cast(int)headerbar_stoptimer; | |
} | |
int | |
headerbarui_message (uint id, ulong ctx, uint p1, uint p2) { | |
trace(); | |
printmsg("message"); | |
if (id != DB_EV_CONFIGCHANGED && headerbarui_flags.disable) return 0; | |
switch (id) { | |
case DB_EV_SONGSTARTED: | |
headerbar_stoptimer = false; | |
headerbar_timer = g_timeout_add (1000/gtkui_get_gui_refresh_rate (), &headerbarui_update_seekbar_cb, null); | |
break; | |
case DB_EV_SONGFINISHED: | |
headerbar_stoptimer = true; | |
break; | |
case DB_EV_CONFIGCHANGED: | |
//headerbarui_getconfig(); | |
//g_idle_add (headerbarui_configchanged_cb, NULL); | |
//g_idle_add (headerbarui_volume_changed, NULL); | |
break; | |
case DB_EV_VOLUMECHANGED: | |
//g_idle_add (headerbarui_volume_changed, NULL); | |
break; | |
default: break; | |
} | |
return 0; | |
} | |
int action1_callback(DB_plugin_action_s* action, int ctx) { | |
printmsg ("action called"); | |
return 0; | |
} | |
static DB_plugin_action_s action1 = { | |
flags: DB_ACTION_COMMON, | |
title: "Some test action", | |
name: "suckyaction", | |
callback2: &action1_callback | |
}; | |
static DB_misc_t plugin; | |
DB_plugin_t * | |
libdpluginsample_load (DB_functions_t *api) { | |
Runtime.initialize(); | |
deadbeefapi = api; | |
with (plugin.plugin) { | |
type = DB_PLUGIN_MISC; | |
api_vmajor = 1; | |
api_vminor = 10; | |
version_major = 1; | |
version_minor = 0; | |
id = "some-dlang-plugin"; | |
name = "D is best"; | |
descr = "A plugin written in D"; | |
copyright = ""; | |
website = "http://saivert.com"; | |
connect = &plugin_connect; | |
get_actions = function DB_plugin_action_s *(DB_playItem_t* it) { | |
return &action1; | |
}; | |
stop = function int() { | |
Runtime.terminate(); | |
return 0; | |
}; | |
message = &headerbarui_message; | |
} | |
return cast(DB_plugin_t*)&plugin; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment