Switch to unified view

a/upmpd/mpdcli.cxx b/upmpd/mpdcli.cxx
...
...
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
        updSong(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
        updSong(m_stat.nextsong, m_stat.songpos + 1);
163
        statSong(m_stat.nextsong, m_stat.songpos + 1);
164
    }
164
    }
165
165
166
    m_stat.songelapsedms = mpd_status_get_elapsed_ms(mpds);
166
    m_stat.songelapsedms = mpd_status_get_elapsed_ms(mpds);
167
    m_stat.songlenms = mpd_status_get_total_time(mpds) * 1000;
167
    m_stat.songlenms = mpd_status_get_total_time(mpds) * 1000;
168
    m_stat.kbrate = mpd_status_get_kbit_rate(mpds);
168
    m_stat.kbrate = mpd_status_get_kbit_rate(mpds);
...
...
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::updSong(unordered_map<string, string>& tsong, int pos)
187
bool MPDCli::statSong(unordered_map<string, string>& tsong, int pos, bool isid)
188
{
188
{
189
    // LOGDEB("MPDCli::updSong" << endl);
189
    // LOGDEB("MPDCli::updSong" << endl);
190
    tsong.clear();
190
    tsong.clear();
191
    if (!ok())
191
    if (!ok())
192
        return false;
192
        return false;
193
193
194
    struct mpd_song *song;
194
    struct mpd_song *song;
195
    if (isid == false) {
195
    if (pos == -1) {
196
        if (pos == -1) {
196
        RETRY_CMD(song = mpd_run_current_song(M_CONN));
197
            RETRY_CMD(song = mpd_run_current_song(M_CONN));
198
        } else {
199
            RETRY_CMD(song = mpd_run_get_queue_song_pos(M_CONN, 
200
                                                        (unsigned int)pos));
201
        }
197
    } else {
202
    } else {
198
        RETRY_CMD(song = mpd_run_get_queue_song_pos(M_CONN, (unsigned int)pos));
203
        RETRY_CMD(song = mpd_run_get_queue_song_id(M_CONN, (unsigned int)pos));
199
    }
204
    }
205
        
200
        
206
        
201
    if (song == 0) {
207
    if (song == 0) {
202
        LOGERR("mpd_run_current_song failed" << endl);
208
        LOGERR("mpd_run_current_song failed" << endl);
203
        return false;
209
        return false;
204
    }
210
    }
...
...
285
        return false;
291
        return false;
286
    RETRY_CMD(mpd_run_toggle_pause(M_CONN));
292
    RETRY_CMD(mpd_run_toggle_pause(M_CONN));
287
    return true;
293
    return true;
288
}
294
}
289
295
296
bool MPDCli::pause(bool onoff)
297
{
298
    LOGDEB("MPDCli::pause" << endl);
299
    if (!ok())
300
        return false;
301
    RETRY_CMD(mpd_run_pause(M_CONN, onoff));
302
    return true;
303
}
304
290
bool MPDCli::play(int pos)
305
bool MPDCli::play(int pos)
291
{
306
{
292
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
307
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
293
    if (!ok())
308
    if (!ok())
294
        return false;
309
        return false;
...
...
297
    } else {
312
    } else {
298
        RETRY_CMD(mpd_run_play(M_CONN));
313
        RETRY_CMD(mpd_run_play(M_CONN));
299
    }
314
    }
300
    return updStatus();
315
    return updStatus();
301
}
316
}
317
318
bool MPDCli::playId(int id)
319
{
320
    LOGDEB("MPDCli::playId(id=" << id << ")" << endl);
321
    if (!ok())
322
        return false;
323
    RETRY_CMD(mpd_run_play_id(M_CONN, (unsigned int)id));
324
    return updStatus();
325
}
302
bool MPDCli::stop()
326
bool MPDCli::stop()
303
{
327
{
304
    LOGDEB("MPDCli::stop" << endl);
328
    LOGDEB("MPDCli::stop" << endl);
305
    if (!ok())
329
    if (!ok())
306
        return false;
330
        return false;
...
...
387
        return -1;
411
        return -1;
388
412
389
    RETRY_CMD(mpd_run_delete_id(M_CONN, (unsigned)id));
413
    RETRY_CMD(mpd_run_delete_id(M_CONN, (unsigned)id));
390
    return true;
414
    return true;
391
}
415
}
416
392
bool MPDCli::statId(int id)
417
bool MPDCli::statId(int id)
393
{
418
{
394
    LOGDEB("MPDCli::statId " << id << endl);
419
    LOGDEB("MPDCli::statId " << id << endl);
395
    if (!ok())
420
    if (!ok())
396
        return -1;
421
        return -1;
...
...
400
        mpd_song_free(song);
425
        mpd_song_free(song);
401
        return true;
426
        return true;
402
    }
427
    }
403
    return false;
428
    return false;
404
}
429
}
430
431
bool MPDCli::getQueueSongs(vector<mpd_song*>& songs)
432
{
433
    songs.clear();
434
435
    RETRY_CMD(mpd_send_list_queue_meta(M_CONN));
436
437
    struct mpd_song *song;
438
    while ((song = mpd_recv_song(M_CONN)) != NULL) {
439
        songs.push_back(song);
440
    }
441
442
    if (!mpd_response_finish(M_CONN)) {
443
        LOGERR("MPDCli::getQueueSongs: mpd_list_queue_meta failed"<< endl);
444
        return false;
445
    }
446
    return true;
447
}
448
449
void MPDCli::freeSongs(vector<mpd_song*>& songs)
450
{
451
    for (vector<mpd_song*>::iterator it = songs.begin();
452
         it != songs.end(); it++) {
453
        mpd_song_free(*it);
454
    }
455
}
456
405
int MPDCli::curpos()
457
int MPDCli::curpos()
406
{
458
{
407
    if (!updStatus())
459
    if (!updStatus())
408
        return -1;
460
        return -1;
409
    LOGDEB("MPDCli::curpos: pos: " << m_stat.songpos << " id " 
461
    LOGDEB("MPDCli::curpos: pos: " << m_stat.songpos << " id "