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

📄 event.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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 ResultPlaylist;
    uint32 nResponse = 0;

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

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

        if (allgood)
            nResponse = m_context->aps->APSGetPlaylist(&InputPlaylist,
                                                       &ResultPlaylist);
        else {
            string caption = "Generate Playlist 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);

            return;
        }
    }
    else {
        APSPlaylist InputPlaylist;
        nResponse = m_context->aps->APSGetPlaylist(&InputPlaylist,
                                                   &ResultPlaylist);
    }

    bool messageError = true;

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

            for (j = ResultPlaylist.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 Playlist Error";
	  string message;

	  if (nResponse != APS_NOERROR) 
          message = "For some reason, the Relatable server returned an error.";
      else 
		  message = "The Relatable Engine didn't have any recommendations for you.  Listen to songs, use the 'Learn Playlist' menu item, and try this again later.";

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

void MusicBrowserUI::RenameEvent(void)
{
    HWND hwnd = m_hMusicView;

    HTREEITEM item;
    //tv_hitTESTINFO hti;

    //GetCursorPos(&hti.pt);
    //ScreenToClient(hwnd, &hti.pt);
    //item = TreeView_HitTest(hwnd, &hti);  

    item = TreeView_GetSelection(hwnd);

    if(item /*&& (hti.flags & TVHT_ONITEM)*/ &&
       item != m_hMyMusicItem &&
       item != m_hPlaylistItem &&
       item != m_hAllItem &&
       item != m_hUncatItem &&
       item != m_hNewPlaylistItem && 
       item != m_hPortableItem &&
       TreeView_GetParent(m_hMusicView, item) != m_hPortableItem)
    {
        EditItemLabel(hwnd, item);
    }
}

const char kErrorMsg[] = "Cannot delete %s: Access is denied.\r\n\r\n"
                        "Make sure the file is not currently in use.";

bool MusicBrowserUI::DeleteFromDrive(const char* url)
{
    bool result = true;
    char path[MAX_PATH];
    uint32 length = sizeof(path);
    BOOL success = FALSE;

    URLToFilePath(url, path, &length);

    do
    {
        success = DeleteFile(path);

        if(!success)
        {
            int ret;
            char msg[MAX_PATH + sizeof(kErrorMsg) + 1];
            char* cp;

            cp = strrchr(path, '\\');

            if(cp)
                cp++;
            else
                cp = path;

            sprintf(msg, kErrorMsg, cp);

            ret = MessageBox(m_hWnd, 
                              msg,
                              "Unable To Delete File",
                              MB_ABORTRETRYIGNORE|MB_ICONSTOP);

            switch(ret)
            {
                case IDABORT:
                    result = false;
                    success = TRUE;
                    break;

                case IDRETRY:
                    result = true;
                    success = FALSE;
                    break;

                case IDIGNORE:
                    result = true;
                    success = TRUE;
                    break;
            }
        }

    }while(!success);

    return result;
}

void MusicBrowserUI::RemoveEvent(void)
{
    // first figure out which control has focus
    HWND hwndFocus = GetFocus();

    if(hwndFocus == m_hPlaylistView)
    {
        uint32 count = ListView_GetSelectedCount(m_hPlaylistView);
        uint32 found = 0;
        uint32 index = ListView_GetItemCount(m_hPlaylistView) - 1;
        bool isCurrent = false;
        vector<PlaylistItem*> items;

        while(found < count)
        {
            uint32 state = ListView_GetItemState(m_hPlaylistView, 
                                                 index, 
                                                 LVIS_SELECTED);
            if(state & LVIS_SELECTED)
            {
                found++;

                if(m_plm->GetCurrentIndex() == index)
                    isCurrent = true;

                items.push_back(m_plm->ItemAt(index));
            }

            index--;
        }    

        bool needToStopPlay = isCurrent && m_playerState == PLAYERSTATE_PLAYING;
        
        if(needToStopPlay)
            m_context->target->AcceptEvent(new Event(CMD_Stop));

        m_plm->RemoveItems(&items);

        if(needToStopPlay)
            m_context->target->AcceptEvent(new Event(CMD_Play));
    }
    else if(hwndFocus == m_hMusicView)
    {
        bool deleteFromDrive = false;

        if(0 < DialogBoxParam(g_hinst, 
                              MAKEINTRESOURCE(IDD_REMOVETRACKS),
                              m_hWnd, 
                              ::RemoveTracksDlgProc, 
                              (LPARAM)&deleteFromDrive))
        {       
            vector<PlaylistItem*> items;
            GetSelectedMusicTreeItems(&items); 
            bool keepGoing = true;

            vector<PlaylistItem*>::iterator i;

            for(i = items.begin(); i != items.end(); i++)
            {
                m_context->catalog->RemoveSong((*i)->URL().c_str());

                if(deleteFromDrive)
                {
                    keepGoing = DeleteFromDrive((*i)->URL().c_str());

                    if(!keepGoing)
                        break;
                }
            }

            if(keepGoing)
            {
                vector<string> urls;            
                GetSelectedPlaylistItems(&urls);

                vector<string>::iterator j;
            
                for(j = urls.begin(); j != urls.end(); j++)
                {
                    m_context->catalog->RemovePlaylist((*j).c_str());

                    if(deleteFromDrive)
                    {
                        keepGoing = DeleteFromDrive((*j).c_str());

                        if(!keepGoing)
                            break;
                    }
                }
            }
        }
    }
}

void MusicBrowserUI::MoveUpEvent(void)
{
    uint32 count = ListView_GetSelectedCount(m_hPlaylistView);
    uint32 found = 0;
    uint32 index = 0;

    while(found < count)
    {
        uint32 state = ListView_GetItemState(m_hPlaylistView, 
                                             index, 
                                             LVIS_SELECTED);

        if(state & LVIS_SELECTED)
        {
            found++;

            if(index == 0)
                break;

            m_plm->MoveItem(index, index - 1);
        }

        index++;
    }    
}

void MusicBrowserUI::MoveDownEvent(void)
{
    uint32 count = ListView_GetSelectedCount(m_hPlaylistView);
    uint32 found = 0;
    uint32 index = ListView_GetItemCount(m_hPlaylistView) - 1;;

    while(found < count)
    {
        uint32 state = ListView_GetItemState(m_hPlaylistView, 
                                             index, 
                                             LVIS_SELECTED);

        if(state & LVIS_SELECTED)
        {
            found++;

            if(index == m_plm->CountItems() - 1)
                break;

            m_plm->MoveItem(index, index + 1);
        }

        index--;
    }    
}

void MusicBrowserUI::MoveItemEvent(int source, int dest)
{
    m_plm->MoveItem(source, dest);
}

void MusicBrowserUI::StartStopMusicSearch(bool useWizard)
{  
    HMENU           hMenu;
    MENUITEMINFO    sItem;
    bool            doSearch = false;

    if (m_bSearchInProgress)
    {
        m_bSearchInProgress = false;
        m_context->catalog->StopSearchMusic();
        return;
    }

    m_searchPathList.clear();

    if(useWizard)
        doSearch = IntroductionWizard(&m_searchPathList, m_context->aps);
    else
        doSearch = (0 < DialogBoxParam(g_hinst, 
                          MAKEINTRESOURCE(IDD_MUSICSEARCH),
                          m_hWnd, 
                          ::MusicSearchDlgProc, 
                          (LPARAM )this));

    if(doSearch)
    {
        
        m_context->catalog->SearchMusic(m_searchPathList);

        m_bSearchInProgress = true;
        hMenu = GetMenu(m_hWnd);
        hMenu = GetSubMenu(hMenu, 0);
        sItem.cbSize = sizeof(MENUITEMINFO);
        sItem.fMask = MIIM_TYPE;
        sItem.fType = MFT_STRING;
        sItem.dwTypeData = "Stop &Music Search";
        sItem.cch = strlen(sItem.dwTypeData);
        SetMenuItemInfo(hMenu, ID_FILE_SEARCHFORMUSIC, false, &sItem);
    }
}

void MusicBrowserUI::ExportPlaylistEvent()
{
    TV_ITEM tv_item;

    // get the first playlist item
    tv_item.hItem = TreeView_GetChild(m_hMusicView, m_hPlaylistItem);
    tv_item.mask = TVIF_STATE|TVIF_PARAM;
    tv_item.stateMask = TVIS_SELECTED;
    tv_item.state = 0;

⌨️ 快捷键说明

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