diff --git a/include/Mixer.h b/include/Mixer.h new file mode 100644 index 0000000..bbb48bd --- /dev/null +++ b/include/Mixer.h @@ -0,0 +1,24 @@ +/* $Id$ */ +/* Copyright (c) 2017 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Mixer */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#ifndef DESKTOP_MIXER_H +# define DESKTOP_MIXER_H + + +# include "Mixer/control.h" + +#endif /* !DESKTOP_MIXER_H */ diff --git a/include/Mixer/control.h b/include/Mixer/control.h new file mode 100644 index 0000000..65017d3 --- /dev/null +++ b/include/Mixer/control.h @@ -0,0 +1,56 @@ +/* $Id$ */ +/* Copyright (c) 2017 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Mixer */ +/* All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + + + +#ifndef DESKTOP_MIXER_CONTROL_H +# define DESKTOP_MIXER_CONTROL_H + +# include +# include +# include + + +/* MixerControlPlugin */ +typedef struct _MixerControlPlugin MixerControlPlugin; + +typedef struct _MixerControlDefinition +{ + String const * icon; + String const * name; + String const * description; + + /* callbacks */ + MixerControlPlugin * (*init)(String const * type, va_list properties); + void (*destroy)(MixerControlPlugin * plugin); + + GtkWidget * (*get_widget)(MixerControlPlugin * plugin); + int (*set)(MixerControlPlugin * plugin, va_list properties); +} MixerControlDefinition; + +#endif /* !DESKTOP_MIXER_CONTROL_H */ diff --git a/include/Mixer/project.conf b/include/Mixer/project.conf new file mode 100644 index 0000000..1cdbf23 --- /dev/null +++ b/include/Mixer/project.conf @@ -0,0 +1,5 @@ +includes=control.h +dist=Makefile + +[control.h] +install=$(PREFIX)/include/Desktop/Mixer diff --git a/include/project.conf b/include/project.conf new file mode 100644 index 0000000..85dbd9f --- /dev/null +++ b/include/project.conf @@ -0,0 +1,6 @@ +subdirs=Mixer +includes=Mixer.h +dist=Makefile + +[Mixer.h] +install=$(PREFIX)/include/Desktop diff --git a/project.conf b/project.conf index bd0f515..138de61 100644 --- a/project.conf +++ b/project.conf @@ -2,7 +2,7 @@ package=Mixer version=0.2.2 config=h,sh -subdirs=data,doc,po,src,tests +subdirs=data,doc,include,po,src,tests dist=COPYING,Makefile,README.md,config.h,config.sh [README.md] diff --git a/src/control.c b/src/control.c new file mode 100644 index 0000000..f5d4795 --- /dev/null +++ b/src/control.c @@ -0,0 +1,152 @@ +/* $Id$ */ +/* Copyright (c) 2017 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Mixer */ +/* All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + + + +#include +#include +#include "Mixer/control.h" +#include "control.h" +#include "../config.h" + + +/* private */ +/* types */ +struct _MixerControl +{ + String * id; + Plugin * handle; + MixerControlDefinition * definition; + MixerControlPlugin * plugin; + GtkWidget * widget; + + /* widgets */ + GtkWidget * frame; + GtkWidget * icon; + GtkWidget * name; +}; + + +/* public */ +/* functions */ +/* mixercontrol_new */ +MixerControl * mixercontrol_new(String const * id, String const * icon, + String const * name, String const * type, ...) +{ + MixerControl * control; + va_list ap; + GtkWidget * hbox; + + if((control = object_new(sizeof(*control))) == NULL) + return NULL; + control->id = string_new(id); + control->handle = plugin_new(LIBDIR, PACKAGE, "controls", type); + control->frame = NULL; + va_start(ap, type); + if(control->id == NULL + || control->handle == NULL + || (control->definition = plugin_lookup(control->handle, + "control")) == NULL + || control->definition->init == NULL + || control->definition->destroy == NULL + || (control->plugin = control->definition->init(type, + ap)) == NULL + || control->definition->get_widget == NULL + || (control->widget = control->definition->get_widget( + control->plugin)) == NULL) + { + va_end(ap); + mixercontrol_delete(control); + return NULL; + } + va_end(ap); + /* widgets */ + control->frame = gtk_frame_new(NULL); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); + control->icon = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_MENU); + gtk_box_pack_start(GTK_BOX(hbox), control->icon, FALSE, TRUE, 0); + control->name = gtk_label_new(name); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_set_halign(control->name, GTK_ALIGN_START); +#else + gtk_misc_set_alignment(GTK_MISC(control->name), 0.0, 0.5); +#endif + gtk_box_pack_start(GTK_BOX(hbox), control->name, TRUE, TRUE, 0); + return control; +} + + +/* mixercontrol_delete */ +void mixercontrol_delete(MixerControl * control) +{ + if(control->plugin != NULL && control->definition->destroy != NULL) + control->definition->destroy(control->plugin); + if(control->handle != NULL) + plugin_delete(control->handle); + if(control->frame != NULL) + g_object_unref(control->frame); + if(control->id != NULL) + string_delete(control->id); + object_delete(control); +} + + +/* accessors */ +/* mixercontrol_get_id */ +String const * mixercontrol_get_id(MixerControl * control) +{ + return control->id; +} + + +/* mixercontrol_get_widget */ +GtkWidget * mixercontrol_get_widget(MixerControl * control) +{ + return control->frame; +} + + +/* mixercontrol_set */ +int mixercontrol_set(MixerControl * control, ...) +{ + int ret; + va_list ap; + + va_start(ap, control); + ret = control->definition->set(control->plugin, ap); + va_end(ap); + return ret; +} + + +/* mixercontrol_set_icon */ +void mixercontrol_set_icon(MixerControl * control, String const * icon) +{ + gtk_image_set_from_icon_name(GTK_IMAGE(control->icon), icon, + GTK_ICON_SIZE_MENU); +} diff --git a/src/control.h b/src/control.h new file mode 100644 index 0000000..e06b3ab --- /dev/null +++ b/src/control.h @@ -0,0 +1,55 @@ +/* $Id$ */ +/* Copyright (c) 2017 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Mixer */ +/* All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + + + +#ifndef MIXER_CONTROL_H +# define MIXER_CONTROL_H + +# include +# include + + +/* MixerControl */ +/* types */ +typedef struct _MixerControl MixerControl; + + +/* functions */ +MixerControl * mixercontrol_new(String const * id, String const * icon, + String const * name, String const * type, ...); +void mixercontrol_delete(MixerControl * control); + +/* accessors */ +String const * mixercontrol_get_id(MixerControl * control); +GtkWidget * mixercontrol_get_widget(MixerControl * control); + +int mixercontrol_set(MixerControl * control, ...); +void mixercontrol_set_icon(MixerControl * control, String const * icon); + +#endif /* !MIXER_CONTROL_H */ diff --git a/src/project.conf b/src/project.conf index c3af87e..bddf76f 100644 --- a/src/project.conf +++ b/src/project.conf @@ -1,4 +1,5 @@ targets=mixer +cppflags_force=-I../include #cppflags=-D EMBEDDED cflags_force=`pkg-config --cflags libDesktop` cflags=-W -Wall -g -O2 -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all @@ -8,9 +9,12 @@ dist=Makefile,mixer.h,window.h,callbacks.h [mixer] type=binary -sources=mixer.c,window.c,callbacks.c,main.c +sources=control.c,mixer.c,window.c,callbacks.c,main.c install=$(BINDIR) +[control.c] +depends=control.h,../config.h + [mixer.c] depends=callbacks.h,mixer.h,../config.h