⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkmusicbrowser.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________

        FreeAmp - The Free MP3 Player

        Portions Copyright (C) 1999-2000 EMusic.com

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

        $Id: gtkmusicbrowser.cpp,v 1.126 2001/03/06 04:58:34 ijr Exp $
____________________________________________________________________________*/

#include "config.h"

#include <gtk/gtk.h>

#include <iostream>
using namespace std;

#ifdef __QNX__
#include <strings.h>
#endif

#include "utility.h"
#include "gtkmusicbrowser.h"
#include "infoeditor.h"
#include "fileselector.h"
#include "eventdata.h"
#include "player.h"
#include "musicbrowserui.h"
#include "gtkmessagedialog.h"

#ifndef NO_CDAUDIO
#include "cdaudio.h"
#include "cdpmo.h"
#endif

#include "aps.h"
#include "apsplaylist.h"

void GTKMusicBrowser::HandleSignature(void)
{
    if (m_sigsStart) {
        m_context->catalog->StartGeneratingSigs();
    }
    else {
        m_context->catalog->StopGeneratingSigs();
    }
}

void GTKMusicBrowser::AskSignatureDialog(void)
{
    GTKMessageDialog *dialog = new GTKMessageDialog();
    string caption = "Signature Tracks?";

    char numtracks[10];
    sprintf(numtracks, "%d", m_context->catalog->GetNumNeedingSigs());
    string message = "Relatable's audio recognition technology enables "
                     the_BRANDING" to create unique digital 'signatures' for "
		     "the music files on your computer. Doing so helps ensure "
                     "that you and other users receive accurate music "
                     "recommendations. Signaturing takes about 2 seconds per "
		     "music file and will work in the background. To "
		     "discontinue signaturing, select 'Stop Signaturing' from "
		     "the Relatable menu in 'My Music'. " +
                     string("Relatable will now signature ") + 
		     string(numtracks) + string(" track(s).  Proceed?");

    if (dialog->Show(message.c_str(), caption.c_str(), kMessageYesNo) ==
        kMessageReturnYes) 
    {
        m_context->catalog->StartGeneratingSigs();
    }

    delete dialog;
}

void GTKMusicBrowser::AskOptIn(bool inMain)
{
    GTKMessageDialog *dialog = new GTKMessageDialog();
    string caption = "Relatable Not Enabled";
    string message = "You didn't opt-in to use the Relatable features.  Would you like to go to the options dialog and create a profile?";

    if (dialog->Show(message.c_str(), caption.c_str(), kMessageYesNo, inMain) ==
        kMessageReturnYes)
    {
        ShowOptions(7);
    }

    delete dialog;
}

void GTKMusicBrowser::StillNeedSignature(bool inMain)
{
    GTKMessageDialog *dialog = new GTKMessageDialog();
    string caption = "Relatable Not Enabled";
    string message;

    int numstill = m_context->catalog->GetNumNeedingSigs();
    int numtotal = m_context->catalog->GetTotalNumTracks();

    int togo = (int)(numtotal * 0.75) - (numtotal - numstill);

    char numtracks[10];
    sprintf(numtracks, "%d", togo);

    if (!m_sigsStart)
        message = string("Before using any of the Relatable features, at least 75 percent of the tracks in your music collection need to be signatured.  "The_BRANDING" is currently in the process of generating the signatures, but there are still ") + string(numtracks) + string(" left to go.");
    else
        message = "Before using any of the Relatable features, at least 75 percent of the tracks in your music collection need to be signatured.  Please click on 'Start Signaturing' in the Relatable menu.";

    dialog->Show(message.c_str(), caption.c_str(), kMessageOk, inMain);

    delete dialog;
}

void GTKMusicBrowser::SubmitPlaylist(void)
{
    APSInterface *pInterface = m_context->aps;
    if (!pInterface)
        return;
 
    if (!pInterface->IsTurnedOn()) {
        AskOptIn();
        return;
    }

    int totaltracks = m_context->catalog->GetTotalNumTracks();
    int needingsigs = m_context->catalog->GetNumNeedingSigs();

    if ((needingsigs * 100) / totaltracks > 25) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem *> *items;

    if (GetClickState() == kContextPlaylist) {
        items = new vector<PlaylistItem *>;
        set<uint32>::iterator i = m_plSelected.begin();
        for (; i != m_plSelected.end(); i++) {
            PlaylistItem *item = m_plm->ItemAt(*i);
            if (item)
                items->push_back(item);
        }
    }
    else if (GetClickState() == kContextBrowser) 
        items = GetTreeSelection();
    else 
        return;

    vector<PlaylistItem *>::iterator i;

    if (!items->empty()) {
        APSPlaylist InputPlaylist;
        bool allgood = true;
 
        for (i = items->begin(); i != items->end(); i++) {
            if ((*i)->GetMetaData().GUID().size() != 16) {
                allgood = false;
                break;
            }
            InputPlaylist.Insert((*i)->GetMetaData().GUID().c_str(),
                                 (*i)->URL().c_str());
        }

        if (allgood)
            pInterface->APSSubmitPlaylist(&InputPlaylist);
        else {
            string caption = "Learn Playlist Error";
            string message = "The item(s) you selected to train the Relatable Engine with are not signatured.  If signaturing is presently taking place, please wait a while longer and try again.  Otherwise, select 'Start Signaturing' from the Relatable menu to start the signaturing process.";
 
            GTKMessageDialog *dialog = new GTKMessageDialog();
            dialog->Show(message.c_str(), caption.c_str(), kMessageOk, true);
            delete dialog;
        }
    }
    else {
        string caption = "Learn Playlist Error";
        string message = "In order to train the Relatable Engine, you need to have tracks selected in the My Music tree, have tracks selected in the playlist, or just have an active playlist.  You don't have any of this right now, so the Relatable Engine has nothing to learn.";

        GTKMessageDialog *dialog = new GTKMessageDialog();
        dialog->Show(message.c_str(), caption.c_str(), kMessageOk, true);
        delete dialog;
    }

    delete items;    
}

void GTKMusicBrowser::GenSLPlaylist(float fMax)
{
    APSInterface *pInterface = m_context->aps;
    if (!pInterface)
        return;

    if (!pInterface->IsTurnedOn()) {
        AskOptIn();
        return;
    }

    int totaltracks = m_context->catalog->GetTotalNumTracks();
    int needingsigs = m_context->catalog->GetNumNeedingSigs();

    if ((needingsigs * 100) / totaltracks > 25) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem *> *items;

    if (GetClickState() == kContextPlaylist) {
        items = new vector<PlaylistItem *>;
        set<uint32>::iterator i = m_plSelected.begin();
        for (; i != m_plSelected.end(); i++) {
            PlaylistItem *item = m_plm->ItemAt(*i);
            if (item)
                items->push_back(item);
        }
    }
    else if (GetClickState() == kContextBrowser)
        items = GetTreeSelection();
    else
        return;

    bool allgood = true;
    vector<PlaylistItem *>::iterator j = items->begin();
    for (; j != items->end(); j++) {
        if ((*j)->GetMetaData().GUID().size() != 16) {
            allgood = false;
            break;
        }
    }

    if (allgood)
        GenSLPlaylist(items, fMax);
    else {
        string caption = "Generate SoundsLike Error";
        string message = "The item(s) you selected to seed the Relatable Engine with are not signatured.  If signaturing is presently taking place, please wait a while longer and try again.  Otherwise, select 'Start Signaturing' from the Relatable menu to start the signaturing process.";

        GTKMessageDialog *dialog = new GTKMessageDialog();
        dialog->Show(message.c_str(), caption.c_str(), kMessageOk, true);
        delete dialog;
    }

    delete items;
}

void GTKMusicBrowser::GenSLPlaylist(vector<PlaylistItem *> *seed, float fMax)
{
    APSInterface *pInterface = m_context->aps;
    if (!pInterface)
        return;

    if (!pInterface->IsTurnedOn()) {
        AskOptIn(false);
        return;
    }

    if (m_context->catalog->GetNumNeedingSigs() > 0) {
        StillNeedSignature(false);
        return;
    }

    APSPlaylist seedList;
    APSPlaylist returnList;
    uint32 nResponse = 0;

    if ((seed) && (!seed->empty())) {
        vector<PlaylistItem *>::iterator i;

        for (i = seed->begin(); i != seed->end(); i++)
            seedList.Insert((*i)->GetMetaData().GUID().c_str(), 
                            (*i)->URL().c_str());
    }
    nResponse = m_context->aps->APSGetSoundsLike(&seedList,
                                                 &returnList);

    if (nResponse == APS_NOERROR) {
        if (returnList.Size() > 0) {
            vector<string> newitems;
            string strTemp;
            string strFilename;
            APSPlaylist::iterator j;

            for (j = returnList.begin(); j.isvalid(); j.next()) {
                strFilename = m_context->catalog->GetFilename(j.first());
                if (strFilename != "")
                    newitems.push_back(strFilename.c_str());
            }

            for (int z = m_plm->CountItems() - 1; z >= 0; z--) {
                PlaylistItem *testitem = m_plm->ItemAt(z);
                bool remove = true;

                if ((seed) && (!seed->empty())) {
                    vector<PlaylistItem *>::iterator i = seed->begin();
                    for (; i != seed->end(); i++) {
                        if ((*i)->GetMetaData().GUID() ==
                             testitem->GetMetaData().GUID()) {
                            remove = false;
                            break;
                        }
                    }
                }

                if (remove)
                    m_plm->RemoveItem(z);
            }
            m_plm->AddItems(newitems);
        }
        else
           cerr << "SoundsLike recommendation didn't return any items\n";
    }
    else
        cerr << "SoundsLike server error\n";
}

void GTKMusicBrowser::GenPlaylist(void)
{
    APSInterface *pInterface = m_context->aps;
    if (!pInterface)
        return;

    if (!pInterface->IsTurnedOn()) {
        AskOptIn();
        return;
    }

    int totaltracks = m_context->catalog->GetTotalNumTracks();
    int needingsigs = m_context->catalog->GetNumNeedingSigs();

    if ((needingsigs * 100) / totaltracks > 25) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem *> *items;  

    if (GetClickState() == kContextPlaylist) {
        items = new vector<PlaylistItem *>;
        set<uint32>::iterator i = m_plSelected.begin();
        for (; i != m_plSelected.end(); i++) {
            PlaylistItem *item = m_plm->ItemAt(*i);
            if (item)
                items->push_back(item);
        }
    }
    else if (GetClickState() == kContextBrowser)
        items = GetTreeSelection();
    else
        return;

    bool allgood = true;
    vector<PlaylistItem *>::iterator j = items->begin();
    for (; j != items->end(); j++) {
        if ((*j)->GetMetaData().GUID().size() != 16) {
            allgood = false;
            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -