Code

ncmpc.git
15 years agoncmpc.1: -k is the short version of --key-file, not -P
J. Alexander Treuman [Sun, 21 Sep 2008 19:37:25 +0000 (21:37 +0200)]
ncmpc.1: -k is the short version of --key-file, not -P

15 years agogenerate po/Makefile.in instead of bundling it
J. Alexander Treuman [Sun, 21 Sep 2008 19:37:03 +0000 (21:37 +0200)]
generate po/Makefile.in instead of bundling it

The previously bundled po/Makefile.in would use predefined variables that
should be set by the configure script.  f.e., $prefix was defined as
/usr/local, and caused po files to always be installed there instead of in
the prefix given to ./configure.

15 years agoconfigure.ac: don't enable the lyrics screen by default
J. Alexander Treuman [Sun, 21 Sep 2008 19:36:11 +0000 (21:36 +0200)]
configure.ac: don't enable the lyrics screen by default

The configure help text already said the lyrics screen was disabled by
default.  Now it actually will be.

15 years agoautogen: don't run ./configure if $NOCONFIGURE is set
J. Alexander Treuman [Sun, 21 Sep 2008 19:36:09 +0000 (21:36 +0200)]
autogen: don't run ./configure if $NOCONFIGURE is set

15 years agompdclient: don't call screen_status_message()
Max Kellermann [Sun, 21 Sep 2008 11:50:35 +0000 (13:50 +0200)]
mpdclient: don't call screen_status_message()

The caller should decide how to display error messages.

15 years agoAdding crop feature in ncmpc
Yannick LM [Sun, 21 Sep 2008 11:50:26 +0000 (13:50 +0200)]
Adding crop feature in ncmpc

The "crop" command deletes all songs from the playlist, except the one
currently being played.

15 years agoscreen_help: removed update() method
Max Kellermann [Sun, 21 Sep 2008 11:48:44 +0000 (13:48 +0200)]
screen_help: removed update() method

Why redraw the help screen when nothing has changed?  Redraw it only
after help_cmd(), and when explicitly requested (help_paint()).

15 years agofilelist: fix segfault during filelist_sort()
Max Kellermann [Fri, 19 Sep 2008 15:31:17 +0000 (17:31 +0200)]
filelist: fix segfault during filelist_sort()

When I converted the filelist from GList to GPtrArray, I missed that
the GCompareFunc does not actually get the pointers from
g_ptr_array_sort(), but pointers to the pointers...  run
g_ptr_array_sort_with_data() instead with a wrapper function.

15 years agofilelist: free entries with g_slice_free()
Max Kellermann [Fri, 19 Sep 2008 14:44:23 +0000 (16:44 +0200)]
filelist: free entries with g_slice_free()

Somehow I forgot about changing free() to g_slice_free() in the
previous patch...

15 years agofilelist: allocate entries with g_slice_alloc()
Max Kellermann [Fri, 19 Sep 2008 14:37:06 +0000 (16:37 +0200)]
filelist: allocate entries with g_slice_alloc()

In this case, slices are faster.  Also fix a memory leak in
filelist_prepend() which I simply forgot about in the last patch set.

15 years agoproperly configure M4 macro dir
unK [Fri, 19 Sep 2008 14:37:06 +0000 (16:37 +0200)]
properly configure M4 macro dir

Add information about the M4 macro dir ./m4/ to both configure.ac and
Makefile.am.

15 years agofilelist: use GPtrArray instead of GList
Max Kellermann [Fri, 19 Sep 2008 14:25:28 +0000 (16:25 +0200)]
filelist: use GPtrArray instead of GList

Since we do a lot of indexed accesses to the filelist, a linked list
doesn't seem appropriate.  Use GPtrArray instead.

15 years agobrowser: added function browser_get_selected()
Max Kellermann [Fri, 19 Sep 2008 14:24:37 +0000 (16:24 +0200)]
browser: added function browser_get_selected()

browser_get_selected() checks if there is a file list and a valid
selection, and returns the selected entry.

15 years agoscreen_search: free second file list
Max Kellermann [Fri, 19 Sep 2008 14:23:33 +0000 (16:23 +0200)]
screen_search: free second file list

Fix a memory leak: the concatened list was never freed.

15 years agofilelist: provide more functions for working with a filelist
Max Kellermann [Fri, 19 Sep 2008 14:23:31 +0000 (16:23 +0200)]
filelist: provide more functions for working with a filelist

Avoid direct accesses to the filelist struct, provide an API for that.

15 years agofilelist: drop "mpdclient" prefix
Max Kellermann [Fri, 19 Sep 2008 14:22:44 +0000 (16:22 +0200)]
filelist: drop "mpdclient" prefix

The separate filelist library does not depend on mpdclient, so the
prefix is superfluous.

15 years agobrowser: use mpdclient_filelist_find_song() in set_highlight()
Max Kellermann [Fri, 19 Sep 2008 12:48:22 +0000 (14:48 +0200)]
browser: use mpdclient_filelist_find_song() in set_highlight()

A song should not be twice in the browser.  Simplify set_highlight()
by finding the entry with mpdclient_filelist_find_song().

15 years agobrowser: song must not be NULL in set_highlight()
Max Kellermann [Fri, 19 Sep 2008 12:45:32 +0000 (14:45 +0200)]
browser: song must not be NULL in set_highlight()

The caller must not pass NULL to set_highlight().  Replaced check with
assertion.

15 years agofilelist: song must not be NULL
Max Kellermann [Fri, 19 Sep 2008 12:42:09 +0000 (14:42 +0200)]
filelist: song must not be NULL

A caller must not pass NULL to mpdclient_filelist_find_song().
Replace the check with an assertion.

15 years agompdclient: moved code to filelist.c
Max Kellermann [Fri, 19 Sep 2008 12:10:37 +0000 (14:10 +0200)]
mpdclient: moved code to filelist.c

Move everything which is solely filelist related to filelist.c and
filelist.h.  Fix the indentation of that file, and provide the struct
name "filelist".  Don't clear data in mpdclient_filelist_free() before
calling g_free().  Constify the "song" parameter to
mpdclient_filelist_find_song().

15 years agocode style, indent with tabs VII
Max Kellermann [Fri, 19 Sep 2008 12:10:35 +0000 (14:10 +0200)]
code style, indent with tabs VII

Follow the same code style als MPD itself.

15 years agofix terminal resizing (SIGWINCH)
Max Kellermann [Fri, 19 Sep 2008 06:02:40 +0000 (08:02 +0200)]
fix terminal resizing (SIGWINCH)

When I replaced ncmpc's old main loop with g_main_loop from libglib,
SIGWINCH (i.e. window resizing) stopped working.  This regression was
caused by the fact that ncurses' wgetch() function was only called
when there was actually data on STDIN.  wgetch() has several side
effects besides reading data from STDIN, for example it checks whether
there has been a window resize.

Fix this with a custom SIGWINCH handler.

15 years agoremoved the clock screen
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
removed the clock screen

Why should an audio player display a large clock?

15 years agoscreen_browser: removed entity.song!=NULL check
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: removed entity.song!=NULL check

It is guaranteed that the "song" attribute is not NULL, remove the
check.

15 years agoscreen_browser: removed redundant highlight check
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: removed redundant highlight check

browser_select_entry() checked the entry's "highlight" flag twice: the
first time, it was toggled, and the second time, action was performed
based on the flag.  Merge the two checks.

15 years agoscreen_browser: removed redundant entity type checks
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: removed redundant entity type checks

The function browser_select_entry() returns early when the entity type
is not "SONG".  No need to double check that.

15 years agoscreen_browser: moved code to browser_select_entry()
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: moved code to browser_select_entry()

Moved code from browser_handle_select().  Call this new function also
from browser_handle_select_all().  This fixes a bug in select_all():
it actually did not select all, but stopped after the first song.

15 years agoscreen_browser: removed commented code
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: removed commented code

15 years agoscreen_browser: moved code to browser_playlist_changed()
Max Kellermann [Thu, 18 Sep 2008 21:35:12 +0000 (23:35 +0200)]
screen_browser: moved code to browser_playlist_changed()

Merge code from all 3 browser screens into one generic browser
function.

15 years agoscreen_browser: moved code to screen_browser.c
Max Kellermann [Thu, 18 Sep 2008 21:35:11 +0000 (23:35 +0200)]
screen_browser: moved code to screen_browser.c

Isolate the generic browser code from the directory browser.

15 years agoscreen_browser: added struct screen_browser
Max Kellermann [Thu, 18 Sep 2008 21:35:11 +0000 (23:35 +0200)]
screen_browser: added struct screen_browser

We are going to separate the browser functions from screen_file.c.
Move all variables which are going to be needed by this code.

15 years agorenamed screen_browse.h to screen_browser.h
Max Kellermann [Thu, 18 Sep 2008 21:35:11 +0000 (23:35 +0200)]
renamed screen_browse.h to screen_browser.h

15 years agocode style, indent with tabs VI
Max Kellermann [Thu, 18 Sep 2008 21:35:10 +0000 (23:35 +0200)]
code style, indent with tabs VI

Follow the same code style als MPD itself.

15 years agoadded support for wide characters
Max Kellermann [Thu, 18 Sep 2008 11:18:16 +0000 (13:18 +0200)]
added support for wide characters

This patch was taken from bug 476, author unknown
(http://www.musicpd.org/mantis/view.php?id=476).  It changes the
definition of my_strlen(): instead of returning the number of UTF-8
characters, it counts the number of terminal cells occupied by a
string.

15 years agocode style, indent with tabs V
Max Kellermann [Thu, 18 Sep 2008 10:53:35 +0000 (12:53 +0200)]
code style, indent with tabs V

Follow the same code style als MPD itself.

15 years agoscreen: don't handle CMD_PLAY
Max Kellermann [Thu, 18 Sep 2008 10:32:09 +0000 (12:32 +0200)]
screen: don't handle CMD_PLAY

CMD_PLAY is mapped to the Enter key by default.  Some screens
(mis-)use it for navigation, for entering a directory.  The playlist
screen actually plays the file under the cursor.  On all other
screens, pressing Enter may be confusing, since it is more of a
"confirmation" key instead of "play".  We should probaby add
CMD_CONFIRM later, but for now, disable the general CMD_PLAY handler
in screen.c.  This fixes bug 240.

15 years agolibmpdclient: added resolver library
Max Kellermann [Thu, 18 Sep 2008 09:17:17 +0000 (11:17 +0200)]
libmpdclient: added resolver library

The resolver library provides unified access to all resolvers
(getaddrinfo(), gethostbyname(), Unix domain sockets).  Like
getaddrinfo(), it can return more than one address for a host name.
This fixes bug 1517 (http://www.musicpd.org/mantis/view.php?id=1517).

15 years agoquit with g_main_loop_quit()
Max Kellermann [Thu, 18 Sep 2008 07:44:01 +0000 (09:44 +0200)]
quit with g_main_loop_quit()

Call g_main_loop_quit() on CMD_QUIT, instead of exit() with an
atexit() handler.

15 years agoplaylist: reset id in playlist_clear()
Max Kellermann [Wed, 17 Sep 2008 23:57:34 +0000 (01:57 +0200)]
playlist: reset id in playlist_clear()

The playlist is reset when the connection to the MPD server is
closed.  After a successful reconnect, we have to reload the full
playlist.  To remember this, also reset the id attribute.

15 years agoplaylist: removed "updated" flag
Max Kellermann [Wed, 17 Sep 2008 23:55:45 +0000 (01:55 +0200)]
playlist: removed "updated" flag

The caller may check the playlist.id instead of checking the old
"updated" flag.

15 years agouse the glib main event loop
Max Kellermann [Wed, 17 Sep 2008 23:49:53 +0000 (01:49 +0200)]
use the glib main event loop

This big patch replaces our custom main loop with the event based glib
main loop.  This has several advantages: we can make all the tiny code
bits in the main loop independent from each others, we can add
additional file descriptors for polling (e.g. the mpdclient socket).

We don't need the ncurses timeout() anymore, because glib will poll
stdin for us.

15 years agoscreen: check MPD status only if connected
Max Kellermann [Wed, 17 Sep 2008 23:15:20 +0000 (01:15 +0200)]
screen: check MPD status only if connected

Fix several segmentation faults: when the connection to the MPD server
is lost, there were NULL pointer dereferences because
client->status==NULL.  Check before accessing it.

15 years agoscreen: moved code to screen_client_cmd()
Max Kellermann [Wed, 17 Sep 2008 23:14:00 +0000 (01:14 +0200)]
screen: moved code to screen_client_cmd()

Move all command handlers which need a connection to the MPD server to
screen_client_cmd().  This will allow us to unify error handling
later.

15 years agomain: connect while UI is displayed
Max Kellermann [Wed, 17 Sep 2008 23:13:02 +0000 (01:13 +0200)]
main: connect while UI is displayed

Display the UI always, and show connection errors there.  This fixes a
lot of consistency problems: error messages used to be printed to
stderr, but afterwards, the atexit() handlers deinitialized ncurses
and the screen was cleared.  This patch is still problematic, but
constitutes a good step forward.

15 years agolibmpdclient: moved code to mpd_recv(), mpd_wait()
Max Kellermann [Wed, 17 Sep 2008 23:10:40 +0000 (01:10 +0200)]
libmpdclient: moved code to mpd_recv(), mpd_wait()

Create generic utility functions for doint I/O: two wait functions,
and mpd_recv() fills the input buffer.  These functions are used in
mpd_newConnection() and mpd_getNextReturnElement().

15 years agolibmpdclient: smaller input buffer
Max Kellermann [Wed, 17 Sep 2008 23:07:16 +0000 (01:07 +0200)]
libmpdclient: smaller input buffer

Even for large responses, 16kB should be enough.  There is no
performance gain for larger buffers, even if MPD is local.

15 years agolibmpdclient: smaller error buffer
Max Kellermann [Wed, 17 Sep 2008 23:05:16 +0000 (01:05 +0200)]
libmpdclient: smaller error buffer

512 characters should be well enough for error messages which are
actually being displayed somewhere.  Use sizeof(errorStr) instead of
MPD_BUFFER_MAX_LENGTH everywhere.  Do proper length checking when
copying the output buffer to errorStr.

15 years agolibmpdclient: use memmove() instead of strcpy() for moving the buffer
Max Kellermann [Wed, 17 Sep 2008 23:05:14 +0000 (01:05 +0200)]
libmpdclient: use memmove() instead of strcpy() for moving the buffer

In general, don't treat the input buffer as a null-terminated string:
don't append '\0', don't use strchr() and strtok().  To delete
consumed portions of the buffer, strcpy() is bad anyway, because it
does not allow overlapping buffers.

15 years agolibmpdclient: don't strdup() MPD's welcome message
Max Kellermann [Wed, 17 Sep 2008 23:00:12 +0000 (01:00 +0200)]
libmpdclient: don't strdup() MPD's welcome message

Why bother duplicating the buffer, when we can simply parse the
response directly from the input buffer?

15 years agolibmpdclient: use size_t and ssize_t
Max Kellermann [Wed, 17 Sep 2008 22:59:40 +0000 (00:59 +0200)]
libmpdclient: use size_t and ssize_t

When working with buffer lengths and recv() results, we should declare
size_t and ssize_t variables, otherwise the code may fail on 64 bit
machines.

15 years agoscreen: removed empty methods
Max Kellermann [Wed, 17 Sep 2008 22:58:40 +0000 (00:58 +0200)]
screen: removed empty methods

Declaring empty methods is of no use.  If a method is empty, we should
set it to NULL in the screen_functions struct.

15 years agoscreen: removed NULL check
Max Kellermann [Wed, 17 Sep 2008 22:57:50 +0000 (00:57 +0200)]
screen: removed NULL check

Since the screen's initialization is guaranteed, we can remove the
NULL check in center_playing_item().

15 years agoscreen_artist: fix compilation errors
Max Kellermann [Wed, 17 Sep 2008 19:09:21 +0000 (21:09 +0200)]
screen_artist: fix compilation errors

Unfortunately when I fixed the GCC warnings and refactored lots of the
code, the "artist" screen was disabled.  This patch applies all API
changes and fixes all warnings.

15 years agocode style, indent with tabs IV
Max Kellermann [Wed, 17 Sep 2008 19:08:06 +0000 (21:08 +0200)]
code style, indent with tabs IV

Follow the same code style als MPD itself.

15 years agobrowse: when deselecting, don't search twice
Max Kellermann [Wed, 17 Sep 2008 10:29:24 +0000 (12:29 +0200)]
browse: when deselecting, don't search twice

When deselecting a song in the file browser, the local variable "idx"
was initialized and overwritten.  Remove the initialization.

15 years agoplaylist: added playlist_remove_reuse()
Max Kellermann [Wed, 17 Sep 2008 10:29:15 +0000 (12:29 +0200)]
playlist: added playlist_remove_reuse()

playlist_remove_reuse() removes a song from the playlist, but does not
free it.

Use this function in mpdclient_cmd_delete() to fix a segmentation
fault: the song pointer was still used after it was freed, by passing
it to mpdclient_playlist_callback().  Free the song manually now.
Reorganize and simply some code in mpdclient_cmd_delete().

15 years agomake several functions return void
Max Kellermann [Wed, 17 Sep 2008 10:29:07 +0000 (12:29 +0200)]
make several functions return void

15 years agoplaylist: use playlist_get() instead of playlist_get_song()
Max Kellermann [Wed, 17 Sep 2008 10:29:06 +0000 (12:29 +0200)]
playlist: use playlist_get() instead of playlist_get_song()

15 years agolist_window: don't reset *highlight to 0
Max Kellermann [Wed, 17 Sep 2008 10:25:52 +0000 (12:25 +0200)]
list_window: don't reset *highlight to 0

Since the list_window code sets highlight to 0 before it calls the
list_callback, the callback itself doesn't have to reset the flag.

15 years agolyrics: don't check current.lines==NULL
Max Kellermann [Wed, 17 Sep 2008 10:25:48 +0000 (12:25 +0200)]
lyrics: don't check current.lines==NULL

current.lines is always initialized, and cannot be NULL, no need to
check it.

15 years agohelp: return early from list_callback()
Max Kellermann [Wed, 17 Sep 2008 10:25:41 +0000 (12:25 +0200)]
help: return early from list_callback()

15 years agohelp: converted help_text_rows to a macro
Max Kellermann [Wed, 17 Sep 2008 10:25:40 +0000 (12:25 +0200)]
help: converted help_text_rows to a macro

Why bother counting the elements of help_text[] (with sentinel) at
runtime, when the compiler can do it at compile time?

15 years agolyrics: removed lyrics_text_rows, use current.lines->len instead
Max Kellermann [Wed, 17 Sep 2008 10:24:56 +0000 (12:24 +0200)]
lyrics: removed lyrics_text_rows, use current.lines->len instead

lyrics_text_rows wasn't set anyway, I somehow removed the code in a
patch some time ago.

15 years agolist_window: added list_window_center()
Max Kellermann [Wed, 17 Sep 2008 10:20:42 +0000 (12:20 +0200)]
list_window: added list_window_center()

Merge code which used to be duplicated in the screens "play", "help",
"lyrics".

15 years agolist_window: added list_window_scroll_cmd()
Max Kellermann [Wed, 17 Sep 2008 10:18:00 +0000 (12:18 +0200)]
list_window: added list_window_scroll_cmd()

It is similar to list_window_cmd(), but it scrolls the window instead
of moving the selection.  It is used by the "lyrics" and the "help"
screen.

15 years agolist_window: set repaint at the end of list_window_cmd()
Max Kellermann [Wed, 17 Sep 2008 10:08:09 +0000 (12:08 +0200)]
list_window: set repaint at the end of list_window_cmd()

15 years agoscreen: return early in switch_screen_mode() on error
Max Kellermann [Wed, 17 Sep 2008 10:08:06 +0000 (12:08 +0200)]
screen: return early in switch_screen_mode() on error

When the selected screen does not exist, return before calling
close().

15 years agoscreen: added macro NUM_SCREENS
Max Kellermann [Wed, 17 Sep 2008 10:08:03 +0000 (12:08 +0200)]
screen: added macro NUM_SCREENS

Since the number of screens is known at compile time, define a macro
which calculates this, instead of having a sentinel element.

15 years agoscreen: close only current screen in screen_exit()
Max Kellermann [Wed, 17 Sep 2008 10:07:32 +0000 (12:07 +0200)]
screen: close only current screen in screen_exit()

Screens which are not active have already been closed, or have never
been opened.  Don't call close again on them.

15 years agoscreen: don't store "screen" as a pointer
Max Kellermann [Wed, 17 Sep 2008 10:07:02 +0000 (12:07 +0200)]
screen: don't store "screen" as a pointer

There can only be onle screen struct instance at a time.  Declare it
as a static struct, instead of a pointer to the struct.  This
simplifies all accesses, and avoids the dynamic allocation.

15 years agoscreen: moved code to find_configured_screen()
Max Kellermann [Wed, 17 Sep 2008 10:06:14 +0000 (12:06 +0200)]
screen: moved code to find_configured_screen()

15 years agoscreen: mode_fn cannot be NULL, removed checks
Max Kellermann [Wed, 17 Sep 2008 10:06:11 +0000 (12:06 +0200)]
screen: mode_fn cannot be NULL, removed checks

At startup, mode_fn is initialized with &screen_playlist, and it will
never be reset to NULL.  Remove all checks.

15 years agoscreen: before calling update(), check if it is defined
Max Kellermann [Wed, 17 Sep 2008 10:06:05 +0000 (12:06 +0200)]
screen: before calling update(), check if it is defined

That seems to be a fn->paint was checked, then the code called
fn->update().  Fix this.

15 years agoscreen: removed screen_functions.get_lw()
Max Kellermann [Wed, 17 Sep 2008 10:06:04 +0000 (12:06 +0200)]
screen: removed screen_functions.get_lw()

If it is really important to set the curser, we should think of a
better way, instead of exporting one non-generic method.  For now,
just set the cursor to the origin.

15 years agoreplaced get_screen_X() with static screen_functions variable
Max Kellermann [Wed, 17 Sep 2008 10:05:02 +0000 (12:05 +0200)]
replaced get_screen_X() with static screen_functions variable

Compile time initialization saves resources, compared to run-time
initialization.  Declare all screen_function structs as global
variables, and remove all get functions.

15 years agocode style, indent with tabs III
Max Kellermann [Wed, 17 Sep 2008 10:03:43 +0000 (12:03 +0200)]
code style, indent with tabs III

Follow the same code style als MPD itself.

15 years agompdclient: call playlist_clear() in mpdclient_playlist_update()
Max Kellermann [Wed, 17 Sep 2008 05:21:30 +0000 (07:21 +0200)]
mpdclient: call playlist_clear() in mpdclient_playlist_update()

Instead of freeing the playlist with mpdclient_playlist_free(), call
playlist_clear() to empty the song list.  This fixes a segmentation
fault which occured when you cleared the playlist.

15 years agoinitial draw without delay
Max Kellermann [Tue, 16 Sep 2008 17:44:37 +0000 (19:44 +0200)]
initial draw without delay

Due to a missing refresh() call, ncmpc painted the screen after one
second.  Add refresh(), make ncmpc display immediately.

15 years agoscreen: added struct names
Max Kellermann [Tue, 16 Sep 2008 17:11:40 +0000 (19:11 +0200)]
screen: added struct names

Let us declare struct names in addition to typedef names, so we can
forward-declare them.

15 years agouse a C99 compiler
Max Kellermann [Tue, 16 Sep 2008 17:11:40 +0000 (19:11 +0200)]
use a C99 compiler

15 years agolyrics: converted in-process plugins to external programs
Max Kellermann [Tue, 16 Sep 2008 17:11:40 +0000 (19:11 +0200)]
lyrics: converted in-process plugins to external programs

In-process plugins are very problematic.  It is much easier and
flexible to move the lyrics plugins to external programs, with a
trivial protocol.  This is work in progress, among the things missing:

 - protocol specification, including exit codes
 - plugin installation
 - plugin search directory
 - run-time configuration (currently hard coded)
 - automatic polling (using glib's main loop?)
 - better and more robust error handling

15 years agouse GPtrArray instead of GArray for playlist songs
Max Kellermann [Tue, 16 Sep 2008 17:11:40 +0000 (19:11 +0200)]
use GPtrArray instead of GArray for playlist songs

15 years agoplaylist: hide direct accesses in inline functions
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
playlist: hide direct accesses in inline functions

Added functions like playlist_length(), playlist_get(),
playlist_replace(), playlist_remove().  Don't access the
mpdclient_playlist struct directly.

15 years agompdclient: added mpdclient_playlist_init(), mpdclient_playlist_clear()
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
mpdclient: added mpdclient_playlist_init(), mpdclient_playlist_clear()

Moved code from mpdclient_new() and mpdclient_playlist_free().  In
mpdclient_disconnect(), call mpdclient_playlist_clear() instead of
mpdclient_playlist_free() (which is now called in mpdclient_free()).

15 years agompdclient: moved code to playlist.c
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
mpdclient: moved code to playlist.c

Move everything which manipulates the mpdclient_playlist struct to
playlist.c.  Many of the functions get a mpdclient pointer instead of
a playlist; this will be changed later.

The functions mpdclient_playlist_update() and
mpdclient_playlist_update_changes() stay in mpdclient.c for now, since
they are tightly connected to the client code.

15 years agosong: allocate mpd_song from glib slices
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
song: allocate mpd_song from glib slices

Since we compile ncmpc with glib, we can use its slice allocator for
efficient song allocation.  I have added a way to disable this with a
macro.

15 years agosong: use struct mpd_song
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
song: use struct mpd_song

Use a forward declared struct mpd_song instead of the typedef
mpd_Song.

15 years agolibmpdclient: moved code to song.c
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
libmpdclient: moved code to song.c

Move everything which manipulates the mpd_Song struct to song.c.
Thousands of lines of too much for libmpdclient.c!

15 years agompdclient: add struct names, for forward declarations
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
mpdclient: add struct names, for forward declarations

To relax the include dependencies, give all structs real names, in
addition to the typedef names.  This way, other headers can
forward-declare them, and do not need to include mpdclient.h.  In the
future, the typedefs will be removed.

15 years agolibmpdclient: const pointers
Max Kellermann [Tue, 16 Sep 2008 17:11:39 +0000 (19:11 +0200)]
libmpdclient: const pointers

Pass const pointers whenever possible.

15 years agocode style, indent with tabs II
Max Kellermann [Tue, 16 Sep 2008 17:11:36 +0000 (19:11 +0200)]
code style, indent with tabs II

Follow the same code style als MPD itself.

15 years agolist_window: update variables without looping
Max Kellermann [Tue, 16 Sep 2008 16:52:55 +0000 (18:52 +0200)]
list_window: update variables without looping

Apparently, somebody was too lazy to derive the formulas for cursor
movement, and wrote lots of while loops.

15 years agoinclude cleanup
Max Kellermann [Tue, 16 Sep 2008 16:52:55 +0000 (18:52 +0200)]
include cleanup

Include only headers which are really used.

15 years agodon't use libncursesw if libncurses was selected
Max Kellermann [Tue, 16 Sep 2008 16:52:54 +0000 (18:52 +0200)]
don't use libncursesw if libncurses was selected

No idea what this code was intended for, but if the user chooses
libncurses, ncmpc shouldn't override this manual choice if it finds
libncursesw.

15 years agoadded myself to AUTHORS
Max Kellermann [Tue, 16 Sep 2008 16:52:54 +0000 (18:52 +0200)]
added myself to AUTHORS

15 years agoset version to 0.12~git
Max Kellermann [Tue, 16 Sep 2008 16:52:54 +0000 (18:52 +0200)]
set version to 0.12~git

We are on git now, and since we are doing major changes, increase the
version number.

15 years agoeasy_download: fixed the type of write_data()
Max Kellermann [Mon, 15 Sep 2008 11:27:33 +0000 (13:27 +0200)]
easy_download: fixed the type of write_data()

Fix the type of write_data() to fit curl_write_callback.

15 years agouse GArray for playlist instead of GList
Max Kellermann [Mon, 15 Sep 2008 11:27:33 +0000 (13:27 +0200)]
use GArray for playlist instead of GList

Using a doubly linked list for the local playlist copy is a huge waste
of both memory and CPU cycles.  Use GArray instead of GList, which is
much faster in this case.

15 years agofree info entity while iterating
Max Kellermann [Mon, 15 Sep 2008 11:27:33 +0000 (13:27 +0200)]
free info entity while iterating

Memory leak: the function mpdclient_playlist_update_changes() did not
free the entity which was returned by mpd_getNextInfoEntity().  Add a
mpd_freeInfoEntity() call at the end of each iteration.

15 years agomanage tag string allocations in a pool
Max Kellermann [Mon, 15 Sep 2008 11:27:33 +0000 (13:27 +0200)]
manage tag string allocations in a pool

There are many duplicated strings in the tag database, e.g. many songs
having the same artist.  Don't allocate such strings twice, manage all
strings in a pool.