[xiph-commits] r10417 - in trunk/maemo/OggPlay: . src
mgrimme at svn.xiph.org
mgrimme at svn.xiph.org
Sun Nov 20 16:05:48 PST 2005
Author: mgrimme
Date: 2005-11-20 16:05:41 -0800 (Sun, 20 Nov 2005)
New Revision: 10417
Added:
trunk/maemo/OggPlay/src/gui.h
trunk/maemo/OggPlay/src/main.c
Modified:
trunk/maemo/OggPlay/ChangeLog
trunk/maemo/OggPlay/src/Makefile.am
trunk/maemo/OggPlay/src/decoder.c
trunk/maemo/OggPlay/src/gui.c
Log:
cleaned up GUI code, applied patches by Ralph Giles, implemented fullscreen mode
Modified: trunk/maemo/OggPlay/ChangeLog
===================================================================
--- trunk/maemo/OggPlay/ChangeLog 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/ChangeLog 2005-11-21 00:05:41 UTC (rev 10417)
@@ -1,3 +1,18 @@
+2005-11-21 Martin Grimme <martin at pycage.de>
+
+ * src/gui.c: Implemented fullscreen mode.
+
+ * src/decoder.c: Applied patch by Ralph Giles <giles at xiph.org> for
+ case insensitive comment tag names.
+
+ * src/gui.c: Applied patch by Ralph Giles <giles at xiph.org> for volume
+ control with the [+] and [-] keys.
+
+2005-11-20 Martin Grimme <martin at pycage.de>
+
+ * src/main.c (main): Cleaned up and finally separated the GUI from
+ functionality.
+
2005-11-19 Martin Grimme <martin at pycage.de>
* src/decoder.c: Fixed some bugs.
Modified: trunk/maemo/OggPlay/src/Makefile.am
===================================================================
--- trunk/maemo/OggPlay/src/Makefile.am 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/src/Makefile.am 2005-11-21 00:05:41 UTC (rev 10417)
@@ -1,11 +1,14 @@
bin_PROGRAMS = oggplay
-oggplay_SOURCES = gui.c \
+oggplay_SOURCES = main.c \
+ gui.c gui.h \
decoder.c decoder.h \
audio.c audio.h \
stream.c stream.h \
ringbuffer.c ringbuffer.h
+
oggplay_CFLAGS = $(GTK_CFLAGS) $(OSSO_CFLAGS)
+
oggplay_LDADD = $(GTK_LIBS) $(OSSO_LIBS) \
/usr/lib/libvorbisidec.la \
-lSDL
Modified: trunk/maemo/OggPlay/src/decoder.c
===================================================================
--- trunk/maemo/OggPlay/src/decoder.c 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/src/decoder.c 2005-11-21 00:05:41 UTC (rev 10417)
@@ -1,4 +1,7 @@
/*
+ * Ogg vorbis decoder using the Tremor library
+ * Copyright (c) 2005 Martin Grimme <martin.grimme at lintegra.de>
+ *
* 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
@@ -121,12 +124,12 @@
for (i = 0; i < comment->comments; i++) {
printf("%s\n", comment->user_comments[i]);
- parts = g_strsplit(comment->user_comments[i], "=", 0);
- if (g_str_equal(parts[0], "TITLE"))
+ parts = g_strsplit(comment->user_comments[i], "=", 2);
+ if (g_strcasecmp(parts[0], "TITLE") == 0)
dec->tag_title = g_strdup(parts[1]);
- else if (g_str_equal(parts[0], "ARTIST"))
+ else if (g_strcasecmp(parts[0], "ARTIST") == 0)
dec->tag_artist = g_strdup(parts[1]);
- else if (g_str_equal(parts[0], "ALBUM"))
+ else if (g_strcasecmp(parts[0], "ALBUM") == 0)
dec->tag_album = g_strdup(parts[1]);
g_strfreev(parts);
Modified: trunk/maemo/OggPlay/src/gui.c
===================================================================
--- trunk/maemo/OggPlay/src/gui.c 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/src/gui.c 2005-11-21 00:05:41 UTC (rev 10417)
@@ -1,4 +1,7 @@
/*
+ * Graphical user interface for OggPlay
+ * Copyright (c) 2005 Martin Grimme <martin.grimme at lintegra.de>
+ *
* 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
@@ -15,119 +18,59 @@
*
*/
-#include <hildon-widgets/hildon-app.h>
-#include <hildon-widgets/hildon-appview.h>
-#include <hildon-widgets/hildon-file-chooser-dialog.h>
-#include <hildon-widgets/hildon-seekbar.h>
-#include <hildon-widgets/hildon-vvolumebar.h>
-#include <gtk/gtk.h>
-#include <libosso.h>
+#include "gui.h"
-#include "stream.h"
-#include "decoder.h"
+static gboolean
+keypress_cb(GtkWidget *src,
+ GdkEventKey *event,
+ Gui *gui) {
-#define SERVICE_NAME "oggplay"
-#define VERSION "0.12"
+ gdouble adjust = 5.0;
+ gdouble level = hildon_volumebar_get_level(HILDON_VOLUMEBAR(gui->volumebar));
+ switch (event->keyval) {
+ case GDK_F6: /* fullscreen button */
+ hildon_appview_set_fullscreen(gui->appview,
+ ! hildon_appview_get_fullscreen(gui->appview));
+ return TRUE;
-struct _AppData {
+ case GDK_F7: /* increase button */
+ hildon_volumebar_set_level(HILDON_VOLUMEBAR(gui->volumebar),
+ level + adjust);
+ return TRUE;
- Decoder *decoder;
- Stream *stream;
- HildonApp *app;
- HildonAppView *appview;
- GtkWidget *seekbar;
- GtkWidget *songlabel;
- GtkWidget *timelabel;
- int current_position;
+ case GDK_F8: /* decrease button */
+ hildon_volumebar_set_level(HILDON_VOLUMEBAR(gui->volumebar),
+ level - adjust);
+ return TRUE;
-};
-typedef struct _AppData AppData;
-
-
-
-static int
-idle_cb(AppData *appdata) {
-
- gint p, t;
- int mins, secs;
- char *time;
-
- p = decoder_get_position(appdata->decoder);
- t = decoder_get_total(appdata->decoder);
-
- appdata->current_position = p;
- hildon_seekbar_set_total_time(HILDON_SEEKBAR(appdata->seekbar), t);
- hildon_seekbar_set_position(HILDON_SEEKBAR(appdata->seekbar), p);
- hildon_seekbar_set_fraction(HILDON_SEEKBAR(appdata->seekbar), t);
-
- secs = p % 60;
- p /= 60;
- mins = p;
- time = g_strdup_printf(" %2d:%02d", mins, secs);
- gtk_label_set_text(GTK_LABEL(appdata->timelabel), time);
- g_free(time);
-
- return TRUE;
-
-}
-
-static void
-open_cb(GtkWidget *src,
- AppData *appdata) {
-
- GtkWidget *dialog;
- gchar *filename;
- char *text;
-
- dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(appdata->app),
- GTK_FILE_CHOOSER_ACTION_OPEN);
- gtk_widget_show_all(dialog);
-
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-
- filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-
- if (appdata->stream) {
- decoder_close_stream(appdata->decoder);
- }
-
- appdata->current_position = 0;
- hildon_seekbar_set_position(HILDON_SEEKBAR(appdata->seekbar), 0);
- appdata->stream = stream_new_from_uri(filename);
- decoder_open_stream(appdata->decoder, appdata->stream);
- text = g_strdup_printf("%s\n<b>%s</b>\n%s",
- appdata->decoder->tag_artist,
- appdata->decoder->tag_title,
- appdata->decoder->tag_album);
- gtk_label_set_markup(appdata->songlabel, text);
- g_free(text);
+ default:
+ return FALSE;
}
- gtk_widget_destroy(dialog);
}
static void
volume_cb(GtkWidget *src,
- AppData *appdata) {
+ Gui *gui) {
- decoder_set_volume(appdata->decoder,
- (int) hildon_volumebar_get_level(HILDON_VOLUMEBAR(src)));
+ (gui->volume_cb)(gui->volume_cb_data,
+ (int) hildon_volumebar_get_level(HILDON_VOLUMEBAR(src)));
}
static void
mute_cb(GtkWidget *src,
- AppData *appdata) {
+ Gui *gui) {
if (hildon_volumebar_get_mute(HILDON_VOLUMEBAR(src))) {
- decoder_set_volume(appdata->decoder, 0);
+ (gui->volume_cb)(gui->volume_cb_data, 0);
} else {
- decoder_set_volume(appdata->decoder,
+ (gui->volume_cb)(gui->volume_cb_data,
(int) hildon_volumebar_get_level(HILDON_VOLUMEBAR(src)));
}
@@ -136,102 +79,194 @@
static void
seek_cb(GtkWidget *src,
- AppData *appdata) {
+ Gui *gui) {
int position;
- position = hildon_seekbar_get_position(HILDON_SEEKBAR(appdata->seekbar));
- if (position != appdata->current_position) {
- appdata->current_position = position;
- decoder_seek(appdata->decoder, position * 1000);
+ position = hildon_seekbar_get_position(HILDON_SEEKBAR(src));
+ if (position != gui->seek_position) {
+ gui->seek_position = position;
+ (gui->seek_cb)(gui->seek_cb_data, position);
}
}
-int main(int argc, char *argv[]) {
+static void
+open_cb(GtkWidget *src,
+ Gui *gui) {
- osso_context_t *osso_context;
+ GtkWidget *dialog;
+ char *filename;
- HildonApp *app;
- HildonAppView *appview;
+ dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(gui->appwindow),
+ GTK_FILE_CHOOSER_ACTION_OPEN);
+ gtk_widget_show_all(dialog);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ (gui->open_cb)(gui->open_cb_data, filename);
+ }
+
+ gtk_widget_destroy(dialog);
+
+}
+
+
+
+Gui *
+gui_new() {
+
+ Gui *gui = g_new(Gui, 1);
GtkWidget *hbox;
- GtkWidget *volumebar;
- GtkWidget *songlabel;
GtkWidget *toolbar;
GtkToolItem *tb_open;
GtkToolItem *tb_seekbar;
GtkToolItem *tb_timelabel;
- GtkWidget *seekbar;
- AppData *appdata;
- gtk_init(&argc, &argv);
-
- app = HILDON_APP(hildon_app_new());
+ gui->appwindow = HILDON_APP(hildon_app_new());
+ hildon_app_set_title(gui->appwindow, "OggPlay");
+ hildon_app_set_two_part_title(gui->appwindow, FALSE);
- hildon_app_set_title(app, "OggPlay");
- hildon_app_set_two_part_title(app, FALSE);
+ gui->appview = HILDON_APPVIEW(hildon_appview_new(NULL));
+ hildon_app_set_appview(gui->appwindow, gui->appview);
- appdata = g_new(AppData, 1);
- appdata->app = app;
- appdata->decoder = decoder_new();
- appdata->stream = NULL;
-
- appview = HILDON_APPVIEW(hildon_appview_new(NULL));
- appdata->appview = appview;
- hildon_app_set_appview(app, appview);
-
hbox = gtk_hbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(appview), hbox);
+ gtk_container_add(GTK_CONTAINER(gui->appview), hbox);
- volumebar = hildon_vvolumebar_new();
- g_signal_connect(G_OBJECT(volumebar), "level-changed",
- G_CALLBACK(volume_cb), appdata);
- g_signal_connect(G_OBJECT(volumebar), "mute-toggled",
- G_CALLBACK(mute_cb), appdata);
- gtk_box_pack_start(GTK_BOX(hbox), volumebar, FALSE, FALSE, 0);
+ gui->volumebar = hildon_vvolumebar_new();
+ gtk_box_pack_start(GTK_BOX(hbox), gui->volumebar, FALSE, FALSE, 0);
- songlabel = gtk_label_new("");
- gtk_box_pack_start(GTK_BOX(hbox), songlabel, TRUE, TRUE, 0);
- appdata->songlabel = songlabel;
+ gui->songlabel = gtk_label_new("");
+ gtk_box_pack_start(GTK_BOX(hbox), gui->songlabel, TRUE, TRUE, 0);
toolbar = gtk_toolbar_new();
+ gtk_box_pack_end(GTK_BOX(gui->appview->vbox), toolbar, TRUE, TRUE, 0);
+
tb_open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
- g_signal_connect(G_OBJECT(tb_open), "clicked",
- G_CALLBACK(open_cb), appdata);
- seekbar = hildon_seekbar_new();
- appdata->seekbar = seekbar;
- g_signal_connect(G_OBJECT(seekbar), "value-changed",
- G_CALLBACK(seek_cb), appdata);
+ gui->seekbar = hildon_seekbar_new();
+ gtk_widget_set_size_request(gui->seekbar, 400, -1);
tb_seekbar = gtk_tool_item_new();
- gtk_container_add(GTK_CONTAINER(tb_seekbar), seekbar);
- gtk_widget_set_size_request(seekbar, 400, -1);
+ gtk_container_add(GTK_CONTAINER(tb_seekbar), gui->seekbar);
- appdata->timelabel = gtk_label_new("");
+ gui->timelabel = gtk_label_new("");
tb_timelabel = gtk_tool_item_new();
- gtk_container_add(GTK_CONTAINER(tb_timelabel), appdata->timelabel);
+ gtk_container_add(GTK_CONTAINER(tb_timelabel), gui->timelabel);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tb_open, -1);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tb_seekbar, -1);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tb_timelabel, -1);
- gtk_box_pack_end(GTK_BOX(appview->vbox), toolbar, TRUE, TRUE, 0);
+
+ /* connect signals */
+ g_signal_connect(G_OBJECT(gui->appwindow), "key-press-event",
+ G_CALLBACK(keypress_cb), gui);
+
+ g_signal_connect(G_OBJECT(gui->volumebar), "level-changed",
+ G_CALLBACK(volume_cb), gui);
+ g_signal_connect(G_OBJECT(gui->volumebar), "mute-toggled",
+ G_CALLBACK(mute_cb), gui);
+
+
+ g_signal_connect(G_OBJECT(gui->seekbar), "value-changed",
+ G_CALLBACK(seek_cb), gui);
+
+ g_signal_connect(G_OBJECT(tb_open), "clicked",
+ G_CALLBACK(open_cb), gui);
+
- gtk_widget_show_all(GTK_WIDGET(app));
+ gtk_widget_show_all(GTK_WIDGET(gui->appwindow));
+ return gui;
+
+}
- osso_context = osso_initialize(SERVICE_NAME, VERSION, TRUE, NULL);
- if (! osso_context)
- fprintf(stderr, "Could not initialize OSSO.");
- g_timeout_add(500, (GSourceFunc) idle_cb, appdata);
+void
+gui_run() {
+ gtk_main();
- gtk_main();
+}
+
+
+void
+gui_quit() {
+
+ gtk_main_quit();
+
+}
+
+
+void
+gui_set_open_cb(Gui *gui,
+ OPEN_CB,
+ void *userdata) {
+
+ gui->open_cb = open_cb;
+ gui->open_cb_data = userdata;
+
+}
+
+
+void
+gui_set_seek_cb(Gui *gui,
+ SEEK_CB,
+ void *userdata) {
+
+ gui->seek_cb = seek_cb;
+ gui->seek_cb_data = userdata;
+
+}
+
+
+void
+gui_set_volume_cb(Gui *gui,
+ VOLUME_CB,
+ void *userdata) {
+
+ gui->volume_cb = volume_cb;
+ gui->volume_cb_data = userdata;
+
+}
+
+
+void
+gui_set_title(Gui *gui,
+ const char *title,
+ const char *artist,
+ const char *album) {
+
+ char *text;
+
+ text = g_strdup_printf("%s\n<b>%s</b>\n%s", artist, title, album);
+ gtk_label_set_markup(gui->songlabel, text);
+ g_free(text);
+
+}
+
+
+void
+gui_set_time(Gui *gui,
+ int seconds,
+ int total) {
+
+ int mins, secs;
+ char *time;
+
+ gui->seek_position = seconds;
+ hildon_seekbar_set_total_time(HILDON_SEEKBAR(gui->seekbar), total);
+ hildon_seekbar_set_fraction(HILDON_SEEKBAR(gui->seekbar), total);
+ hildon_seekbar_set_position(HILDON_SEEKBAR(gui->seekbar), seconds);
- return 0;
+ secs = seconds % 60;
+ seconds /= 60;
+ mins = seconds;
+ time = g_strdup_printf(" %2d:%02d", mins, secs);
+ gtk_label_set_text(GTK_LABEL(gui->timelabel), time);
+ g_free(time);
}
Added: trunk/maemo/OggPlay/src/gui.h
===================================================================
--- trunk/maemo/OggPlay/src/gui.h 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/src/gui.h 2005-11-21 00:05:41 UTC (rev 10417)
@@ -0,0 +1,79 @@
+/*
+ * Graphical user interface for OggPlay
+ * Copyright (c) 2005 Martin Grimme <martin.grimme at lintegra.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#ifndef GUI_H
+#define GUI_H
+
+#include <hildon-widgets/hildon-app.h>
+#include <hildon-widgets/hildon-appview.h>
+#include <hildon-widgets/hildon-file-chooser-dialog.h>
+#include <hildon-widgets/hildon-seekbar.h>
+#include <hildon-widgets/hildon-vvolumebar.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "stream.h"
+#include "decoder.h"
+
+
+#define OPEN_CB void (*open_cb) (void *userdata, const char *uri)
+#define SEEK_CB void (*seek_cb) (void *userdata, int seconds)
+#define VOLUME_CB void (*volume_cb) (void *userdata, int volume)
+
+
+
+struct _Gui {
+
+ OPEN_CB;
+ void *open_cb_data;
+ SEEK_CB;
+ void *seek_cb_data;
+ VOLUME_CB;
+ void *volume_cb_data;
+
+ int seek_position;
+
+ HildonApp *appwindow;
+ HildonAppView *appview;
+ GtkWidget *volumebar;
+ GtkWidget *songlabel;
+ GtkWidget *seekbar;
+ GtkWidget *timelabel;
+
+};
+typedef struct _Gui Gui;
+
+
+Gui *gui_new();
+void gui_run();
+void gui_quit();
+
+void gui_set_open_cb(Gui *gui, OPEN_CB, void *userdata);
+void gui_set_seek_cb(Gui *gui, SEEK_CB, void *userdata);
+void gui_set_volume_cb(Gui *gui, VOLUME_CB, void *userdata);
+
+void gui_set_title(Gui *gui, const char *title, const char *artist,
+ const char *album);
+void gui_set_time(Gui *gui, int seconds, int total);
+
+
+
+#endif
Added: trunk/maemo/OggPlay/src/main.c
===================================================================
--- trunk/maemo/OggPlay/src/main.c 2005-11-20 19:22:02 UTC (rev 10416)
+++ trunk/maemo/OggPlay/src/main.c 2005-11-21 00:05:41 UTC (rev 10417)
@@ -0,0 +1,134 @@
+/*
+ * Ogg Vorbis player for the Nokia 770
+ * Copyright (c) 2005 Martin Grimme <martin.grimme at lintegra.de>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#include "gui.h"
+#include "decoder.h"
+#include "stream.h"
+#include <libosso.h>
+
+
+#define SERVICE_NAME "oggplay"
+#define VERSION "0.12"
+
+
+struct _AppData {
+
+ Decoder *decoder;
+ Stream *stream;
+ Gui *gui;
+ int current_position;
+
+};
+typedef struct _AppData AppData;
+
+
+
+
+/* callback for updating status information */
+static int
+status_cb(AppData *appdata) {
+
+ int p, t;
+
+ p = decoder_get_position(appdata->decoder);
+ t = decoder_get_total(appdata->decoder);
+ gui_set_time(appdata->gui, p, t);
+
+ return TRUE;
+
+}
+
+
+
+/* callback for opening a file */
+static void
+open_cb(AppData *appdata,
+ const char *uri) {
+
+ /* close old stream */
+ if (appdata->stream)
+ decoder_close_stream(appdata->decoder);
+
+ /* open new stream */
+ appdata->stream = stream_new_from_uri(uri);
+ decoder_open_stream(appdata->decoder, appdata->stream);
+
+ gui_set_title(appdata->gui,
+ appdata->decoder->tag_title,
+ appdata->decoder->tag_artist,
+ appdata->decoder->tag_album);
+
+}
+
+
+/* callback for seeking */
+static void
+seek_cb(AppData *appdata,
+ int seconds) {
+
+ decoder_seek(appdata->decoder, seconds * 1000);
+
+}
+
+
+/* callback for volume changes */
+static void
+volume_cb(AppData *appdata,
+ int volume) {
+
+ decoder_set_volume(appdata->decoder, volume);
+
+}
+
+
+
+int
+main(int argc,
+ char *argv[]) {
+
+ osso_context_t *osso_context;
+ AppData *appdata = g_new(AppData, 1);
+
+
+ gtk_init(&argc, &argv);
+
+ /* register OSSO service */
+ osso_context = osso_initialize(SERVICE_NAME, VERSION, TRUE, NULL);
+ if (! osso_context)
+ fprintf(stderr, "Could not initialize OSSO.");
+
+ appdata->decoder = decoder_new();
+ appdata->stream = NULL;
+
+ /* setup GUI callbacks */
+ appdata->gui = gui_new();
+ gui_set_open_cb(appdata->gui, open_cb, (void *) appdata);
+ gui_set_volume_cb(appdata->gui, volume_cb, (void *) appdata);
+ gui_set_seek_cb(appdata->gui, seek_cb, (void *) appdata);
+
+ g_timeout_add(500, (GSourceFunc) status_cb, appdata);
+
+ gui_run();
+
+
+ return 0;
+
+}
More information about the commits
mailing list