diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | deadbeef.h | 8 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | playlist.c | 92 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/ddblistview.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 5 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 5 | ||||
-rw-r--r-- | plugins/gtkui/mainplaylist.c | 8 | ||||
-rw-r--r-- | plugins/gtkui/plcommon.c | 146 | ||||
-rw-r--r-- | plugins/gtkui/search.c | 8 | ||||
-rw-r--r-- | session.c | 291 | ||||
-rw-r--r-- | session.h | 27 |
13 files changed, 174 insertions, 427 deletions
diff --git a/Makefile.am b/Makefile.am index 2b00eebf..e5d0c09c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,7 +14,6 @@ deadbeef_SOURCES =\ playback.h\ threading_pthread.c threading.h\ volume.c volume.h\ - session.h session.c \ junklib.h junklib.c utf8.c utf8.h\ optmath.h\ vfs.c vfs.h vfs_stdio.c\ @@ -235,15 +235,10 @@ enum { }; // preset columns, working using IDs +// DON'T add new ids in range 2-7, they are reserved for backwards compatibility enum pl_column_t { DB_COLUMN_FILENUMBER = 0, DB_COLUMN_PLAYING = 1, - DB_COLUMN_ARTIST_ALBUM = 2, - DB_COLUMN_ARTIST = 3, - DB_COLUMN_ALBUM = 4, - DB_COLUMN_TITLE = 5, - DB_COLUMN_DURATION = 6, - DB_COLUMN_TRACK = 7, DB_COLUMN_ALBUM_ART = 8, DB_COLUMN_ID_MAX }; @@ -400,6 +395,7 @@ typedef struct { %a artist %t title %b album + %B band / album artist %n track %l length (duration) %y year @@ -49,7 +49,6 @@ #include "streamer.h" #include "conf.h" #include "volume.h" -#include "session.h" #include "plugins.h" #ifndef PATH_MAX @@ -608,13 +607,6 @@ main (int argc, char *argv[]) { // start all subsystems volume_set_db (conf_get_float ("playback.volume", 0)); plug_trigger_event_playlistchanged (); -// this is old code left for backwards compatibility - { - char sessfile[1024]; // $HOME/.config/deadbeef/session - if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) { - session_load (sessfile); - } - } streamer_init (); @@ -2242,18 +2242,6 @@ pl_format_time (float t, char *dur, int size) { } } -// following helpers must be called from within pl_lock/unlock block -static const char * -pl_get_meta_cached (playItem_t *it, const char *meta, const char *ret, const char *def) { - if (!ret) { - ret = pl_find_meta (it, meta); - if (!ret) { - ret = def; - } - } - return ret; -} - static const char * pl_format_duration (playItem_t *it, const char *ret, char *dur, int size) { if (ret) { @@ -2279,8 +2267,7 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char char elp[50]; char fno[50]; char tags[200]; - const char *artist = NULL; - const char *album = NULL; + char artistalbum[1024]; const char *track = NULL; const char *title = NULL; const char *duration = NULL; @@ -2307,42 +2294,6 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char case DB_COLUMN_PLAYING: UNLOCK; return pl_format_item_queue (it, s, size); - case DB_COLUMN_ARTIST_ALBUM: - { - char artistalbum[1024]; - artist = pl_get_meta_cached (it, "artist", artist, "Unknown artist"); - album = pl_get_meta_cached (it, "album", album, "Unknown album"); - snprintf (artistalbum, sizeof (artistalbum), "%s - %s", artist, album); - text = artistalbum; - } - break; - case DB_COLUMN_ARTIST: - text = (artist = pl_get_meta_cached (it, "artist", artist, "Unknown artist")); - break; - case DB_COLUMN_ALBUM: - text = (album = pl_get_meta_cached (it, "album", artist, "Unknown album")); - break; - case DB_COLUMN_TITLE: - text = (title = pl_get_meta_cached (it, "title", artist, "?")); - break; - case DB_COLUMN_DURATION: - text = (duration = pl_format_duration (it, duration, dur, sizeof (dur))); - break; - case DB_COLUMN_TRACK: - track = pl_get_meta_cached (it, "track", track, ""); - text = track; -#if 0 // kept for tracing purposes - char ftrk[50]; - if (isdigit (track[0])) { - snprintf (ftrk, sizeof (ftrk), "%03d (%s)", atoi (track), track); - text = ftrk; - } - else { - snprintf (ftrk, sizeof (ftrk), "-1 (%s)", track); - text = ftrk; - } -#endif - break; } if (text) { strncpy (s, text, size); @@ -2373,28 +2324,40 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char break; } else if (*fmt == 'a') { - meta = (artist = pl_get_meta_cached (it, "artist", artist, "Unknown artist")); + meta = pl_find_meta (it, "artist"); + if (!meta) { + meta = "Unknown artist"; + } } else if (*fmt == 't') { - meta = (title = pl_get_meta_cached (it, "title", title, "?")); + meta = pl_find_meta (it, "title"); + if (!meta) { + meta = "?"; + } } else if (*fmt == 'b') { - meta = (album = pl_get_meta_cached (it, "album", album, "Unknown album")); + meta = pl_find_meta (it, "album"); + if (!meta) { + meta = "Unknown album"; + } + } + else if (*fmt == 'B') { + meta = pl_find_meta (it, "band"); } else if (*fmt == 'n') { - meta = (track = pl_get_meta_cached (it, "track", track, "")); + meta = pl_find_meta (it, "track"); } else if (*fmt == 'y') { - meta = (year = pl_get_meta_cached (it, "year", year, "")); + meta = pl_find_meta (it, "year"); } else if (*fmt == 'g') { - meta = (genre = pl_get_meta_cached (it, "genre", genre, "")); + meta = pl_find_meta (it, "genre"); } else if (*fmt == 'c') { - meta = (comment = pl_get_meta_cached (it, "comment", comment, "")); + meta = pl_find_meta (it, "comment"); } else if (*fmt == 'r') { - meta = (copyright = pl_get_meta_cached (it, "copyright", copyright, "")); + meta = pl_find_meta (it, "copyright"); } else if (*fmt == 'l') { const char *value = (duration = pl_format_duration (it, duration, dur, sizeof (dur))); @@ -2502,6 +2465,15 @@ pl_sort (int iter, int id, const char *format, int ascending) { } GLOBAL_LOCK; int sorted = 0; + int is_duration = 0; + int is_track = 0; + if (format && id == -1 && !strcmp (format, "%l")) { + is_duration = 1; + } + if (format && id == -1 && !strcmp (format, "%n")) { + is_track = 1; + } + do { sorted = 1; playItem_t *it; @@ -2511,10 +2483,10 @@ pl_sort (int iter, int id, const char *format, int ascending) { break; } int cmp; - if (id == DB_COLUMN_DURATION) { + if (is_duration) { cmp = ascending ? next->_duration > it->_duration : it->_duration > next->_duration; } - else if (id == DB_COLUMN_TRACK) { + else if (is_track) { const char *t; t = pl_find_meta (it, "track"); int a = t ? atoi (t) : -1; diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index a51c5136..ed4fb3ca 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -38,7 +38,6 @@ #include "ddbseekbar.h" #include "search.h" #include "progress.h" -#include "../../session.h" #include "gtkui.h" #include "parser.h" #include "drawing.h" diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c index 90874f6b..6ea18db4 100644 --- a/plugins/gtkui/ddblistview.c +++ b/plugins/gtkui/ddblistview.c @@ -2704,6 +2704,7 @@ ddb_listview_column_set_info (DdbListview *listview, int col, const char *title, c->align_right = align_right; c->minheight = minheight; c->user_data = user_data; + listview->binding->columns_changed (listview); return 0; } } diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 854d46fd..28dd63a1 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -1707,13 +1707,14 @@ <property name="visible">True</property> <property name="items" translatable="yes">File number Playing +Album Art Artist - Album Artist Album Title Length Track -Album Art +Band / Album Artist Custom</property> <property name="add_tearoffs">False</property> <property name="focus_on_click">True</property> @@ -1850,7 +1851,7 @@ Right</property> <property name="label" translatable="yes">Format conversions (start with %): [a]rtist, [t]itle, al[b]um, track[n]umber, [l]ength, [y]ear, [g]enre, [c]omment, - copy[r]ight, [f]ilename + copy[r]ight, [f]ilename, [T]ags, [B]and Example: %a - %t [%l]</property> <property name="use_underline">False</property> <property name="use_markup">True</property> diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index bd6222d4..f35a71ab 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1307,13 +1307,14 @@ create_editcolumndlg (void) gtk_box_pack_start (GTK_BOX (hbox30), id, TRUE, TRUE, 0); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "File number"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Playing"); + gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Album Art"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Artist - Album"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Artist"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Album"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Title"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Length"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Track"); - gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Album Art"); + gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Band / Album Artist"); gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Custom"); hbox31 = gtk_hbox_new (FALSE, 8); @@ -1346,7 +1347,7 @@ create_editcolumndlg (void) gtk_combo_box_append_text (GTK_COMBO_BOX (align), "Left"); gtk_combo_box_append_text (GTK_COMBO_BOX (align), "Right"); - label25 = gtk_label_new ("Format conversions (start with %):\n [a]rtist, [t]itle, al[b]um, track[n]umber,\n [l]ength, [y]ear, [g]enre, [c]omment,\n copy[r]ight, [f]ilename\nExample: %a - %t [%l]"); + label25 = gtk_label_new ("Format conversions (start with %):\n [a]rtist, [t]itle, al[b]um, track[n]umber,\n [l]ength, [y]ear, [g]enre, [c]omment,\n copy[r]ight, [f]ilename, [T]ags, [B]and\nExample: %a - %t [%l]"); gtk_widget_show (label25); gtk_box_pack_start (GTK_BOX (vbox14), label25, TRUE, TRUE, 0); GTK_WIDGET_SET_FLAGS (label25, GTK_CAN_FOCUS); diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c index f360fecf..8ea4041c 100644 --- a/plugins/gtkui/mainplaylist.c +++ b/plugins/gtkui/mainplaylist.c @@ -283,10 +283,10 @@ main_playlist_init (GtkWidget *widget) { if (!col) { // create default set of columns add_column_helper (listview, "Playing", 50, DB_COLUMN_PLAYING, NULL, 0); - add_column_helper (listview, "Artist / Album", 150, DB_COLUMN_ARTIST_ALBUM, NULL, 0); - add_column_helper (listview, "Track №", 50, DB_COLUMN_TRACK, NULL, 1); - add_column_helper (listview, "Title / Track Artist", 150, DB_COLUMN_TITLE, NULL, 0); - add_column_helper (listview, "Duration", 50, DB_COLUMN_DURATION, NULL, 0); + add_column_helper (listview, "Artist / Album", 150, -1, "%a - %b", 0); + add_column_helper (listview, "Track №", 50, -1, "%n", 1); + add_column_helper (listview, "Title / Track Artist", 150, -1, "%t", 0); + add_column_helper (listview, "Duration", 50, -1, "%l", 0); } else { while (col) { diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c index a5305615..aa43425d 100644 --- a/plugins/gtkui/plcommon.c +++ b/plugins/gtkui/plcommon.c @@ -498,11 +498,91 @@ append_column_from_textdef (DdbListview *listview, const uint8_t *def) { col_info_t *inf = malloc (sizeof (col_info_t)); memset (inf, 0, sizeof (col_info_t)); - inf->format = strdup (fmt); - inf->id = id; + + enum { + DB_COLUMN_ARTIST_ALBUM = 2, + DB_COLUMN_ARTIST = 3, + DB_COLUMN_ALBUM = 4, + DB_COLUMN_TITLE = 5, + DB_COLUMN_DURATION = 6, + DB_COLUMN_TRACK = 7, + }; + + inf->id = -1; + // convert IDs from pre-0.4 + switch (id) { + case DB_COLUMN_ARTIST_ALBUM: + inf->format = strdup ("%a - %b"); + break; + case DB_COLUMN_ARTIST: + inf->format = strdup ("%a"); + break; + case DB_COLUMN_ALBUM: + inf->format = strdup ("%b"); + break; + case DB_COLUMN_TITLE: + inf->format = strdup ("%t"); + break; + case DB_COLUMN_DURATION: + inf->format = strdup ("%l"); + break; + case DB_COLUMN_TRACK: + inf->format = strdup ("%n"); + break; + default: + inf->format = *fmt ? strdup (fmt) : NULL; + inf->id = id; + break; + } ddb_listview_column_append (listview, title, width, align, id == DB_COLUMN_ALBUM_ART ? width : 0, inf); } +static void +init_column (col_info_t *inf, int id, const char *format) { + if (inf->format) { + free (inf->format); + inf->format = NULL; + } + + inf->id = -1; + + switch (id) { + case 0: + inf->id = DB_COLUMN_FILENUMBER; + break; + case 1: + inf->id = DB_COLUMN_PLAYING; + break; + case 2: + inf->id = DB_COLUMN_ALBUM_ART; + break; + case 3: + inf->format = strdup ("%a - %b"); + break; + case 4: + inf->format = strdup ("%a"); + break; + case 5: + inf->format = strdup ("%b"); + break; + case 6: + inf->format = strdup ("%t"); + break; + case 7: + inf->format = strdup ("%l"); + break; + case 8: + inf->format = strdup ("%n"); + break; + case 9: + inf->format = strdup ("%B"); + break; + default: + inf->format = strdup (format); + } +} + + void on_add_column_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -516,16 +596,15 @@ on_add_column_activate (GtkMenuItem *menuitem, if (response == GTK_RESPONSE_OK) { const gchar *title = gtk_entry_get_text (GTK_ENTRY (lookup_widget (dlg, "title"))); const gchar *format = gtk_entry_get_text (GTK_ENTRY (lookup_widget (dlg, "format"))); - int id = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "id"))); - int align = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "align"))); - if (id >= DB_COLUMN_ID_MAX) { - id = -1; - } + int sel = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "id"))); + col_info_t *inf = malloc (sizeof (col_info_t)); memset (inf, 0, sizeof (col_info_t)); - inf->format = strdup (format); - inf->id = id; - ddb_listview_column_insert (last_playlist, active_column, title, 100, align, id == DB_COLUMN_ALBUM_ART ? 100 : 0, inf); + + init_column (inf, sel, format); + + int align = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "align"))); + ddb_listview_column_insert (last_playlist, active_column, title, 100, align, inf->id == DB_COLUMN_ALBUM_ART ? 100 : 0, inf); ddb_listview_refresh (last_playlist, DDB_REFRESH_COLUMNS | DDB_REFRESH_LIST | DDB_REFRESH_HSCROLL | DDB_EXPOSE_LIST | DDB_EXPOSE_COLUMNS); } gtk_widget_destroy (dlg); @@ -554,12 +633,41 @@ on_edit_column_activate (GtkMenuItem *menuitem, } gtk_entry_set_text (GTK_ENTRY (lookup_widget (dlg, "title")), title); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (dlg, "format")), inf->format); + int idx = 10; if (inf->id == -1) { - gtk_combo_box_set_active (GTK_COMBO_BOX (lookup_widget (dlg, "id")), DB_COLUMN_ID_MAX); + if (inf->format) { + if (!strcmp (inf->format, "%a - %b")) { + idx = 3; + } + else if (!strcmp (inf->format, "%a")) { + idx = 4; + } + else if (!strcmp (inf->format, "%b")) { + idx = 5; + } + else if (!strcmp (inf->format, "%t")) { + idx = 6; + } + else if (!strcmp (inf->format, "%l")) { + idx = 7; + } + else if (!strcmp (inf->format, "%n")) { + idx = 8; + } + else if (!strcmp (inf->format, "%B")) { + idx = 9; + } + } + } + else if (inf->id <= DB_COLUMN_PLAYING) { + idx = inf->id; } - else { - gtk_combo_box_set_active (GTK_COMBO_BOX (lookup_widget (dlg, "id")), inf->id); + else if (inf->id == DB_COLUMN_ALBUM_ART) { + idx = 2; + } + gtk_combo_box_set_active (GTK_COMBO_BOX (lookup_widget (dlg, "id")), idx); + if (idx == 10) { + gtk_entry_set_text (GTK_ENTRY (lookup_widget (dlg, "format")), inf->format); } gtk_combo_box_set_active (GTK_COMBO_BOX (lookup_widget (dlg, "align")), align_right); gint response = gtk_dialog_run (GTK_DIALOG (dlg)); @@ -568,13 +676,9 @@ on_edit_column_activate (GtkMenuItem *menuitem, const gchar *format = gtk_entry_get_text (GTK_ENTRY (lookup_widget (dlg, "format"))); int id = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "id"))); int align = gtk_combo_box_get_active (GTK_COMBO_BOX (lookup_widget (dlg, "align"))); - if (id >= DB_COLUMN_ID_MAX) { - id = -1; - } - free (inf->format); - inf->format = strdup (format); - inf->id = id; - ddb_listview_column_set_info (last_playlist, active_column, title, width, align, id == DB_COLUMN_ALBUM_ART ? width : 0, inf); + + init_column (inf, id, format); + ddb_listview_column_set_info (last_playlist, active_column, title, width, align, inf->id == DB_COLUMN_ALBUM_ART ? width : 0, inf); ddb_listview_refresh (last_playlist, DDB_REFRESH_COLUMNS | DDB_REFRESH_LIST | DDB_EXPOSE_LIST | DDB_EXPOSE_COLUMNS); } diff --git a/plugins/gtkui/search.c b/plugins/gtkui/search.c index 965b526f..09680f24 100644 --- a/plugins/gtkui/search.c +++ b/plugins/gtkui/search.c @@ -424,10 +424,10 @@ search_playlist_init (GtkWidget *widget) { // create default set of columns DB_conf_item_t *col = deadbeef->conf_find ("search.column.", NULL); if (!col) { - add_column_helper (listview, "Artist / Album", 150, DB_COLUMN_ARTIST_ALBUM, NULL, 0); - add_column_helper (listview, "Track №", 50, DB_COLUMN_TRACK, NULL, 1); - add_column_helper (listview, "Title / Track Artist", 150, DB_COLUMN_TITLE, NULL, 0); - add_column_helper (listview, "Duration", 50, DB_COLUMN_DURATION, NULL, 0); + add_column_helper (listview, "Artist / Album", 150, -1, "%a - %b", 0); + add_column_helper (listview, "Track №", 50, -1, "%n", 1); + add_column_helper (listview, "Title / Track Artist", 150, -1, "%t", 0); + add_column_helper (listview, "Duration", 50, -1, "%l", 0); } else { while (col) { diff --git a/session.c b/session.c deleted file mode 100644 index 4be42deb..00000000 --- a/session.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> - - 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 <stdio.h> -#include <string.h> -#include <stdint.h> -#include <unistd.h> -#include "session.h" -#include "common.h" -#include "deadbeef.h" -#include "conf.h" - -#define SESS_CURRENT_VER 4 -// changelog: -// version 5 everything moved to common config -// version 4 column settings moved to common config -// version 3 adds column widths - -// NOTE: dont forget to update session_reset when changing that - -static const uint8_t sessfile_magic[] = { 0xdb, 0xef, 0x5e, 0x55 }; // dbefsess in hexspeak - -void -session_reset (void) { -} - -#if 0 -static int -write_i16_be (uint16_t val, FILE *fp) { - uint8_t b; - b = (uint8_t)(val&0xff); - if (fwrite (&b, 1, 1, fp) != 1) { - return 0; - } - b = (uint8_t)((val&0xff00)>>8); - if (fwrite (&b, 1, 1, fp) != 1) { - return 1; - } - return 2; -} - -static int -write_i32_be (uint32_t val, FILE *fp) { - uint8_t b; - b = (uint8_t)(val&0xff); - if (fwrite (&b, 1, 1, fp) != 1) { - return 0; - } - b = (uint8_t)((val&0xff00)>>8); - if (fwrite (&b, 1, 1, fp) != 1) { - return 1; - } - b = (uint8_t)((val&0xff0000)>>16); - if (fwrite (&b, 1, 1, fp) != 1) { - return 2; - } - b = (uint8_t)((val&0xff000000)>>24); - if (fwrite (&b, 1, 1, fp) != 1) { - return 3; - } - return 4; -} -#endif - -static int -read_i16_be (uint16_t *pval, FILE *fp) { - uint16_t val = 0; - uint8_t b; - if (fread (&b, 1, 1, fp) != 1) { - return 0; - } - val |= (uint16_t)b; - if (fread (&b, 1, 1, fp) != 1) { - return 1; - } - val |= (((uint16_t)b) << 8); - *pval = val; - return 2; -} - -static int -read_i32_be (uint32_t *pval, FILE *fp) { - uint32_t val = 0; - uint8_t b; - if (fread (&b, 1, 1, fp) != 1) { - return 0; - } - val |= (uint32_t)b; - if (fread (&b, 1, 1, fp) != 1) { - return 1; - } - val |= (((uint32_t)b) << 8); - if (fread (&b, 1, 1, fp) != 1) { - return 2; - } - val |= (((uint32_t)b) << 16); - if (fread (&b, 1, 1, fp) != 1) { - return 3; - } - val |= (((uint32_t)b) << 24); - *pval = val; - return 4; -} - -int -session_load (const char *fname) { - char session_dir[2048]; - float session_volume; - int8_t session_playlist_order; - int8_t session_playlist_looping; - int8_t session_scroll_follows_playback = 1; - int session_win_attrs[5] = { 40, 40, 500, 300, 0 }; - - session_volume = 0; - session_dir[0] = 0; - session_playlist_looping = 0; - session_playlist_order = 0; - session_scroll_follows_playback = 1; - session_win_attrs[0] = 40; - session_win_attrs[1] = 40; - session_win_attrs[2] = 500; - session_win_attrs[3] = 300; - session_win_attrs[4] = 0; - - FILE *fp = fopen (fname, "r+b"); - if (!fp) { - return -1; - } - // magic - uint8_t magic[4]; - if (fread (magic, 1, 4, fp) != 4) { - goto session_load_fail; - } - if (memcmp (magic, sessfile_magic, 4)) { - goto session_load_fail; - } - uint8_t version; - if (fread (&version, 1, 1, fp) != 1) { - goto session_load_fail; - } - if (version < 2 || version > SESS_CURRENT_VER) { - goto session_load_fail; - } - uint16_t l; - if (read_i16_be (&l, fp) != 2) { - goto session_load_fail; - } - if (l >= 2048) { - goto session_load_fail; - } - if (fread (session_dir, 1, l, fp) != l) { - goto session_load_fail; - } - session_dir[l] = 0; - if (read_i32_be ((uint32_t*)&session_volume, fp) != 4) { - goto session_load_fail; - } - if (fread (&session_playlist_order, 1, 1, fp) != 1) { - goto session_load_fail; - } - if (session_playlist_order < 0 || session_playlist_order > 2) { - goto session_load_fail; - } - if (fread (&session_playlist_looping, 1, 1, fp) != 1) { - goto session_load_fail; - } - if (session_playlist_looping < 0 || session_playlist_looping > 2) { - goto session_load_fail; - } - if (fread (&session_scroll_follows_playback, 1, 1, fp) != 1) { - goto session_load_fail; - } - for (int k = 0; k < 5; k++) { - if (read_i32_be (&session_win_attrs[k], fp) != 4) { - goto session_load_fail; - } - } - if (version == 3) { - // import playlist and search columns to new common config -#define PL_MAX_COLUMNS 5 - int session_main_colwidths[PL_MAX_COLUMNS] = { 50, 150, 50, 150, 50 }; - int session_main_numcols = 5; - int session_search_colwidths[PL_MAX_COLUMNS] = { 0, 150, 50, 150, 50 };; - int session_search_numcols = 5; - { - // main column widths - uint8_t l; - if (fread (&l, 1, 1, fp) != 1) { - goto session_load_fail; - } - if (l > PL_MAX_COLUMNS) { - goto session_load_fail; - } - session_main_numcols = l; - for (int i = 0; i < l; i++) { - int16_t w; - if (fread (&w, 1, sizeof (w), fp) != sizeof (w)) { - goto session_load_fail; - } - session_main_colwidths[i] = w; - } - } - { - // search column widths - uint8_t l; - if (fread (&l, 1, 1, fp) != 1) { - goto session_load_fail; - } - if (l > PL_MAX_COLUMNS) { - goto session_load_fail; - } - session_search_numcols = l; - for (int i = 0; i < l; i++) { - int16_t w; - if (fread (&w, 1, sizeof (w), fp) != sizeof (w)) { - goto session_load_fail; - } - session_search_colwidths[i] = w; - } - } - // convert to common config - const char *colnames[] = { - "Playing", - "Artist / Album", - "Track №", - "Title / Track Artist", - "Duration" - }; - int colids[] = { - DB_COLUMN_PLAYING, - DB_COLUMN_ARTIST_ALBUM, - DB_COLUMN_TRACK, - DB_COLUMN_TITLE, - DB_COLUMN_DURATION - }; - int i; - for (i = 0; i < 5; i++) { - char key[128]; - char value[128]; - snprintf (key, sizeof (key), "playlist.column.%d", i); - snprintf (value, sizeof (value), "\"%s\" \"%s\" %d %d %d", colnames[i], "", colids[i], session_main_colwidths[i], i == 2 ? 1 : 0); - conf_set_str (key, value); - } - for (i = 1; i < 5; i++) { - char key[128]; - char value[128]; - snprintf (key, sizeof (key), "search.column.%d", i-1); - snprintf (value, sizeof (value), "\"%s\" \"%s\" %d %d %d", colnames[i], "", colids[i], session_main_colwidths[i], i == 2 ? 1 : 0); - conf_set_str (key, value); - } - } -// printf ("dir: %s\n", session_dir); -// printf ("volume: %f\n", session_volume); -// printf ("win: %d %d %d %d %d\n", session_win_attrs[0], session_win_attrs[1], session_win_attrs[2], session_win_attrs[3], session_win_attrs[4]); - fclose (fp); - - if (version <= 4) { - // move everything to common config - conf_set_str ("filechooser.lastdir", session_dir); - conf_set_int ("playback.loop", session_playlist_looping); - conf_set_int ("playback.order", session_playlist_order); - conf_set_float ("playback.volume", session_volume); - conf_set_int ("playlist.scroll.followplayback", session_scroll_follows_playback); - conf_set_int ("mainwin.geometry.x", session_win_attrs[0]); - conf_set_int ("mainwin.geometry.y", session_win_attrs[1]); - conf_set_int ("mainwin.geometry.w", session_win_attrs[2]); - conf_set_int ("mainwin.geometry.h", session_win_attrs[3]); - } - - return 0; -session_load_fail: - fprintf (stderr, "failed to load session, session file is corrupt\n"); - fclose (fp); -// session_reset (); - return -1; -} diff --git a/session.h b/session.h deleted file mode 100644 index 92b605e8..00000000 --- a/session.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> - - 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 __SESSION_H -#define __SESSION_H - -#include <stdint.h> - -int -session_load (const char *fname); - -#endif // __SESSION_H |