Enlightenment CVS committal

Author  : tsauerbeck
Project : misc
Module  : eplayer

Dir     : misc/eplayer/src


Modified Files:
        Makefile.am callbacks.c eplayer.c eplayer.h interface.c 
        playlist.c playlist.h vorbis.c 
Added Files:
        .cvsignore callbacks.h interface.h mixer.c mixer.h vorbis.h 


Log Message:
ePlayer now loads oggs and directories containing oggs directly again, cleaned up the 
code, added .cvsignore files, filled AUTHORS, tweaked configure.ac
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- Makefile.am 15 Oct 2003 16:54:01 -0000      1.3
+++ Makefile.am 16 Oct 2003 14:54:33 -0000      1.4
@@ -8,10 +8,11 @@
 
 ### I think e_player_HEADER is more correct but not doc'ed.
 eplayer_SOURCES = eplayer.c eplayer.h \
-       interface.c \
-       callbacks.c \
-       vorbis.c \
-       playlist.c playlist.h
+       interface.c interface.h \
+       callbacks.c callbacks.h \
+       vorbis.c vorbis.h \
+       playlist.c playlist.h \
+       mixer.c mixer.h
 
 eplayer_LDADD = -lao -lvorbis -lvorbisfile \
        @ECORE_LIBS@ @EVAS_LIBS@ @EDJE_LIBS@ @ESMART_LIBS@
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/callbacks.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- callbacks.c 15 Oct 2003 16:19:00 -0000      1.2
+++ callbacks.c 16 Oct 2003 14:54:33 -0000      1.3
@@ -1,107 +1,129 @@
+#include <Edje.h>
 #include "eplayer.h"
+#include "mixer.h"
+#include "vorbis.h"
 
-       int             paused = 0;
+static int paused = 1;
 
+void unpause_playback(ePlayer *data, Evas *e, Evas_Object *obj, void *event_info) {
+       /* This ensures we don't call this callback multiple times */
+       if (!paused)
+               return;
 
+#ifdef DEBUG
+       printf("Unpause callback entered\n");
+#endif
+       
+       paused = 0;
 
-
-
-void unpause_playback(player_session *data, Evas *e, Evas_Object *obj, void 
*event_info){
-
-        /* This ensures we don't call this callback multiple times */
-        if (paused == 0)
-                return;
-
-        printf("Unpause callback entered\n");
-        paused = 0;
-
-        data->play_idler = ecore_idler_add(play_loop, data);   /* Start the play 
idler */
-
+       data->play_idler = ecore_idler_add(play_loop, data); /* Start the play idler */
 }
 
+void pause_playback(ePlayer *player, Evas *e, Evas_Object *obj,
+                    void *event_info) {
+       if (paused)
+               return;
+       
+#ifdef DEBUG
+       printf("Pause callback entered\n");
+#endif
+       
+       paused = 1;
 
-
-void pause_playback(player_session *data, Evas *e, Evas_Object *obj, void 
*event_info){
-
-        if (paused == 1)
-                return;
-
-        printf("Pause callback entered\n");
-        paused = 1;
-
-        ecore_idler_del(data->play_idler);     /* Stop the play idler */
-
+       /* Stop the current playing stream */
+       if (player->play_idler) {
+               ecore_idler_del(player->play_idler);
+               player->play_idler = NULL;
+       }
 }
 
-
-void next_file(player_session *data, Evas *e, Evas_Object *obj, void *event_info){
-       printf("DEBUG: Next File Called\n");        /* Report what we're doing for 
debugging purposes */
+void next_file(ePlayer *player, Evas *e, Evas_Object *obj, void *event_info) {
+#ifdef DEBUG
+       printf("DEBUG: Next File Called\n");
+#endif
        
-       ecore_idler_del(data->play_idler);      /* Stop the current playing stream */
+       /* Stop the current playing stream */
+       if (player->play_idler) {
+               ecore_idler_del(player->play_idler);
+               player->play_idler = NULL;
+       }
 
-        data->play_list = data->play_list->next;      /* Get the next list item */
-       printf("DEBUG: Pointer addr is: %d\n", (int)data->play_list);
-
-       if(data->play_list == NULL){
+       /* Get the next list item */
+       player->playlist->cur_item = player->playlist->cur_item->next;
+       
+       if (!player->playlist->cur_item) {
+#ifdef DEBUG
                printf("\n\nDEBUG: Youve hit the end of the list!!! \n\n");
+#endif
 
-               edje_object_part_text_set(data->edje, "artist_name", 
"*****************************");
-                edje_object_part_text_set(data->edje, "album_name", " END OF THE ROAD 
");
-                edje_object_part_text_set(data->edje, "song_name", 
"*****************************");
-                edje_object_part_text_set(data->edje, "time_text", "DAS:EN:DE");
+               edje_object_part_text_set(player->gui.edje, "artist_name", 
"*****************************");
+               edje_object_part_text_set(player->gui.edje, "album_name", " END OF THE 
ROAD ");
+               edje_object_part_text_set(player->gui.edje, "song_name", 
"*****************************");
+               edje_object_part_text_set(player->gui.edje, "time_text", "DAS:EN:DE");
                
                /* Since we hit the end, start from the beginning. */
-               printf("DEBUG: Reseting playlist.  Currently NULL playlist pointer %d, 
reset pointer %d\n", 
-                       (int)data->play_list, (int)data->full_list);
-               data->play_list = data->full_list;
+               player->playlist->cur_item = player->playlist->items;
 
                return;
        } 
+       
+       /* Start the play loop */
+       open_track(player);
+    player->play_idler = ecore_idler_add(play_loop, player);
+}
+
+void prev_file(ePlayer *player, Evas *e, Evas_Object *obj,
+               void *event_info) {
+#ifdef DEBUG
+       printf("DEBUG: Previous File Called\n");
+#endif
+
+       if (player->play_idler) {
+               /* Stop the current playing stream */
+               ecore_idler_del(player->play_idler);
+               player->play_idler = NULL;
+       }
 
-    printf("DEBUG: Next file to play is: %s\n", (char *) data->play_list->data);
-       printf("DEBUG: In next-file, proccessing new file\n");
-       setup_ao();                                     /* If so, seutp the audio out 
path */
-       get_vorbis (data, (PlayListItem *) data->play_list->data); /* Setup the 
intrface with comments, etc */
-    ao_open();                                 /* Open the outbound audio path */
-    data->play_idler = ecore_idler_add(play_loop, data);        /* Start the play 
loop */
-}
-
-
-void prev_file(void *udata, Evas *e, Evas_Object *obj, void *event_info) {
-       player_session *data = udata;
-       printf("DEBUG: Previous File Called\n");        /* Report what we're doing for 
debugging purposes */
-
-       ecore_idler_del(data->play_idler);      /* Stop the current playing stream */
+       /* Get the previous list item */
+       if (!player->playlist->cur_item->prev)
+               return;
 
-       data->play_list = evas_list_prev(data->play_list);      /* Get the previous 
list item */
+       player->playlist->cur_item = player->playlist->cur_item->prev;
 
-       setup_ao(); /* If so, seutp the audio out path */
-       get_vorbis (data, (PlayListItem *) data->play_list->data); /* Setup the 
intrface with comments, etc */
-       ao_open(); /* Open the outbound audio path */
-       data->play_idler = ecore_idler_add(play_loop, data);    /* Start the play loop 
*/
+       /* Start the play loop */
+       open_track (player);
+       player->play_idler = ecore_idler_add(play_loop, player);
 }
 
-void raise_vol(void *udata, Evas_Object *obj, const char *emission, const char *src) {
-       player_session *data = udata;
+void raise_vol(ePlayer *player, Evas_Object *obj, const char *emission,
+               const char *src) {
        int vol;
 
-       vol = read_mixer(data);
+#ifdef DEBUG
+       printf("DEBUG: Raising volume\n");
+#endif
+
+       vol = read_mixer(player);
        set_mixer(vol + 1);
-       read_mixer(data);
+       read_mixer(player);
 }
 
-void lower_vol(void *udata, Evas_Object *obj, const char *emission, const char *src) {
-       player_session *data = udata;
+void lower_vol(ePlayer *player, Evas_Object *obj, const char *emission,
+               const char *src) {
        int vol;
 
-       vol = read_mixer(data);
+#ifdef DEBUG
+       printf("DEBUG: Lowering volume\n");
+#endif
+       
+       vol = read_mixer(player);
        set_mixer(vol - 1);
-       read_mixer(data);
+       read_mixer(player);
 }
 
-void switch_time_display (void *udata, Evas_Object *obj, const char *emission, const 
char *src) {
-       player_session *session = udata;
-
-       session->time_display = !session->time_display;
-       update_time (session);
+void switch_time_display(ePlayer *player, Evas_Object *obj,
+                         const char *emission, const char *src) {
+       player->time_display = !player->time_display;
+       update_time(player);
 }
+
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- eplayer.c   15 Oct 2003 21:02:38 -0000      1.4
+++ eplayer.c   16 Oct 2003 14:54:33 -0000      1.5
@@ -1,67 +1,49 @@
 /* Eplayer OggVorbis Player - Phase 3 - Started 5/6/03 */
 /* Edje Overhaul startnig phase 4 - Started 7/30/03 */
 
+#include <Ecore_Evas.h>
 #include "eplayer.h"
+#include "interface.h"
+#include "vorbis.h"
 
 int main(int argc, const char **argv) {
-       player_session *st_session;
-       PlayList *pl = NULL;
-       int arg_count;
-
-       st_session = malloc(sizeof(player_session)); 
-       memset(st_session, 0, sizeof(player_session)); 
-
-       if( argc == 1){
-               printf("eVorbisPlayer v0.7  - Usage: %s playlist.m3u ...\n\n", 
argv[0]);
-               exit(0);
-       }
+       ePlayer *player;
+       int args;
 
-       /* FIXME: Parse Args, free playlist when shutting ecore down etc */
-       /*for (args = 1; args < argc; args++) {
-               printf("Adding file to playlist: %s\n", argv[args]);
-               
-               st_session->play_list = evas_list_append(st_session->play_list, 
argv[args]);
-       }*/
-       
-       pl = playlist_new();
+       player = malloc(sizeof(ePlayer)); 
+       memset(player, 0, sizeof(ePlayer)); 
 
-       if (!playlist_load_m3u(pl, argv[1], 0)) {
-               printf ("no files loaded!\n");
-               exit (0);
+       if (argc == 1) {
+               printf("eVorbisPlayer v0.7  - Usage: %s playlist.m3u [file.ogg] 
[some/dir] ...\n\n", argv[0]);
+               return 1;
        }
        
-       st_session->play_list = pl->items;
-       
-       arg_count = pl->num;
-       st_session->full_list = st_session->play_list;
-       printf("DEBUG: Int val of playlist pointers is: %d, and fulllist pointer is: 
%d\n\n", 
-               (int)st_session->play_list, (int)st_session->full_list);
-       printf("DEBUG: The list is ready with %d elements in it\n", arg_count);
-
-       {       /* HACKISH HACKISH!!! */
-               Evas_List       * temp_list;
-               temp_list = evas_list_last(st_session->play_list);
-               sprintf(st_session->last_file, "%s", ((PlayListItem *) 
temp_list->data)->file);
-               printf("DEBUG: Last file in playlist is: %s\n", st_session->last_file);
-       }
+       player->playlist = playlist_new();
 
-       printf("Going to play %s\n", ((PlayListItem *) 
st_session->play_list->data)->file);
-       //printf("PCM Volume Level is: %d\n", read_mixer(NULL));
-       
-       /* Done with args */
+       /* Parse Args */
+       for (args = 1; args < argc; args++) {
+#ifdef DEBUG
+               printf("Adding file to playlist: %s\n", argv[args]);
+#endif
+               
+               playlist_load_any(player->playlist, argv[args], args > 1);
+       }
        
-       setup_ecore(st_session);
-       show_playlist (st_session);
+       setup_ecore(player);
+       show_playlist(player);
 
        /*ecore_timer_add (1.5, mixer_refresh, st_session);*/
 
-       setup_ao();
-       get_vorbis (st_session, (PlayListItem *) st_session->play_list->data);
-       ao_open();
-       st_session->play_idler = ecore_idler_add(play_loop, st_session);
+       open_track (player);
 
+#ifdef DEBUG
        printf("DEBUG: Starting main loop\n");
+#endif
+
        ecore_main_loop_begin();
+
+       playlist_free(player->playlist);
+       free(player);
 
        ecore_evas_shutdown();
        ecore_shutdown();
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- eplayer.h   15 Oct 2003 16:19:00 -0000      1.2
+++ eplayer.h   16 Oct 2003 14:54:33 -0000      1.3
@@ -1,16 +1,8 @@
-#include <Ecore_Evas.h>
-#include <Ecore.h>
-#include <Edje.h>
-#include <vorbis/codec.h>
-#include <vorbis/vorbisfile.h>
-#include <ao/ao.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <fcntl.h>
-#include <linux/soundcard.h>
+#ifndef __EPLAYER_H
+#define __EPLAYER_H
 
+#include <Ecore.h>
+#include <config.h>
 #include "playlist.h"
 
 #define        WIDTH   500
@@ -19,42 +11,20 @@
 typedef enum {
        TIME_DISPLAY_LEFT,
        TIME_DISPLAY_ELAPSED
-} Time_Display;
+} TimeDisplay;
 
 typedef struct {
-       Evas *evas;
-       Evas_List *play_list;
-       Evas_List *full_list;
+       PlayList *playlist;
        Ecore_Idler *play_idler;
-       Evas_Object *edje;
-       Evas_Object *playlist_obj; /* container */
-
-       char last_file[1000];
-       Time_Display time_display;
-} player_session;
-
-/* Protos */
-int play_loop(void *udata);
-void unpause_playback();
-void pause_playback();
-
-int update_time(player_session *st_session);
-
-int setup_ao();
-int ao_open();
-int get_vorbis(player_session *st_session, PlayListItem *pli);
-void handle_comments(player_session *st_session);
-void seek_forward();
-void seek_backward();
-void setup_ecore(player_session *st_session);
-void next_file();
-void prev_file();
-int read_mixer (player_session *st_session);
-
-void switch_time_display (void *udata, Evas_Object *obj, const char *emission, const 
char *src);
+       
+       struct {
+               Evas *evas;
+               Evas_Object *edje;
+               Evas_Object *playlist; /* playlist container */
+       } gui;
 
-void raise_vol(void *udata, Evas_Object *obj, const char *emission, const char *src);
-void lower_vol(void *udata, Evas_Object *obj, const char *emission, const char *src);
+       TimeDisplay time_display;
+} ePlayer;
 
-void show_playlist(player_session *session);
+#endif
 
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/interface.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- interface.c 15 Oct 2003 16:19:00 -0000      1.2
+++ interface.c 16 Oct 2003 14:54:33 -0000      1.3
@@ -1,23 +1,35 @@
 #include "eplayer.h"
+#include <Ecore_Evas.h>
 #include <Esmart/container.h>
+#include <Edje.h>
+#include "callbacks.h"
+#include "mixer.h"
+#include "vorbis.h"
 
 /* ECORE/EVAS */
-Ecore_Evas *ee;
+static Ecore_Evas *ee = NULL;
 
 static int app_signal_exit(void *data, int type, void *event) {
+#ifdef DEBUG
        printf("DEBUG: Exit called, shutting down\n");
+#endif
+       
        ecore_main_loop_quit();
        return 1;
 }
 
 static void window_move(Ecore_Evas *ee) {
+#ifdef DEBUG
        printf("DEBUG: Window Move callback entered.\n");
+#endif
 }
 
-void setup_ecore(player_session *st_session) {
+void setup_ecore(ePlayer *player) {
        double edje_w = 0, edje_h = 0;
 
+#ifdef DEBUG
        printf("DEBUG: Starting setup\n");
+#endif
 
        ecore_init();
        ecore_evas_init();
@@ -26,65 +38,79 @@
        ee = ecore_evas_software_x11_new(NULL, 0,  0, 0, WIDTH, HEIGHT);
        ecore_evas_title_set(ee, "eVorbisPlayer");
        ecore_evas_name_class_set(ee, "ecore_test", "test_evas");
-       ecore_evas_borderless_set(ee, 0);
+       ecore_evas_borderless_set(ee, 1);
        ecore_evas_shaped_set(ee, 1);
        ecore_evas_show(ee);
 
        ecore_evas_callback_move_set(ee, window_move);
 
-       st_session->evas = ecore_evas_get(ee);
-       evas_font_path_append(st_session->evas, "../data/");
-       evas_font_path_append(st_session->evas, "../data/fonts/");
+       player->gui.evas = ecore_evas_get(ee);
+       evas_font_path_append(player->gui.evas, "../data/");
+       evas_font_path_append(player->gui.evas, "../data/fonts/");
 
        /* EDJE */
+#ifdef DEBUG
        printf("DEBUG - EDJE: Defining Edje \n");
+#endif
 
-       st_session->edje = edje_object_add(st_session->evas);
-       edje_object_file_set(st_session->edje, "../data/eplayer.eet", "eplayer");
-       evas_object_move(st_session->edje, 0, 0);
-       edje_object_size_min_get(st_session->edje, &edje_w, &edje_h);
-       evas_object_resize(st_session->edje, edje_w, edje_h);
-       evas_object_show(st_session->edje);
+       player->gui.edje = edje_object_add(player->gui.evas);
+       edje_object_file_set(player->gui.edje, "../data/eplayer.eet",
+                            "eplayer");
+       evas_object_move(player->gui.edje, 0, 0);
+       edje_object_size_min_get(player->gui.edje, &edje_w, &edje_h);
+       evas_object_resize(player->gui.edje, edje_w, edje_h);
+       evas_object_show(player->gui.edje);
 
        ecore_evas_resize(ee, (int)edje_w, (int)edje_h);
        ecore_evas_show(ee);
 
        /* add the playlist container */
-       st_session->playlist_obj = e_container_new(st_session->evas);
-       e_container_direction_set(st_session->playlist_obj, 0);
-       e_container_spacing_set(st_session->playlist_obj, 0);
-       e_container_fill_policy_set(st_session->playlist_obj,
+       player->gui.playlist = e_container_new(player->gui.evas);
+       e_container_direction_set(player->gui.playlist, 0);
+       e_container_spacing_set(player->gui.playlist, 0);
+       e_container_fill_policy_set(player->gui.playlist,
                                    CONTAINER_FILL_POLICY_FILL_Y);
        
-       edje_object_part_swallow(st_session->edje, "playlist", 
st_session->playlist_obj);
+       edje_object_part_swallow(player->gui.edje, "playlist",
+                                player->gui.playlist);
 
        /*** Edje Callbacks ***************************/
-       edje_object_signal_callback_add(st_session->edje, "PLAY_PREVIOUS",
-                                       "previous_button", prev_file,
-                                       st_session);
-       edje_object_signal_callback_add(st_session->edje, "PLAY_NEXT", "next_button", 
next_file, st_session);
-
-       edje_object_signal_callback_add(st_session->edje, "SEEK_BACK", 
"seekback_button", seek_backward, st_session);
-       edje_object_signal_callback_add(st_session->edje, "SEEK_FORWARD", 
"seekforward_button", seek_forward, st_session);
-
-       edje_object_signal_callback_add(st_session->edje, "PLAY", "play_button", 
unpause_playback, st_session);
-       edje_object_signal_callback_add(st_session->edje, "PAUSE", "pause_button", 
pause_playback, st_session);
-
-       edje_object_signal_callback_add(st_session->edje, "VOL_INCR", 
"vol_incr_button", raise_vol, st_session);
-       edje_object_signal_callback_add(st_session->edje, "VOL_DECR", 
"vol_decr_button", lower_vol, st_session);
-
-       edje_object_signal_callback_add (st_session->edje, "SWITCH_TIME_DISPLAY", 
"time_text", switch_time_display, st_session);
-
-       printf("DEBUG: Done with Ecore Setup\n");
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "PLAY_PREVIOUS", "previous_button",
+                                       prev_file, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "PLAY_NEXT", "next_button",
+                                       next_file, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "SEEK_BACK", "seekback_button",
+                                       seek_backward, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "SEEK_FORWARD", "seekforward_button",
+                                       seek_forward, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "PLAY", "play_button",
+                                       unpause_playback, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "PAUSE", "pause_button",
+                                       pause_playback, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "VOL_INCR", "vol_incr_button",
+                                       raise_vol, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "VOL_DECR", "vol_decr_button",
+                                       lower_vol, player);
+       edje_object_signal_callback_add(player->gui.edje,
+                                       "SWITCH_TIME_DISPLAY", "time_text",
+                                       switch_time_display, player);
 
        /* Update interface with current PCM Volume Setting */
-       read_mixer(st_session); 
+       read_mixer(player);     
 }
 
-Evas_Object *playlist_column_add(player_session *session,
-                                 double width, double height,
-                                 Container_Alignment align) {
-       Evas_Object *o = e_container_new(session->evas);
+static Evas_Object *playlist_column_add(ePlayer *player,
+                                        double width, double height,
+                                        Container_Alignment align) {
+       Evas_Object *o = e_container_new(player->gui.evas);
        e_container_direction_set(o, 1);
        e_container_spacing_set(o, 0);
        e_container_alignment_set(o, align);
@@ -95,7 +121,7 @@
        return o;
 }
 
-void show_playlist(player_session *session) {
+void show_playlist(ePlayer *player) {
        Evas_Object *o, *col[2];
        Evas_List *l;
        char *title, len[32];
@@ -103,7 +129,7 @@
        double w = 0, h = 0;
        int i, added_cols = 0, duration;
 
-       for (l = session->full_list; l; l = l->next) {
+       for (l = player->playlist->items; l; l = l->next) {
                /* get the information we want to display */
                title = ((PlayListItem *) l->data)->title;
                duration = ((PlayListItem *) l->data)->duration;
@@ -113,7 +139,7 @@
                
                /* add the title/length items to the container */
                for (i = 0; i < 2; i++) {
-                       o = edje_object_add(session->evas);
+                       o = edje_object_add(player->gui.evas);
                        edje_object_file_set(o, "../data/eplayer.eet", name[i]);
                        edje_object_part_text_set(o, "text", i ? len : title);
                        edje_object_size_min_get(o, &w, &h);
@@ -124,11 +150,11 @@
                         * the edje object first, to get the width/height
                         */
                        if (!added_cols) {
-                               evas_object_geometry_get(session->playlist_obj, NULL, 
NULL, NULL, &h);
-                               col[i] = playlist_column_add(session, w, h,
+                               evas_object_geometry_get(player->gui.playlist, NULL, 
NULL, NULL, &h);
+                               col[i] = playlist_column_add(player, w, h,
                                                             i ? CONTAINER_ALIGN_RIGHT
                                                             : CONTAINER_ALIGN_LEFT);
-                               e_container_element_append(session->playlist_obj, 
col[i]);
+                               e_container_element_append(player->gui.playlist, 
col[i]);
                        }
 
                        e_container_element_append(col[i], o);
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- playlist.c  15 Oct 2003 16:37:29 -0000      1.1
+++ playlist.c  16 Oct 2003 14:54:33 -0000      1.2
@@ -8,9 +8,10 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <config.h>
 #include "playlist.h"
 
-static int dir_exists (const char *dir) {
+static int is_dir (const char *dir) {
        struct stat st;
 
        if (stat(dir, &st) != 0)
@@ -93,6 +94,7 @@
        PlayListItem *pli;
        FILE *fp;
        OggVorbis_File vf = {0};
+       vorbis_info *info;
 
        if (!(fp = fopen(file, "rb")) || ov_open(fp, &vf, NULL, 0))
                return NULL;
@@ -101,12 +103,18 @@
                return NULL;
 
        memset(pli, 0, sizeof(PlayListItem));
+       snprintf(pli->file, sizeof(pli->file), "%s", file);
 
        /* read the vorbis comments etc */
-       snprintf(pli->file, sizeof(pli->file), "%s", file);
-       pli->duration = ov_time_total(&vf, -1);
        playlist_item_read_comments(pli, ov_comment(&vf, -1));
 
+       /* get bitrate and number of channels */
+       info = ov_info(&vf, -1);
+       pli->channels = info->channels;
+       pli->rate = info->rate;
+       
+       pli->duration = ov_time_total(&vf, -1);
+
        ov_clear(&vf);  /* ov_clear closes the file, too */
 
        return pli;
@@ -148,8 +156,8 @@
                return;
        
        while (pl->items) {
-               pl->items = evas_list_remove(pl->items, pl->items->data);
                playlist_item_free((PlayListItem *) pl->items->data);
+               pl->items = evas_list_remove(pl->items, pl->items->data);
        }
 }
 
@@ -184,6 +192,9 @@
 
        pl->items = evas_list_append(pl->items, pli);
 
+       if (!append)
+               pl->cur_item = pl->items;
+
        return 1;
 }
 
@@ -213,7 +224,7 @@
        
        /* real entries: load directories recursively */
        while ((entry = readdir(dir))) {
-               if (dir_exists(entry->d_name))
+               if (is_dir(entry->d_name))
                        playlist_load_dir(pl, entry->d_name, 1);
                else if ((pli = playlist_item_new(entry->d_name)))
                        tmp = evas_list_prepend(tmp, pli);
@@ -223,6 +234,7 @@
 
        if (!append) {
                pl->items = evas_list_reverse(tmp);
+               pl->cur_item = pl->items;
                return 1;
        }
        
@@ -231,7 +243,7 @@
        pl->items->last->next = tmp;
        tmp->prev = pl->items->last;
        pl->items->last = tmp->last;
-       
+
        return 1;
 }
 
@@ -244,6 +256,7 @@
  */
 int playlist_load_m3u(PlayList *pl, const char *file, int append) {
        PlayListItem *pli = NULL;
+       Evas_List *tmp = NULL;
        FILE *fp;
        char buf[1024], path[PATH_MAX + 1], *dir, *ptr;
 
@@ -267,7 +280,7 @@
                }
 
                if ((pli = playlist_item_new(ptr))) {
-                       pl->items = evas_list_prepend(pl->items, pli);
+                       tmp = evas_list_prepend(tmp, pli);
                        pl->num++;
                }
        }
@@ -275,8 +288,44 @@
        fclose(fp);
        free(dir);
 
-       if (pl->items)
-               pl->items = evas_list_reverse(pl->items);
+       if (!append) {
+               pl->items = evas_list_reverse(tmp);
+               pl->cur_item = pl->items;
+               return 1;
+       }
 
+       if (!pl->items)
+               pl->items = evas_list_reverse(tmp);
+       else { /* append the temporary list */
+               tmp = evas_list_reverse(tmp);
+               pl->items->last->next = tmp;
+               tmp->prev = pl->items->last;
+               pl->items->last = tmp->last;
+       }
+       
        return 1;
+}
+
+/**
+ * Add a M3U file, an Ogg file or a directory to a PlayList.
+ *
+ * @param pl
+ * @param path
+ * @param append If 0, the old entries will be overwritten.
+ */
+int playlist_load_any(PlayList *pl, const char *path, int append) {
+       char *ptr = NULL;
+       
+       if (is_dir(path))
+               return playlist_load_dir(pl, path, append);
+
+       /* FIXME we check for m3u or ogg using the suffix :/ */
+       ptr = (char *) &path[strlen(path) - 3];
+
+       if (!strcasecmp(ptr, "ogg"))
+               return playlist_load_file(pl, path, append);
+       else if (!strcasecmp(ptr, "m3u"))
+               return playlist_load_m3u(pl, path, append);
+       else
+               return 0;
 }
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- playlist.h  15 Oct 2003 16:37:29 -0000      1.1
+++ playlist.h  16 Oct 2003 14:54:33 -0000      1.2
@@ -18,11 +18,15 @@
        char title[PLAYLIST_ITEM_COMMENT_LEN];
        char album[PLAYLIST_ITEM_COMMENT_LEN];
        double duration;
+
+       int channels; /* number of channels */
+       long rate; /* bitrate */
 } PlayListItem;
 
 typedef struct {
        int num; /* number of entries */
        Evas_List *items;
+       Evas_List *cur_item;
 } PlayList;
 
 PlayList *playlist_new();
@@ -31,6 +35,7 @@
 int playlist_load_file(PlayList *pl, const char *file, int append);
 int playlist_load_dir(PlayList *pl, const char *dir, int append);
 int playlist_load_m3u(PlayList *pl, const char *file, int append);
+int playlist_load_any(PlayList *pl, const char *path, int append);
 
 void playlist_remove_all(PlayList *pl);
 
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/vorbis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- vorbis.c    15 Oct 2003 16:19:00 -0000      1.2
+++ vorbis.c    16 Oct 2003 14:54:33 -0000      1.3
@@ -1,318 +1,146 @@
+#include <Edje.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+#include <ao/ao.h>
 #include <sys/ioctl.h>
 #include "eplayer.h"
+#include "vorbis.h"
 
-       int     eof = 0;
-       int     endian;
-        int    time_left;
-
-        /* AUDIO BUFFER */
-        char            pcmout[16384];   
-
-        /* XIPH AO */
-        ao_device *     device;
-        ao_sample_format format;
-        int             default_driver;
-        int             dev_type;
-
-        /* OggVorbis */
-        OggVorbis_File  vf;
-        int             current_section;
-        vorbis_info *   info;
-        vorbis_comment * comment;
-
+ao_device *device = NULL;
+ao_sample_format format = {0};
+OggVorbis_File current_track = {0};
 
 /* Main Play Loop */
 int play_loop(void *udata) {
-       player_session *st_session = udata;
-
-
-        /* printf("DEBUG: In play loop function \n"); */
-
-    long buff_len = ov_read(&vf, pcmout, sizeof(pcmout), endian, 2, 1, 
&current_section);
+       ePlayer *player = udata;
+       long buff_len;
+       unsigned char pcmout[16384];
+       int big_endian = 0;
+       
+#ifdef WORDS_BIGENDIAN
+       big_endian = 1;
+#endif
+       
+       buff_len = ov_read(&current_track, pcmout, sizeof(pcmout), big_endian,
+                          2, 1, NULL);
 
-    if (buff_len)
+    if (buff_len) {
                ao_play (device, pcmout, buff_len);
-       else {
-               printf("DEBUG: Hit EOF.  Idle timer should be removed now\n");
-               /* This sucks ass, but look for another file here....... THIS IS A BAD 
THING! */
-               st_session->play_list = evas_list_next(st_session->play_list);
-        setup_ao();
-        get_vorbis (st_session, (PlayListItem *) st_session->play_list->data);
-        ao_open();
-        st_session->play_idler = ecore_idler_add(play_loop, st_session);
-               
-               return 0; /* Stream is empty, EOF reached, leave func and remove timer 
*/
+               update_time(player);
+               return 1;
        }
-
-       update_time(st_session);
+               
+       /* This sucks ass, but look for another file here....... THIS IS A BAD THING! 
*/
+       player->playlist->cur_item = player->playlist->cur_item->next;
+       open_track(player);
 
        return 1;
 }
 
-int update_time(player_session *st_session) {
-       int  cur_time;
+int update_time(ePlayer *player) {
+       static int old_time = -1;
+       int cur_time;
        char time[9];
 
-       if (st_session->time_display == TIME_DISPLAY_LEFT)
-               cur_time = ov_time_tell (&vf);
+       if (player->time_display == TIME_DISPLAY_LEFT)
+               cur_time = ov_time_tell(&current_track);
        else
-               cur_time = ov_time_total (&vf, -1) - ov_time_tell (&vf);
+               cur_time = ov_time_total(&current_track, -1) -
+                          ov_time_tell(&current_track);
 
-       if (cur_time == time_left)
+       if (cur_time == old_time) /* value didn't change, so update */
                return 1;
 
-       time_left = cur_time;
+       old_time = cur_time;
 
-       /* printf("DEBUG: Updating time\n"); */
-
-       if (st_session->time_display == TIME_DISPLAY_LEFT)
-               snprintf (time, sizeof(time), "%d:%02d", (time_left/60), 
(time_left%60));
+       if (player->time_display == TIME_DISPLAY_LEFT)
+               snprintf(time, sizeof(time), "%d:%02d",
+                        (cur_time / 60), (cur_time % 60));
        else
-               snprintf (time, sizeof(time), "-%d:%02d", (time_left/60), 
(time_left%60));
+               snprintf(time, sizeof(time), "-%d:%02d",
+                        (cur_time / 60), (cur_time % 60));
 
-       edje_object_part_text_set(st_session->edje, "time_text", time);
-       evas_render(st_session->evas);
+       edje_object_part_text_set(player->gui.edje, "time_text", time);
+       evas_render(player->gui.evas);
 
        return 1;
 }
 
-int setup_ao(){
-
+static int setup_ao(PlayListItem *current) {
+       ao_info *driver_info;
+       int default_driver;
+       
        ao_initialize();
        default_driver = ao_default_driver_id();
-       printf("AO DEBUG: Driver is %d\n", default_driver);
-
-        return 1;
 
-}
-
-int ao_open(){
-
-       ao_info * driver_info;
+#ifdef DEBUG
+       printf("AO DEBUG: Driver is %d\n", default_driver);
+#endif
 
        driver_info = ao_driver_info(default_driver);   
 
        format.bits = 16;
-        format.channels = info->channels;
-        format.rate = info->rate;
-        format.byte_format = AO_FMT_NATIVE;
-
-       printf("AO DEBUG: %d Channels at %d Hz, in %d bit words\n", format.channels, 
format.rate, format.bits);
+       format.channels = current->channels;
+       format.rate = current->rate;
+       format.byte_format = AO_FMT_NATIVE;
+
+#ifdef DEBUG
+       printf("AO DEBUG: %d Channels at %d Hz, in %d bit words\n",
+              format.channels, format.rate, format.bits);
        printf("AO DEBUG: Audio Device: %s\n", driver_info->name);
+#endif
        
-       endian = ao_is_big_endian();
-
-       printf("AO DEBUG: Endianness is %d\n", endian);
-
-        device = ao_open_live(default_driver, &format, NULL);
-                if (device == NULL) {
-                  fprintf(stderr, "Error opening device.\n");
-                  return 0;
-                }
-
-  return 1;
-}
-
-int get_vorbis(player_session *st_session, PlayListItem *pli) {
-       FILE *fp;
-
-       if (!(fp = fopen (pli->file, "rb")) || ov_open(fp, &vf, NULL, 0)) {
-               fprintf (stderr, "ERROR: Can't open file '%s'\n", pli->file);
+       if (!(device = ao_open_live(default_driver, &format, NULL))) {
+               fprintf(stderr, "Error opening device.\n");
                return 0;
        }
 
-    printf("DEBUG: Opened file %s\n", pli->file);
-
-       info = ov_info(&vf, -1);
-       comment = ov_comment(&vf, -1);
-
-       printf("Going to parse comments\n");
-       handle_comments(st_session);
-
        return 1;
 }
 
-/* Use VorbisFile for comment handling */
-void handle_comments(player_session *st_session){
-
-        int i;
-        int  track_len;
-        char time[9];
-
-        track_len = (int) ov_time_total(&vf, -1);
-        time_left = track_len;
-        sprintf(time, "-%d:%02d", (track_len/60), (track_len%60));
-
-        //evas_object_text_text_set(st_session->time_text, time);
-       edje_object_part_text_set(st_session->edje, "time_text", time);
-
-
-
-        printf("DEBUG: There are %d comments\n", comment->comments);
-
-  for(i = 0; i < comment->comments; i++){
-
-       /* Use strncasecmp instead - or strcasecmp */
-        if(strstr(comment->user_comments[i],"title=")){
-                char * title;
-
-                title = strchr(comment->user_comments[i], '=');
-                if (title)
-                  title = strdup(title + 1);
-
-
-                  //evas_object_text_text_set(st_session->title_text, title);
-               edje_object_part_text_set(st_session->edje, "song_name", title);
-
-        } else if (strstr(comment->user_comments[i],"artist=")){
-                char * artist;
-
-                artist = strchr(comment->user_comments[i], '=');
-                if (artist)
-                  artist = strdup(artist + 1);
-
-                  //evas_object_text_text_set(st_session->artist_text, artist );
-               edje_object_part_text_set(st_session->edje, "artist_name", artist);
-
-
-        } else if (strstr(comment->user_comments[i],"album=")){
-                char * album;
-
-                album = strchr(comment->user_comments[i], '=');
-                if (album)
-                  album = strdup(album + 1);
-
-                //evas_object_text_text_set(st_session->album_text, album);
-               edje_object_part_text_set(st_session->edje, "album_name", album);
-        }
-  }
+void open_track(ePlayer *player) {
+       PlayListItem *pli = player->playlist->cur_item->data;
+       FILE *fp;
 
+       ov_clear(&current_track);
 
-}
+       if (!(fp = fopen (pli->file, "rb"))
+           || ov_open(fp, &current_track, NULL, 0)) {
+               fprintf (stderr, "ERROR: Can't open file '%s'\n", pli->file);
+               return;
+       }
 
-/* More Bite Size Functions for comments */
+       edje_object_part_text_set(player->gui.edje, "song_name", pli->title);
+       edje_object_part_text_set(player->gui.edje, "artist_name", pli->artist);
+       edje_object_part_text_set(player->gui.edje, "album_name", pli->album);
 
-char *get_track_name (char *file) {
-       /* Shit.......... I've gotta think about this...... */  
-       return NULL;
+       setup_ao (pli);
 }
 
-
-void seek_forward(){
-        double  cur_time;
-
+void seek_forward(void *udata, Evas_Object *obj,
+                  const char *emission, const char *src) {
        /* We don't care if you seek past the file, the play look will catch EOF and 
play next file */
-
+#ifdef DEBUG
        printf("DEBUG: Seeking forward\n");
+#endif
 
-        cur_time =  ov_time_tell(&vf);
-        ov_time_seek(&vf, cur_time + 5);
+       ov_time_seek(&current_track, ov_time_tell(&current_track) + 5);
 }
 
-void seek_backward(){
-        double  cur_time;//, total_time;
-
-        cur_time =  ov_time_tell(&vf);
+void seek_backward(void *udata, Evas_Object *obj,
+                   const char *emission, const char *src) {
+       double cur_time = ov_time_tell(&current_track);
        
        /* Lets not seek backward if there isn't a point */
-       if(cur_time < 6) {
+       if (cur_time < 6) {
                printf("You arent even 5 secs into the stream!\n");
                return;
        } 
 
-       //printf("DEBUG: Seeking backward - Current Pos: %d\n", (int)cur_time);
-        ov_time_seek(&vf, cur_time - 5);
-}
-
-
-/************ STOLEN FROM MOC (Music on CLI) *********************/
-/* Get PCM volume, return -1 on error */
-int read_mixer (player_session *st_session) {
-        int vol;
-       int mixer_fd;
-
-       printf("DEBUG: Reading mixer\n");
-
-       mixer_fd = open ("/dev/mixer", O_RDWR);
-
-        if (mixer_fd == -1) {
-                open ("/dev/mixer0", O_RDWR);
-        }
-        if (mixer_fd == -1) {
-                printf("MIXER: Can't open mixer device\n");
-               return 0;
-        }
-
-        if (mixer_fd != -1) {
-                if (ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_PCM), &vol) == -1)
-                        printf("MIXER: Can't read from mixer\n");
-                else {
-                       int return_val;
-                        /* Average between left and right */
-                        return_val =  ((vol & 0xFF) + ((vol >> 8) & 0xFF)) / 2;
-                       printf("MIXER: Returning value: %d\n", return_val);
-                       close(mixer_fd);
+#ifdef DEBUG
+       printf("DEBUG: Seeking backward - Current Pos: %lf\n", cur_time);
+#endif
        
-
-       /* Update the display with the volume level */
-       {
-
-                char vol_str[3];
-
-                sprintf(vol_str, "%d", (int)return_val);
-                printf("DEBUG: Setting the mixer vol: %s\n", vol_str);
-
-                edje_object_part_text_set(st_session->edje, "vol_display_text",  
vol_str);     
-       }
-/*
-
-               if(st_session->edje) {
-                       if(return_val > 99) 
-                               return_val == 99;
-                       if(return_val < 1) 
-                               edje_object_part_text_set(st_session->edje, 
"vol_display_text", "--");
-                       if(return_val < 10) 
-                               sprintf(return_val, "0%s", (int)return_val);
-
-                       edje_object_part_text_set(st_session->edje, 
"vol_display_text", return_val);
-               }
-*/
-                       return return_val;
-                }
-        }
-
-        return -1;
-}
-
-/* Set PCM volume */
-void set_mixer(int vol){
-
-        int mixer_fd;
-
-        printf("DEBUG: Setting mixer\n");
-
-        mixer_fd = open ("/dev/mixer", O_RDWR);
-
-        if (mixer_fd == -1) 
-                mixer_fd = open ("/dev/mixer0", O_RDWR);
-
-        if (mixer_fd == -1) {
-                printf("MIXER: Can't open mixer device\n");
-                return;
-        }
-
-
-        if (mixer_fd != -1) {
-                if (vol > 100)
-                        vol = 100;
-                else if (vol < 0)
-                        vol = 0;
-
-                vol = vol | (vol << 8);
-                if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_PCM), &vol) == -1)
-                        printf("DEBUG: Can't set mixer\n");
-        }
-       close(mixer_fd);
+       ov_time_seek(&current_track, cur_time - 5);
 }
-/********** END THEFT *********************************************/
 




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to