Switch to unified view

a/upmpd/mpdcli.cxx b/upmpd/mpdcli.cxx
...
...
152
    m_stat.mixrampdb = mpd_status_get_mixrampdb(mpds);
152
    m_stat.mixrampdb = mpd_status_get_mixrampdb(mpds);
153
    m_stat.mixrampdelay = mpd_status_get_mixrampdelay(mpds);
153
    m_stat.mixrampdelay = mpd_status_get_mixrampdelay(mpds);
154
    m_stat.songpos = mpd_status_get_song_pos(mpds);
154
    m_stat.songpos = mpd_status_get_song_pos(mpds);
155
    m_stat.songid = mpd_status_get_song_id(mpds);
155
    m_stat.songid = mpd_status_get_song_id(mpds);
156
    if (m_stat.songpos >= 0) {
156
    if (m_stat.songpos >= 0) {
157
        string prevuri = m_stat.currentsong["uri"];
157
        string prevuri = m_stat.currentsong.uri;
158
        statSong(m_stat.currentsong);
158
        statSong(m_stat.currentsong);
159
        if (m_stat.currentsong["uri"].compare(prevuri)) {
159
        if (m_stat.currentsong.uri.compare(prevuri)) {
160
            m_stat.trackcounter++;
160
            m_stat.trackcounter++;
161
            m_stat.detailscounter = 0;
161
            m_stat.detailscounter = 0;
162
        }
162
        }
163
        statSong(m_stat.nextsong, m_stat.songpos + 1);
163
        statSong(m_stat.nextsong, m_stat.songpos + 1);
164
    }
164
    }
...
...
182
182
183
    mpd_status_free(mpds);
183
    mpd_status_free(mpds);
184
    return true;
184
    return true;
185
}
185
}
186
186
187
bool MPDCli::statSong(unordered_map<string, string>& tsong, int pos, bool isid)
187
bool MPDCli::statSong(UpSong& upsong, int pos, bool isid)
188
{
188
{
189
    // LOGDEB("MPDCli::updSong" << endl);
189
    // LOGDEB("MPDCli::statSong" << endl);
190
    tsong.clear();
191
    if (!ok())
190
    if (!ok())
192
        return false;
191
        return false;
193
192
194
    struct mpd_song *song;
193
    struct mpd_song *song;
195
    if (isid == false) {
194
    if (isid == false) {
...
...
200
                                                        (unsigned int)pos));
199
                                                        (unsigned int)pos));
201
        }
200
        }
202
    } else {
201
    } else {
203
        RETRY_CMD(song = mpd_run_get_queue_song_id(M_CONN, (unsigned int)pos));
202
        RETRY_CMD(song = mpd_run_get_queue_song_id(M_CONN, (unsigned int)pos));
204
    }
203
    }
205
        
206
        
207
    if (song == 0) {
204
    if (song == 0) {
208
        LOGERR("mpd_run_current_song failed" << endl);
205
        LOGERR("mpd_run_current_song failed" << endl);
209
        return false;
206
        return false;
210
    }
207
    }
208
    bool ret = mapSong(upsong, song);
209
    mpd_song_free(song);
210
    return ret;
211
}    
211
212
213
bool  MPDCli::mapSong(UpSong& upsong, struct mpd_song *song)
214
{
212
    const char *cp;
215
    const char *cp;
216
217
    upsong.clear();
218
219
    cp = mpd_song_get_uri(song);
220
    if (cp != 0)
221
        upsong.uri = cp;
222
213
    cp = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
223
    cp = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
214
    if (cp != 0)
224
    if (cp != 0)
215
        tsong["upnp:artist"] = cp;
225
        upsong.artist = cp;
216
226
217
    cp = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
227
    cp = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
218
    if (cp != 0)
228
    if (cp != 0)
219
        tsong["upnp:album"] = cp;
229
        upsong.album = cp;
220
230
221
    cp = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
231
    cp = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
222
    if (cp != 0) {
232
    if (cp != 0) 
223
        tsong["dc:title"] = cp;
233
        upsong.title = cp;
224
    }
225
234
226
    cp = mpd_song_get_tag(song, MPD_TAG_TRACK, 0);
235
    cp = mpd_song_get_tag(song, MPD_TAG_TRACK, 0);
227
    if (cp != 0)
236
    if (cp != 0)
228
        tsong["upnp:originalTrackNumber"] = cp;
237
        upsong.tracknum = cp;
229
238
230
    cp = mpd_song_get_tag(song, MPD_TAG_GENRE, 0);
239
    cp = mpd_song_get_tag(song, MPD_TAG_GENRE, 0);
231
    if (cp != 0)
240
    if (cp != 0)
232
        tsong["upnp:genre"] = cp;
241
        upsong.genre = cp;
233
    
242
243
    upsong.duration_secs = mpd_song_get_duration(song);
234
    cp = mpd_song_get_uri(song);
244
    upsong.mpdid = mpd_song_get_id(song);
235
    if (cp != 0)
236
        tsong["uri"] = cp;
237
245
238
    mpd_song_free(song);
239
    return true;
246
    return true;
240
}
247
}
241
248
242
bool MPDCli::setVolume(int volume, bool isMute)
249
bool MPDCli::setVolume(int volume, bool isMute)
243
{
250
{
...
...
393
    int id;
400
    int id;
394
    RETRY_CMD((id=mpd_run_add_id_to(M_CONN, uri.c_str(), (unsigned)pos))!=-1);
401
    RETRY_CMD((id=mpd_run_add_id_to(M_CONN, uri.c_str(), (unsigned)pos))!=-1);
395
402
396
    return id;
403
    return id;
397
}
404
}
405
406
bool MPDCli::insertAfterId(const string& uri, int id)
407
{
408
    LOGDEB("MPDCli::insertAfterId: id " << id << " uri " << uri << endl);
409
    if (!ok())
410
        return -1;
411
412
    if (!updStatus())
413
        return -1;
414
415
    // id == 0 means insert at start
416
    if (id == 0) {
417
        return insert(uri, 0) != -1;
418
    }
419
420
    vector<mpd_song*> songs;
421
    if (!getQueueSongs(songs)) {
422
        return false;
423
    }
424
    bool ok = false;
425
    for (unsigned int pos = 0; pos < songs.size(); pos++) {
426
        unsigned int qid = mpd_song_get_id(songs[pos]);
427
        if (qid == (unsigned int)id) {
428
            ok = insert(uri, pos+1) != -1;
429
            break;
430
        }
431
    }
432
    freeSongs(songs);
433
    return ok;
434
}
435
398
bool MPDCli::clearQueue()
436
bool MPDCli::clearQueue()
399
{
437
{
400
    LOGDEB("MPDCli::clearQueue " << endl);
438
    LOGDEB("MPDCli::clearQueue " << endl);
401
    if (!ok())
439
    if (!ok())
402
        return -1;
440
        return -1;
...
...
450
{
488
{
451
    for (vector<mpd_song*>::iterator it = songs.begin();
489
    for (vector<mpd_song*>::iterator it = songs.begin();
452
         it != songs.end(); it++) {
490
         it != songs.end(); it++) {
453
        mpd_song_free(*it);
491
        mpd_song_free(*it);
454
    }
492
    }
493
}
494
bool MPDCli::getQueueIds(std::vector<unsigned int>& vids)
495
{
496
    vector<mpd_song*> songs;
497
    if (!getQueueSongs(songs)) {
498
        return false;
499
    }
500
    vids.reserve(songs.size());
501
    for (unsigned int pos = 0; pos < songs.size(); pos++) {
502
        vids.push_back(mpd_song_get_id(songs[pos]));
503
    }
504
    freeSongs(songs);
505
    return true;
455
}
506
}
456
507
457
int MPDCli::curpos()
508
int MPDCli::curpos()
458
{
509
{
459
    if (!updStatus())
510
    if (!updStatus())