Skip to content

Commit

Permalink
Merge pull request #27 from jcorporation/devel
Browse files Browse the repository at this point in the history
Merge devel into master
  • Loading branch information
jcorporation authored Aug 6, 2018
2 parents 14e96a8 + 874103b commit b687ffa
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 189 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.6)
project (mympd C)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
set(CPACK_PACKAGE_VERSION_MAJOR "3")
set(CPACK_PACKAGE_VERSION_MINOR "3")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_PACKAGE_VERSION_MINOR "4")
set(CPACK_PACKAGE_VERSION_PATCH "0")

if(CMAKE_BUILD_TYPE MATCHES RELEASE)
set(ASSETS_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/htdocs")
Expand Down
4 changes: 2 additions & 2 deletions dist/htdocs/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/htdocs/index.html

Large diffs are not rendered by default.

71 changes: 39 additions & 32 deletions dist/htdocs/js/mpd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/htdocs/sw.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion htdocs/css/mpd.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ main {
}

a.card-img-top {
height:250px;
overflow:hidden;
display:block;
}
Expand Down
217 changes: 120 additions & 97 deletions htdocs/index.html

Large diffs are not rendered by default.

219 changes: 174 additions & 45 deletions htdocs/js/mpd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion htdocs/sw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var CACHE = 'myMPD-cache-v3.3.0';
var CACHE = 'myMPD-cache-v3.4.0';
var urlsToCache = [
'/',
'/player.html',
Expand Down
71 changes: 65 additions & 6 deletions src/mpd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
unsigned int uint_buf1, uint_buf2, uint_rc;
int je, int_buf, int_rc;
float float_buf;
char *p_charbuf1, *p_charbuf2;
char *p_charbuf1, *p_charbuf2, *p_charbuf3;
struct mympd_state { int a; int b; } state = { .a = 0, .b = 0 };
enum mpd_cmd_ids cmd_id;

Expand Down Expand Up @@ -162,10 +162,13 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
mpd_run_stop(mpd.conn);
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
break;
case MPD_API_RM_ALL:
case MPD_API_QUEUE_CLEAR:
mpd_run_clear(mpd.conn);
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
break;
case MPD_API_QUEUE_CROP:
n = mympd_queue_crop(mpd.buf);
break;
case MPD_API_RM_TRACK:
je = json_scanf(msg.p, msg.len, "{ data: { track:%u } }", &uint_buf1);
if (je == 1) {
Expand Down Expand Up @@ -403,8 +406,21 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
n = mympd_search_add(mpd.buf, p_charbuf1, p_charbuf2);
free(p_charbuf1);
free(p_charbuf2);
if (n == 0)
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
}
break;
case MPD_API_SEARCH_ADD_PLIST:
je = json_scanf(msg.p, msg.len, "{ data: { plist:%Q, filter:%Q, searchstr:%Q } }", &p_charbuf1, &p_charbuf2, &p_charbuf3);
if (je == 3) {
n = mympd_search_add_plist(p_charbuf1, p_charbuf2, p_charbuf3);
free(p_charbuf1);
free(p_charbuf2);
free(p_charbuf3);
if (n == 0)
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
}
break;
case MPD_API_SEARCH:
je = json_scanf(msg.p, msg.len, "{ data: { offset:%u, mpdtag:%Q, searchstr:%Q } }", &uint_buf1, &p_charbuf1, &p_charbuf2);
if (je == 3) {
Expand Down Expand Up @@ -1264,11 +1280,10 @@ int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *sear
return len;
}

int mympd_search_add(char *buffer,char *mpdtagtype, char *searchstr) {
int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr) {
int len = 0;
struct mpd_song *song;
int len;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
len = 0;

if (mpd_search_add_db_songs(mpd.conn, false) == false) {
RETURN_ERROR_AND_RECOVER("mpd_search_add_db_songs");
Expand All @@ -1295,12 +1310,56 @@ int mympd_search_add(char *buffer,char *mpdtagtype, char *searchstr) {
return len;
}

int mympd_search_add_plist(char *plist, char *mpdtagtype, char *searchstr) {
int len = 0;
struct mpd_pair *pair;

mpd_send_command(mpd.conn, "searchaddpl", plist, mpdtagtype, searchstr, NULL);

while ((pair = mpd_recv_pair(mpd.conn)) != NULL) {
mpd_return_pair(mpd.conn, pair);
}

if (len > MAX_SIZE)
fprintf(stderr,"Buffer truncated\n");
return len;
}

int mympd_queue_crop(char *buffer) {
int len = 0;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
struct mpd_status *status = mpd_run_status(mpd.conn);
int length = mpd_status_get_queue_length(status) - 1;
int playing_song_pos = mpd_status_get_song_pos(status);

mpd_status_free(status);

if (length < 0) {
len = json_printf(&out, "{ type: error, data: %Q }", "A playlist longer than 1 song in length is required to crop.");
}
else if (mpd_status_get_state(status) == MPD_STATE_PLAY || mpd_status_get_state(status) == MPD_STATE_PAUSE) {
playing_song_pos++;
if (playing_song_pos < length)
mpd_run_delete_range(mpd.conn, playing_song_pos, -1);
playing_song_pos--;
if (playing_song_pos > 0 )
mpd_run_delete_range(mpd.conn, 0, playing_song_pos--);
len = json_printf(&out, "{ type: result, data: ok }");
} else {
len = json_printf(&out, "{ type: error, data: %Q }", "You need to be playing to crop the playlist");
}

if (len > MAX_SIZE)
fprintf(stderr,"Buffer truncated\n");
return len;
}

int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr) {
struct mpd_song *song;
unsigned long entity_count = 0;
unsigned long entities_returned = 0;
int len;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);

if (mpd_search_queue_songs(mpd.conn, false) == false) {
RETURN_ERROR_AND_RECOVER("mpd_search_queue_songs");
Expand Down
6 changes: 5 additions & 1 deletion src/mpd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
X(MPD_API_SAVE_QUEUE) \
X(MPD_API_RM_TRACK) \
X(MPD_API_RM_RANGE) \
X(MPD_API_RM_ALL) \
X(MPD_API_QUEUE_CLEAR) \
X(MPD_API_QUEUE_CROP) \
X(MPD_API_MOVE_TRACK) \
X(MPD_API_SEARCH_QUEUE) \
X(MPD_API_SEARCH_ADD_PLIST) \
X(MPD_API_SEARCH_ADD) \
X(MPD_API_SEARCH) \
X(MPD_API_SEND_MESSAGE) \
Expand Down Expand Up @@ -145,6 +147,7 @@ int mympd_put_queue(char *buffer, unsigned int offset);
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr);
int mympd_search_add_plist(char *plist, char *mpdtagtype, char *searchstr);
int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
int mympd_put_welcome(char *buffer);
int mympd_get_stats(char *buffer);
Expand All @@ -154,6 +157,7 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album);
int mympd_put_playlists(char *buffer, unsigned int offset, char *filter);
int mympd_put_playlist_list(char *buffer, char *uri, unsigned int offset, char *filter);
int mympd_put_songdetails(char *buffer, char *uri);
int mympd_queue_crop(char *buffer);
void mympd_disconnect();
#endif

0 comments on commit b687ffa

Please sign in to comment.