Fixing up the documentation, regrouping and adding missing descriptions.
[libmpd.git] / src / libmpd-playlist.c
bloba82701121666fcd6b49facd148f3b305c9893468
1 /*
2 *Copyright (C) 2004-2007 Qball Cow <Qball@qballcow.nl>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #define __USE_GNU
24 #include <string.h>
25 #include <regex.h>
26 #include <stdarg.h>
27 #include <config.h>
28 #include "debug_printf.h"
29 #include "libmpd.h"
30 #include "libmpd-internal.h"
33 int mpd_playlist_get_playlist_length(MpdObj *mi)
35 if(!mpd_check_connected(mi))
37 debug_printf(DEBUG_WARNING,"not connected\n");
38 return MPD_NOT_CONNECTED;
40 if(mpd_status_check(mi) != MPD_OK)
42 debug_printf(DEBUG_ERROR,"Failed grabbing status\n");
43 return MPD_STATUS_FAILED;
45 return mi->status->playlistLength;
48 long long mpd_playlist_get_old_playlist_id(MpdObj *mi)
50 return mi->OldState.playlistid;
53 long long mpd_playlist_get_playlist_id(MpdObj *mi)
55 if(!mpd_check_connected(mi))
57 debug_printf(DEBUG_WARNING,"not connected\n");
58 return MPD_NOT_CONNECTED;
60 if(mpd_status_check(mi) != MPD_OK)
62 debug_printf(DEBUG_WARNING,"Failed grabbing status\n");
63 return MPD_STATUS_FAILED;
65 return mi->status->playlist;
67 int mpd_playlist_add(MpdObj *mi, char *path)
69 int retv = mpd_playlist_queue_add(mi, path);
70 if(retv != MPD_OK) return retv;
71 return mpd_playlist_queue_commit(mi);
74 int mpd_playlist_delete_id(MpdObj *mi, int songid)
76 int retv = mpd_playlist_queue_delete_id(mi, songid);
77 if(retv != MPD_OK) return retv;
78 return mpd_playlist_queue_commit(mi);
81 int mpd_playlist_delete_pos(MpdObj *mi, int songpos)
83 int retv = mpd_playlist_queue_delete_pos(mi, songpos);
84 if(retv != MPD_OK) return retv;
85 return mpd_playlist_queue_commit(mi);
87 /*******************************************************************************
88 * PLAYLIST
90 mpd_Song * mpd_playlist_get_song(MpdObj *mi, int songid)
92 mpd_Song *song = NULL;
93 mpd_InfoEntity *ent = NULL;
94 if(songid < 0){
95 debug_printf(DEBUG_ERROR, "songid < 0 Failed");
96 return NULL;
98 if(!mpd_check_connected(mi))
100 debug_printf(DEBUG_ERROR, "Not Connected\n");
101 return NULL;
104 if(mpd_lock_conn(mi))
106 return NULL;
108 debug_printf(DEBUG_INFO, "Trying to grab song with id: %i\n", songid);
109 mpd_sendPlaylistIdCommand(mi->connection, songid);
110 ent = mpd_getNextInfoEntity(mi->connection);
111 mpd_finishCommand(mi->connection);
113 if(mpd_unlock_conn(mi))
115 if(ent) mpd_freeInfoEntity(ent);
116 return NULL;
119 if(ent == NULL)
121 debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n");
122 return NULL;
125 if(ent->type != MPD_INFO_ENTITY_TYPE_SONG)
127 mpd_freeInfoEntity(ent);
128 debug_printf(DEBUG_ERROR, "Failed to grab correct song type from mpd\n");
129 return NULL;
131 song = ent->info.song;
132 ent->info.song = NULL;
134 mpd_freeInfoEntity(ent);
136 return song;
139 mpd_Song * mpd_playlist_get_song_from_pos(MpdObj *mi, int songpos)
141 mpd_Song *song = NULL;
142 mpd_InfoEntity *ent = NULL;
143 if(songpos < 0){
144 debug_printf(DEBUG_ERROR, "songpos < 0 Failed");
145 return NULL;
147 if(!mpd_check_connected(mi))
149 debug_printf(DEBUG_ERROR, "Not Connected\n");
150 return NULL;
153 if(mpd_lock_conn(mi))
155 return NULL;
157 debug_printf(DEBUG_INFO, "Trying to grab song with id: %i\n", songpos);
158 mpd_sendPlaylistInfoCommand(mi->connection, songpos);
159 ent = mpd_getNextInfoEntity(mi->connection);
160 mpd_finishCommand(mi->connection);
162 if(mpd_unlock_conn(mi))
164 /*TODO free entity. for now this can never happen */
165 return NULL;
168 if(ent == NULL)
170 debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n");
171 return NULL;
174 if(ent->type != MPD_INFO_ENTITY_TYPE_SONG)
176 mpd_freeInfoEntity(ent);
177 debug_printf(DEBUG_ERROR, "Failed to grab corect song type from mpd\n");
178 return NULL;
180 song = ent->info.song;
181 ent->info.song = NULL;
183 mpd_freeInfoEntity(ent);
185 return song;
188 mpd_Song * mpd_playlist_get_current_song(MpdObj *mi)
190 if(!mpd_check_connected(mi))
192 debug_printf(DEBUG_ERROR, "Not Connected\n");
193 return NULL;
196 if(mpd_status_check(mi) != MPD_OK)
198 debug_printf(DEBUG_ERROR, "Failed to check status\n");
199 return NULL;
202 if(mi->CurrentSong != NULL && mi->CurrentSong->id != mi->status->songid)
204 debug_printf(DEBUG_WARNING, "Current song not up2date, updating\n");
205 mpd_freeSong(mi->CurrentSong);
206 mi->CurrentSong = NULL;
208 /* only update song when playing/pasing */
209 if(mi->CurrentSong == NULL &&
210 (mpd_player_get_state(mi) != MPD_PLAYER_STOP && mpd_player_get_state(mi) != MPD_PLAYER_UNKNOWN))
212 /* TODO: this to use the geT_current_song_id function */
213 mi->CurrentSong = mpd_playlist_get_song(mi, mpd_player_get_current_song_id(mi));
214 if(mi->CurrentSong == NULL)
216 debug_printf(DEBUG_ERROR, "Failed to grab song\n");
217 return NULL;
220 return mi->CurrentSong;
223 int mpd_playlist_clear(MpdObj *mi)
225 if(!mpd_check_connected(mi))
227 debug_printf(DEBUG_WARNING,"not connected\n");
228 return MPD_NOT_CONNECTED;
230 if(mpd_lock_conn(mi))
232 debug_printf(DEBUG_WARNING,"lock failed\n");
233 return MPD_LOCK_FAILED;
236 mpd_sendClearCommand(mi->connection);
237 mpd_finishCommand(mi->connection);
238 /* hack to make it update correctly when replacing 1 song */
239 mi->CurrentState.songid = -1;
240 /* unlock */
241 mpd_unlock_conn(mi);
242 mpd_status_update(mi);
243 return FALSE;
246 int mpd_playlist_shuffle(MpdObj *mi)
248 if(!mpd_check_connected(mi))
250 debug_printf(DEBUG_WARNING,"not connected\n");
251 return MPD_NOT_CONNECTED;
253 if(mpd_lock_conn(mi))
255 debug_printf(DEBUG_ERROR,"lock failed\n");
256 return MPD_LOCK_FAILED;
259 mpd_sendShuffleCommand(mi->connection);
260 mpd_finishCommand(mi->connection);
262 /* unlock */
263 mpd_unlock_conn(mi);
264 return FALSE;
269 int mpd_playlist_move_id(MpdObj *mi, int old_id, int new_id)
271 if(!mpd_check_connected(mi))
273 debug_printf(DEBUG_WARNING,"not connected\n");
274 return MPD_NOT_CONNECTED;
276 if(mpd_lock_conn(mi))
278 debug_printf(DEBUG_ERROR,"lock failed\n");
279 return MPD_LOCK_FAILED;
282 mpd_sendMoveIdCommand(mi->connection,old_id, new_id);
283 mpd_finishCommand(mi->connection);
285 /* unlock */
286 mpd_unlock_conn(mi);
287 return MPD_OK;
290 int mpd_playlist_move_pos(MpdObj *mi, int old_pos, int new_pos)
292 if(!mpd_check_connected(mi))
294 debug_printf(DEBUG_WARNING,"not connected\n");
295 return MPD_NOT_CONNECTED;
297 if(mpd_lock_conn(mi))
299 debug_printf(DEBUG_ERROR,"lock failed\n");
300 return MPD_LOCK_FAILED;
303 mpd_sendMoveCommand(mi->connection,old_pos, new_pos);
304 mpd_finishCommand(mi->connection);
306 /* unlock */
307 mpd_unlock_conn(mi);
308 return MPD_OK;
311 MpdData * mpd_playlist_get_changes(MpdObj *mi,int old_playlist_id)
313 MpdData *data = NULL;
314 mpd_InfoEntity *ent = NULL;
315 if(!mpd_check_connected(mi))
317 debug_printf(DEBUG_WARNING,"not connected\n");
318 return NULL;
320 if(mpd_lock_conn(mi))
322 debug_printf(DEBUG_WARNING,"lock failed\n");
323 return NULL;
326 if(old_playlist_id == -1)
328 debug_printf(DEBUG_INFO,"get fresh playlist\n");
329 mpd_sendPlChangesCommand (mi->connection, 0);
330 /* mpd_sendPlaylistIdCommand(mi->connection, -1); */
332 else
334 mpd_sendPlChangesCommand (mi->connection, old_playlist_id);
337 while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
339 if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
341 data = mpd_new_data_struct_append(data);
342 data->type = MPD_DATA_TYPE_SONG;
343 data->song = ent->info.song;
344 ent->info.song = NULL;
346 mpd_freeInfoEntity(ent);
348 mpd_finishCommand(mi->connection);
350 /* unlock */
351 if(mpd_unlock_conn(mi))
353 debug_printf(DEBUG_WARNING,"mpd_playlist_get_changes: unlock failed.\n");
354 mpd_data_free(data);
355 return NULL;
357 if(data == NULL)
359 return NULL;
361 return mpd_data_get_first(data);
366 MpdData * mpd_playlist_get_changes_posid(MpdObj *mi,int old_playlist_id)
368 MpdData *data = NULL;
369 mpd_InfoEntity *ent = NULL;
370 debug_printf(DEBUG_INFO, "Fetching using new plchangesposid command");
371 if(!mpd_check_connected(mi))
373 debug_printf(DEBUG_WARNING,"not connected\n");
374 return NULL;
376 if(mpd_lock_conn(mi))
378 debug_printf(DEBUG_WARNING,"lock failed\n");
379 return NULL;
382 if(old_playlist_id == -1)
384 debug_printf(DEBUG_INFO,"get fresh playlist\n");
385 mpd_sendPlChangesPosIdCommand (mi->connection, 0);
386 /* mpd_sendPlaylistIdCommand(mi->connection, -1); */
388 else
390 mpd_sendPlChangesPosIdCommand (mi->connection, old_playlist_id);
393 while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
395 if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
397 data = mpd_new_data_struct_append(data);
398 data->type = MPD_DATA_TYPE_SONG;
399 data->song = ent->info.song;
400 ent->info.song = NULL;
402 mpd_freeInfoEntity(ent);
404 mpd_finishCommand(mi->connection);
406 /* unlock */
407 if(mpd_unlock_conn(mi))
409 debug_printf(DEBUG_WARNING,"mpd_playlist_get_changes: unlock failed.\n");
410 mpd_data_free(data);
411 return NULL;
413 if(data == NULL)
415 return NULL;
417 return mpd_data_get_first(data);
420 int mpd_playlist_queue_add(MpdObj *mi,char *path)
422 if(!mpd_check_connected(mi))
424 debug_printf(DEBUG_WARNING,"not connected\n");
425 return MPD_NOT_CONNECTED;
427 if(path == NULL)
429 debug_printf(DEBUG_ERROR, "path != NULL Failed");
430 return MPD_ARGS_ERROR;
433 if(mi->queue == NULL)
435 mi->queue = mpd_new_queue_struct();
436 mi->queue->first = mi->queue;
437 mi->queue->next = NULL;
438 mi->queue->prev = NULL;
440 else
442 mi->queue->next = mpd_new_queue_struct();
443 mi->queue->next->first = mi->queue->first;
444 mi->queue->next->prev = mi->queue;
445 mi->queue = mi->queue->next;
446 mi->queue->next = NULL;
448 mi->queue->type = MPD_QUEUE_ADD;
449 mi->queue->path = strdup(path);
450 return MPD_OK;
453 int mpd_playlist_queue_load(MpdObj *mi,char *path)
455 if(!mpd_check_connected(mi))
457 debug_printf(DEBUG_WARNING,"not connected\n");
458 return MPD_NOT_CONNECTED;
460 if(path == NULL)
462 debug_printf(DEBUG_ERROR, "path != NULL Failed");
463 return MPD_ARGS_ERROR;
466 if(mi->queue == NULL)
468 mi->queue = mpd_new_queue_struct();
469 mi->queue->first = mi->queue;
470 mi->queue->next = NULL;
471 mi->queue->prev = NULL;
473 else
475 mi->queue->next = mpd_new_queue_struct();
476 mi->queue->next->first = mi->queue->first;
477 mi->queue->next->prev = mi->queue;
478 mi->queue = mi->queue->next;
479 mi->queue->next = NULL;
481 mi->queue->type = MPD_QUEUE_LOAD;
482 mi->queue->path = strdup(path);
483 return MPD_OK;
487 int mpd_playlist_queue_commit(MpdObj *mi)
489 if(mi->queue == NULL)
491 debug_printf(DEBUG_WARNING,"mi->queue is empty");
492 return MPD_PLAYLIST_QUEUE_EMPTY;
494 if(!mpd_check_connected(mi))
496 debug_printf(DEBUG_WARNING,"not connected\n");
497 return MPD_NOT_CONNECTED;
499 if(mpd_lock_conn(mi))
501 debug_printf(DEBUG_WARNING,"lock failed\n");
502 return MPD_LOCK_FAILED;
504 mpd_sendCommandListBegin(mi->connection);
505 /* get first item */
506 mi->queue = mi->queue->first;
507 while(mi->queue != NULL)
509 if(mi->queue->type == MPD_QUEUE_ADD)
511 if(mi->queue->path != NULL)
513 mpd_sendAddCommand(mi->connection, mi->queue->path);
516 else if(mi->queue->type == MPD_QUEUE_LOAD)
518 if(mi->queue->path != NULL)
520 mpd_sendLoadCommand(mi->connection, mi->queue->path);
523 else if (mi->queue->type == MPD_QUEUE_DELETE_ID)
525 if(mi->queue->id >= 0)
527 mpd_sendDeleteIdCommand(mi->connection, mi->queue->id);
530 else if (mi->queue->type == MPD_QUEUE_DELETE_POS)
532 if(mi->queue->id >= 0)
534 mpd_sendDeleteCommand(mi->connection, mi->queue->id);
537 else if (mi->queue->type == MPD_QUEUE_MPD_QUEUE_ADD)
539 if(mi->queue->id >= 0)
541 mpd_sendQueueIdCommand(mi->connection, mi->queue->id);
544 else if (mi->queue->type == MPD_QUEUE_MPD_QUEUE_REMOVE)
546 if(mi->queue->id >= 0)
548 mpd_sendDequeueCommand(mi->connection, mi->queue->id);
552 mpd_queue_get_next(mi);
554 mpd_sendCommandListEnd(mi->connection);
555 mpd_finishCommand(mi->connection);
556 mpd_unlock_conn(mi);
557 mpd_status_update(mi);
558 return MPD_OK;
560 int mpd_playlist_queue_delete_id(MpdObj *mi,int id)
562 if(!mpd_check_connected(mi))
564 debug_printf(DEBUG_WARNING,"not connected\n");
565 return MPD_NOT_CONNECTED;
568 if(mi->queue == NULL)
570 mi->queue = mpd_new_queue_struct();
571 mi->queue->first = mi->queue;
572 mi->queue->next = NULL;
573 mi->queue->prev = NULL;
575 else
577 mi->queue->next = mpd_new_queue_struct();
578 mi->queue->next->first = mi->queue->first;
579 mi->queue->next->prev = mi->queue;
580 mi->queue = mi->queue->next;
581 mi->queue->next = NULL;
583 mi->queue->type = MPD_QUEUE_DELETE_ID;
584 mi->queue->id = id;
585 mi->queue->path = NULL;
586 return MPD_OK;
589 int mpd_playlist_queue_delete_pos(MpdObj *mi,int songpos)
591 if(!mpd_check_connected(mi))
593 debug_printf(DEBUG_WARNING,"mpd_playlist_add: not connected\n");
594 return MPD_NOT_CONNECTED;
597 if(mi->queue == NULL)
599 mi->queue = mpd_new_queue_struct();
600 mi->queue->first = mi->queue;
601 mi->queue->next = NULL;
602 mi->queue->prev = NULL;
604 else
606 mi->queue->next = mpd_new_queue_struct();
607 mi->queue->next->first = mi->queue->first;
608 mi->queue->next->prev = mi->queue;
609 mi->queue = mi->queue->next;
610 mi->queue->next = NULL;
612 mi->queue->type = MPD_QUEUE_DELETE_POS;
613 mi->queue->id = songpos;
614 mi->queue->path = NULL;
615 return MPD_OK;
618 int mpd_playlist_add_get_id(MpdObj *mi, char *path)
620 int songid = -1;
621 if(mi == NULL || path == NULL)
623 debug_printf(DEBUG_ERROR, "mi == NULL || path == NULL failed");
624 return MPD_ARGS_ERROR;
626 if(!mpd_check_connected(mi))
628 debug_printf(DEBUG_WARNING,"mpd_playlist_add: not connected\n");
629 return MPD_NOT_CONNECTED;
631 if(mpd_lock_conn(mi))
633 debug_printf(DEBUG_WARNING,"lock failed\n");
634 return MPD_LOCK_FAILED;
636 songid = mpd_sendAddIdCommand(mi->connection, path);
637 mpd_finishCommand(mi->connection);
639 mpd_unlock_conn(mi);
640 return songid;
643 void mpd_playlist_search_start(MpdObj *mi, int exact)
646 * Check argument
648 if(mi == NULL || exact > 1 || exact < 0)
650 debug_printf(DEBUG_ERROR, "Argument error");
651 return ;
653 if(!mpd_check_connected(mi))
655 debug_printf(DEBUG_ERROR, "Not Connected\n");
656 return ;
658 if(!mpd_server_check_version(mi, 0,12,1))
660 debug_printf(DEBUG_ERROR, "Advanced search requires mpd 0.12.2 or higher");
661 return ;
663 /* lock, so we can work on mi->connection */
664 if(mpd_lock_conn(mi) != MPD_OK)
666 debug_printf(DEBUG_ERROR, "Failed to lock connection");
667 return ;
669 mpd_startPlaylistSearch(mi->connection, exact);
670 /* Set search type */
671 mi->search_type = (exact)? MPD_SEARCH_TYPE_PLAYLIST_FIND:MPD_SEARCH_TYPE_PLAYLIST_SEARCH;
672 /* unlock, let the error handler handle any possible error.
674 mpd_unlock_conn(mi);
675 return;
678 void mpd_playlist_search_add_constraint(MpdObj *mi, mpd_TagItems field,const char *value)
680 mpd_database_search_add_constraint(mi, field, value);
682 MpdData * mpd_playlist_search_commit(MpdObj *mi)
684 mpd_InfoEntity *ent = NULL;
685 MpdData *data = NULL;
686 if(!mpd_check_connected(mi))
688 debug_printf(DEBUG_WARNING,"not connected\n");
689 return NULL;
691 if(mi->search_type < MPD_SEARCH_TYPE_PLAYLIST_FIND )
693 debug_printf(DEBUG_ERROR, "no or wrong search in progress to commit");
694 return NULL;
696 if(mpd_lock_conn(mi))
698 debug_printf(DEBUG_ERROR,"lock failed\n");
699 return NULL;
701 mpd_commitSearch(mi->connection);
702 while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
704 if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
706 data = mpd_new_data_struct_append(data);
707 data->type = MPD_DATA_TYPE_SONG;
708 data->song = ent->info.song;
709 ent->info.song = NULL;
711 mpd_freeInfoEntity(ent);
713 mpd_finishCommand(mi->connection);
715 * reset search type
717 mi->search_type = MPD_SEARCH_TYPE_NONE;
718 mi->search_field = MPD_TAG_ITEM_ARTIST;
719 /* unlock */
720 if(mpd_unlock_conn(mi))
722 debug_printf(DEBUG_ERROR, "Failed to unlock connection");
723 if(data)mpd_data_free(data);
724 return NULL;
726 if(data == NULL)
728 return NULL;
730 return mpd_data_get_first(data);
733 MpdData * mpd_playlist_get_mpd_queue(MpdObj *mi)
735 MpdData *data = NULL;
736 mpd_InfoEntity *ent = NULL;
737 if(!mpd_check_connected(mi))
739 debug_printf(DEBUG_WARNING,"not connected\n");
740 return NULL;
742 if(mpd_lock_conn(mi))
744 debug_printf(DEBUG_WARNING,"lock failed\n");
745 return NULL;
748 mpd_sendQueueInfoCommand(mi->connection);
750 while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
752 if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
754 data = mpd_new_data_struct_append(data);
755 data->type = MPD_DATA_TYPE_SONG;
756 data->song = ent->info.song;
757 ent->info.song = NULL;
759 mpd_freeInfoEntity(ent);
761 mpd_finishCommand(mi->connection);
763 /* unlock */
764 if(mpd_unlock_conn(mi))
766 debug_printf(DEBUG_WARNING,"unlock failed.\n");
767 mpd_data_free(data);
768 return NULL;
770 if(data == NULL)
772 return NULL;
774 return mpd_data_get_first(data);
777 int mpd_playlist_mpd_queue_add(MpdObj *mi, int songid)
779 if(!mpd_check_connected(mi))
781 debug_printf(DEBUG_WARNING,"not connected\n");
782 return MPD_NOT_CONNECTED;
784 if(songid < 0)
786 return MPD_ARGS_ERROR;
788 if(mpd_lock_conn(mi))
790 debug_printf(DEBUG_WARNING,"lock failed\n");
791 return MPD_LOCK_FAILED;
794 mpd_sendQueueIdCommand(mi->connection,songid);
795 mpd_finishCommand(mi->connection);
796 /* unlock */
797 if(mpd_unlock_conn(mi))
799 return MPD_LOCK_FAILED;
801 /* always update the status */
802 mpd_status_queue_update(mi);
803 return MPD_OK;
805 int mpd_playlist_mpd_queue_remove(MpdObj *mi, int songpos)
807 if(!mpd_check_connected(mi))
809 debug_printf(DEBUG_WARNING,"not connected\n");
810 return MPD_NOT_CONNECTED;
812 if(songpos < 0)
814 return MPD_ARGS_ERROR;
816 if(mpd_lock_conn(mi))
818 debug_printf(DEBUG_WARNING,"lock failed\n");
819 return MPD_LOCK_FAILED;
822 mpd_sendDequeueCommand(mi->connection,songpos);
823 mpd_finishCommand(mi->connection);
824 /* unlock */
825 if(mpd_unlock_conn(mi))
827 return MPD_LOCK_FAILED;
829 /* always update the status */
830 mpd_status_queue_update(mi);
831 return MPD_OK;
834 int mpd_playlist_queue_mpd_queue_add(MpdObj *mi,int id)
836 if(!mpd_check_connected(mi))
838 debug_printf(DEBUG_WARNING,"not connected\n");
839 return MPD_NOT_CONNECTED;
842 if(mi->queue == NULL)
844 mi->queue = mpd_new_queue_struct();
845 mi->queue->first = mi->queue;
846 mi->queue->next = NULL;
847 mi->queue->prev = NULL;
849 else
851 mi->queue->next = mpd_new_queue_struct();
852 mi->queue->next->first = mi->queue->first;
853 mi->queue->next->prev = mi->queue;
854 mi->queue = mi->queue->next;
855 mi->queue->next = NULL;
857 mi->queue->type = MPD_QUEUE_MPD_QUEUE_ADD;
858 mi->queue->id = id;
859 mi->queue->path = NULL;
860 return MPD_OK;
862 int mpd_playlist_queue_mpd_queue_remove(MpdObj *mi,int pos)
864 if(!mpd_check_connected(mi))
866 debug_printf(DEBUG_WARNING,"not connected\n");
867 return MPD_NOT_CONNECTED;
870 if(mi->queue == NULL)
872 mi->queue = mpd_new_queue_struct();
873 mi->queue->first = mi->queue;
874 mi->queue->next = NULL;
875 mi->queue->prev = NULL;
877 else
879 mi->queue->next = mpd_new_queue_struct();
880 mi->queue->next->first = mi->queue->first;
881 mi->queue->next->prev = mi->queue;
882 mi->queue = mi->queue->next;
883 mi->queue->next = NULL;
885 mi->queue->type = MPD_QUEUE_MPD_QUEUE_REMOVE;
886 mi->queue->id = pos;
887 mi->queue->path = NULL;
888 return MPD_OK;