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

📄 event.cpp

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

        FreeAmp - The Free MP3 Player

        Portions Copyright (C) 1999 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: Event.cpp,v 1.104 2001/03/07 09:33:07 elrod Exp $
____________________________________________________________________________*/

#include <windows.h>
#include <windowsx.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <direct.h>
#include <math.h>

#include <sstream>

using namespace std;

#include "config.h"
#include "utility.h"
#include "resource.h"
#include "Win32MusicBrowser.h"
#include "EditTrackInfoDialog.h"
#include "eventdata.h"
#include "debug.h"
#include "FavoriteDialog.h"
#include "player.h"

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

//RAK: Is this still used?
//const char* kAudioFileFilter =
//            "MPEG Audio Streams (.mpg, .mp1, .mp2, .mp3, .mpp)\0"
//            "*.mpg;*.mp1;*.mp2;*.mp3;*.mpp\0"
//            "All Files (*.*)\0"
//            "*.*\0";

void MusicBrowserUI::TipEvent(PlaylistItem *item)
{
   vector<PlaylistItem*> items;
   PlaylistItem *tip = NULL;
   if (item)
       tip = item;

   if (!tip) {
	   GetSelectedPlaylistItems(&items);
       tip = *(items.begin());
   }
 
   if (!tip)
	   return;

   string artistname = tip->GetMetaData().Artist();

   if (artistname.size() == 0 || artistname == "Unknown")
       return;

   string encoded;
   ReplaceSpaces(artistname, encoded);
   string url = string("http://www.fairtunes.com/servlet/ArtistLookupServlet?redirectPage=http://www.fairtunes.com/search.jsp&searchTerms=") + encoded;

   ShellExecute(m_hWnd, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
}

void MusicBrowserUI::ClearPlaylistEvent(void)
{
    m_context->target->AcceptEvent(new Event(CMD_Stop));

    m_plm->RemoveAll();
}

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

void MusicBrowserUI::AskSignatureDialog(void)
{
    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?");

    int ret = MessageBox(m_hWnd, message.c_str(), caption.c_str(),
                         MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND);

    if (ret == IDYES)
        m_context->catalog->StartGeneratingSigs();
}

void MusicBrowserUI::AskOptIn(void)
{
    string caption = "Relatable Features 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?";

    int ret = MessageBox(m_hWnd, message.c_str(), caption.c_str(),
                         MB_YESNO|MB_ICONSTOP|MB_SETFOREGROUND);

    if (ret == IDYES)
        m_context->target->AcceptEvent(new ShowPreferencesEvent(7));
}

void MusicBrowserUI::StillNeedSignature(void)
{
    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 = 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" needs to signature ") + string(numtracks) + string(" track(s).  Please click on 'Start Signaturing' in the Relatable menu.");

    MessageBox(m_hWnd, message.c_str(), caption.c_str(), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
}

void MusicBrowserUI::SubmitPlaylistEvent(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 (ceil((needingsigs * 100) / totaltracks) > 26) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem*> items;

    GetSelectedMusicTreeItems(&items);

	if (items.empty())
	    GetSelectedPlaylistItems(&items);

    PlaylistItem* pPlaylistItem = NULL;   
    if (items.empty())
    {
        // fill the vector with the current playlist;
        int nCount = m_plm->CountItems();
        for (int i = 0; i < nCount; i++)
        {
            pPlaylistItem = m_plm->ItemAt(i);
            if (pPlaylistItem != NULL)
            {
                items.push_back(pPlaylistItem);
            }
	} 
    }

   vector<PlaylistItem*>::iterator i;

   if (!items.empty())
   {
       APSPlaylist InputPlaylist;
       bool allgood = true;

       // Assumes that GUID's are set properly in meta structures
       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.";

            MessageBox(m_hWnd, message.c_str(), caption.c_str(), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
       }
   }
   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.";

      MessageBox(m_hWnd, message.c_str(), caption.c_str(), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
   }
}


void MusicBrowserUI::GenSLPlaylistEvent(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 (ceil((needingsigs * 100) / totaltracks) > 26) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem*> items;
    GetSelectedMusicTreeItems(&items);
    if (items.empty())
    {
        GetSelectedPlaylistItems(&items);
    }

    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)
        GenSLPlaylistEvent(&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.";

        MessageBox(m_hWnd, message.c_str(), caption.c_str(), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
    }
}

void MusicBrowserUI::GenSLPlaylistEvent(vector<PlaylistItem*>* pSeed, 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 (ceil((needingsigs * 100) / totaltracks) > 26) {
        StillNeedSignature();
        return;
    }

    APSPlaylist seedList;
    APSPlaylist returnList;
    uint32 nResponse = 0;

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

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

    bool messageError = true;

    if (nResponse == APS_NOERROR) {
        if (returnList.Size() > 0) {
            messageError = false;
            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 ((pSeed) && (!pSeed->empty())) {
                    vector<PlaylistItem *>::iterator i = pSeed->begin();
                    for (; i != pSeed->end(); i++) {
                        if ((*i)->GetMetaData().GUID() ==
                             testitem->GetMetaData().GUID()) {
                            remove = false;
                            break;
                        }
                    }
                }

                if (remove)
                    m_plm->RemoveItem(z);
            }
            m_plm->AddItems(newitems);
        }
    }

    if (messageError) {
      string caption = "Generate SoundsLike Playlist Error";
      string message;

      if (nResponse != APS_NOERROR) 
          message = "For some reason, the Relatable SoundsLike server returned an error.";
      else 
	  message = "The Relatable SoundsLike server didn't return any matches.";

      MessageBox(m_hWnd, message.c_str(), caption.c_str(), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
   }
}

void MusicBrowserUI::GenPlaylistEvent()
{
    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 (ceil((needingsigs * 100) / totaltracks) > 26) {
        StillNeedSignature();
        return;
    }

    vector<PlaylistItem*> items;
    GetSelectedMusicTreeItems(&items);
    if (items.empty())
    {
        GetSelectedPlaylistItems(&items);
    }
    GenPlaylistEvent(&items);
}

void MusicBrowserUI::GenPlaylistEvent(vector<PlaylistItem*>* pSeed)
{

⌨️ 快捷键说明

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