From 0358e19702ca5a39b5609b7af126111a846df235 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 7 Jul 2010 20:03:13 +0200 Subject: moved old timeline code to gtkui --- Makefile.am | 1 - plugins/gtkui/timeline.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/gtkui/timeline.h | 52 ++++++++++++++++++++ timeline.c | 122 ----------------------------------------------- timeline.h | 52 -------------------- 5 files changed, 174 insertions(+), 175 deletions(-) create mode 100644 plugins/gtkui/timeline.c create mode 100644 plugins/gtkui/timeline.h delete mode 100644 timeline.c delete mode 100644 timeline.h diff --git a/Makefile.am b/Makefile.am index 14682d92..feb500c6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,7 +29,6 @@ deadbeef_SOURCES =\ junklib.h junklib.c utf8.c utf8.h u8_lc_map.h\ optmath.h\ vfs.c vfs.h vfs_stdio.c\ - timeline.c timeline.h\ md5/md5.c md5/md5.h\ metacache.c metacache.h\ gettext.h diff --git a/plugins/gtkui/timeline.c b/plugins/gtkui/timeline.c new file mode 100644 index 00000000..4543f6c6 --- /dev/null +++ b/plugins/gtkui/timeline.c @@ -0,0 +1,122 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko + + 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. +*/ +#include +#include +#include +#include +#include +#include +#include +#include "timeline.h" +#include "threading.h" + +timeline_t * +timeline_create (void) { + timeline_t *tl = malloc (sizeof (timeline_t)); + memset (tl, 0, sizeof (timeline_t)); + return tl; +} + +void +timeline_free (timeline_t *tl, int wait) { + if (tl->tid && wait) { + int tid = tl->tid; + tl->destroy = 1; + thread_join (tid); + } + else { + tl->destroy = 1; + } +} + +void +timeline_init (timeline_t *tl, float seconds, float fps, int (*callback)(float _progress, int _last, void *_ctx), void *ctx) { + tl->fps = fps; + tl->duration = seconds; + tl->progress = 0; + tl->callback = callback; + tl->callback_ctx = ctx; + tl->destroy = 0; + tl->stop = 0; +} + +void +timeline_stop (timeline_t *tl, int wait) { + int tid = tl->tid; + if (tid) { + tl->stop = 1; + if (wait) { + thread_join (tid); + } + } +} + +void +timeline_thread_func (void *ctx) { + printf ("timeline thread started\n"); + timeline_t *tl = (timeline_t *)ctx; + + for (;;) { + if (tl->stop || tl->destroy) { + tl->callback (1, 1, tl->callback_ctx); + break; + } + struct timeval tm; + gettimeofday (&tm, NULL); + float dt = (tm.tv_sec - tl->time.tv_sec) + (tm.tv_usec - tl->time.tv_usec) / 1000000.0; + float t = tl->progress; + tl->progress += dt; + memcpy (&tl->time, &tm, sizeof (tm)); + if (t > tl->duration) { + tl->callback (1, 1, tl->callback_ctx); + break; + } + else { + if (tl->callback (t/tl->duration, 0, tl->callback_ctx) < 0) { + break; + } + } + printf ("progress: %f\n", tl->progress); + + // sleep until next frame + usleep (1000000 / tl->fps); + } + tl->tid = 0; + if (tl->destroy) { + printf ("timeline %p destroyed\n", tl); + free (tl); + } + printf ("timeline %p thread terminated\n", tl); +} + + +void +timeline_start (timeline_t *tl) { + gettimeofday (&tl->time, NULL); + tl->progress = 0; + tl->stop = 0; + tl->destroy = 0; + if (!tl->tid) { + tl->tid = thread_start (timeline_thread_func, tl); + } + else { + printf ("reusing existing thread\n"); + } +} + diff --git a/plugins/gtkui/timeline.h b/plugins/gtkui/timeline.h new file mode 100644 index 00000000..5325288e --- /dev/null +++ b/plugins/gtkui/timeline.h @@ -0,0 +1,52 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko + + 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. +*/ +#ifndef __TIMELINE_H +#define __TIMELINE_H + +#include + +typedef struct { + float fps; + float duration; + float progress; + struct timeval time; + intptr_t tid; + int stop; + int destroy; + int (*callback)(float _progress, int _last, void *_ctx); + void *callback_ctx; +} timeline_t; + +// callback must return 0 to continue, or -1 to abort +timeline_t * +timeline_create (void); + +void +timeline_free (timeline_t *timeline, int wait); + +void +timeline_stop (timeline_t *tl, int wait); + +void +timeline_init (timeline_t *timeline, float seconds, float fps, int (*callback)(float _progress, int _last, void *_ctx), void *ctx); + +void +timeline_start (timeline_t *timeline); + +#endif // __TIMELINE_H diff --git a/timeline.c b/timeline.c deleted file mode 100644 index 4543f6c6..00000000 --- a/timeline.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2010 Alexey Yakovenko - - 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. -*/ -#include -#include -#include -#include -#include -#include -#include -#include "timeline.h" -#include "threading.h" - -timeline_t * -timeline_create (void) { - timeline_t *tl = malloc (sizeof (timeline_t)); - memset (tl, 0, sizeof (timeline_t)); - return tl; -} - -void -timeline_free (timeline_t *tl, int wait) { - if (tl->tid && wait) { - int tid = tl->tid; - tl->destroy = 1; - thread_join (tid); - } - else { - tl->destroy = 1; - } -} - -void -timeline_init (timeline_t *tl, float seconds, float fps, int (*callback)(float _progress, int _last, void *_ctx), void *ctx) { - tl->fps = fps; - tl->duration = seconds; - tl->progress = 0; - tl->callback = callback; - tl->callback_ctx = ctx; - tl->destroy = 0; - tl->stop = 0; -} - -void -timeline_stop (timeline_t *tl, int wait) { - int tid = tl->tid; - if (tid) { - tl->stop = 1; - if (wait) { - thread_join (tid); - } - } -} - -void -timeline_thread_func (void *ctx) { - printf ("timeline thread started\n"); - timeline_t *tl = (timeline_t *)ctx; - - for (;;) { - if (tl->stop || tl->destroy) { - tl->callback (1, 1, tl->callback_ctx); - break; - } - struct timeval tm; - gettimeofday (&tm, NULL); - float dt = (tm.tv_sec - tl->time.tv_sec) + (tm.tv_usec - tl->time.tv_usec) / 1000000.0; - float t = tl->progress; - tl->progress += dt; - memcpy (&tl->time, &tm, sizeof (tm)); - if (t > tl->duration) { - tl->callback (1, 1, tl->callback_ctx); - break; - } - else { - if (tl->callback (t/tl->duration, 0, tl->callback_ctx) < 0) { - break; - } - } - printf ("progress: %f\n", tl->progress); - - // sleep until next frame - usleep (1000000 / tl->fps); - } - tl->tid = 0; - if (tl->destroy) { - printf ("timeline %p destroyed\n", tl); - free (tl); - } - printf ("timeline %p thread terminated\n", tl); -} - - -void -timeline_start (timeline_t *tl) { - gettimeofday (&tl->time, NULL); - tl->progress = 0; - tl->stop = 0; - tl->destroy = 0; - if (!tl->tid) { - tl->tid = thread_start (timeline_thread_func, tl); - } - else { - printf ("reusing existing thread\n"); - } -} - diff --git a/timeline.h b/timeline.h deleted file mode 100644 index 5325288e..00000000 --- a/timeline.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2010 Alexey Yakovenko - - 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. -*/ -#ifndef __TIMELINE_H -#define __TIMELINE_H - -#include - -typedef struct { - float fps; - float duration; - float progress; - struct timeval time; - intptr_t tid; - int stop; - int destroy; - int (*callback)(float _progress, int _last, void *_ctx); - void *callback_ctx; -} timeline_t; - -// callback must return 0 to continue, or -1 to abort -timeline_t * -timeline_create (void); - -void -timeline_free (timeline_t *timeline, int wait); - -void -timeline_stop (timeline_t *tl, int wait); - -void -timeline_init (timeline_t *timeline, float seconds, float fps, int (*callback)(float _progress, int _last, void *_ctx), void *ctx); - -void -timeline_start (timeline_t *timeline); - -#endif // __TIMELINE_H -- cgit v1.2.3