Switch to unified view

a/upmpd/ohplaylist.cxx b/upmpd/ohplaylist.cxx
...
...
117
    return tstate;
117
    return tstate;
118
}
118
}
119
119
120
// The data format for id lists is an array of msb 32 bits ints
120
// The data format for id lists is an array of msb 32 bits ints
121
// encoded in base64...
121
// encoded in base64...
122
static string translateIdArray(const vector<unsigned int>& in)
122
static string translateIdArray(const vector<UpSong>& in)
123
{
123
{
124
    string out1;
124
    string out1;
125
    string sdeb;
125
    string sdeb;
126
    for (auto val : in) {
126
    for (auto us : in) {
127
        unsigned int val = us.mpdid;
128
        if (val) {
127
        out1 += (unsigned char) ((val & 0xff000000) >> 24);
129
            out1 += (unsigned char) ((val & 0xff000000) >> 24);
128
        out1 += (unsigned char) ((val & 0x00ff0000) >> 16);
130
            out1 += (unsigned char) ((val & 0x00ff0000) >> 16);
129
        out1 += (unsigned char) ((val & 0x0000ff00) >> 8);
131
            out1 += (unsigned char) ((val & 0x0000ff00) >> 8);
130
        out1 += (unsigned char) ((val & 0x000000ff));
132
            out1 += (unsigned char) ((val & 0x000000ff));
133
        }
131
        //sdeb += SoapArgs::i2s(val) + " ";
134
        //sdeb += SoapArgs::i2s(val) + " ";
132
    }
135
    }
133
    //LOGDEB("OHPlaylist: current ids: " << sdeb << endl);
136
    //LOGDEB("OHPlaylist: current ids: " << sdeb << endl);
134
    return base64_encode(out1);
137
    return base64_encode(out1);
135
}
138
}
136
string OHPlaylist::makeIdArray()
139
string OHPlaylist::makeIdArray()
137
{
140
{
138
    string out;
141
    string out;
139
    vector<unsigned int> vids;
142
140
    // Retrieve the ids for current queue songs from mpd, and translate format
143
    // Retrieve the data for current queue songs from mpd, and make an
144
    // ohPlaylist id array.
145
    vector<UpSong> vdata;
141
    bool ok = m_dev->m_mpdcli->getQueueIds(vids);
146
    bool ok = m_dev->m_mpdcli->getQueueData(vdata);
142
    if (ok) {
147
    if (ok) {
143
        out = translateIdArray(vids);
148
        out = translateIdArray(vdata);
144
    }
149
    }
145
150
146
    // Clear metadata cache: entries not in vids are not valid any more
151
    // Update metadata cache: entries not in the curren id list are
152
    // not valid any more. Also there may be entries which were added
153
    // through an MPD client and which don't know about, record the
154
    // metadata for these. We don't update the current array, but
147
    // We just build a new cache for data about current entries
155
    // just build a new cache for data about current entries
148
    unordered_map<int, string> nmeta;
156
    unordered_map<int, string> nmeta;
149
    for (auto& id : vids) {
157
    for (auto& usong : vdata) {
150
        auto inold = m_metacache.find(id);
158
        auto inold = m_metacache.find(usong.mpdid);
151
        if (inold != m_metacache.end())
159
        if (inold != m_metacache.end())
152
            nmeta[id].swap(inold->second);
160
            nmeta[usong.mpdid].swap(inold->second);
161
        else
162
            nmeta[usong.mpdid] = didlmake(usong);
153
    }
163
    }
154
    m_metacache = nmeta;
164
    m_metacache = nmeta;
155
165
156
    return out;
166
    return out;
157
}
167
}