void testConstructWithLine() { string line = "あ,a,0.4,0,0"; Lyric lyric = Lyric( line ); CPPUNIT_ASSERT( false == lyric.isProtected ); CPPUNIT_ASSERT_EQUAL( string( "あ" ), lyric.phrase ); CPPUNIT_ASSERT_EQUAL( string( "a" ), lyric.getPhoneticSymbol() ); CPPUNIT_ASSERT_EQUAL( 0.4, lyric.lengthRatio ); line = "あ\"\",a,1.0,0,0"; lyric = Lyric( line ); CPPUNIT_ASSERT_EQUAL( string( "あ\"" ), lyric.phrase ); line = "は,h a,1.0,64,0,1"; lyric = Lyric( line ); CPPUNIT_ASSERT_EQUAL( string( "は" ), lyric.phrase ); CPPUNIT_ASSERT( lyric.isProtected ); vector<string> symbols = lyric.getPhoneticSymbolList(); CPPUNIT_ASSERT_EQUAL( 2, (int)symbols.size() ); CPPUNIT_ASSERT_EQUAL( string( "h" ), symbols[0] ); CPPUNIT_ASSERT_EQUAL( string( "a" ), symbols[1] ); line = "\"a\",\"b\",1,0,0"; lyric = Lyric( line ); CPPUNIT_ASSERT_EQUAL( string( "a" ), lyric.phrase ); CPPUNIT_ASSERT_EQUAL( string( "b" ), lyric.getPhoneticSymbol() ); }
void testEquals() { Lyric a = Lyric( "は,h a,1,64,0,0" ); Lyric b = Lyric( "は,h a,1,64,0,0" ); CPPUNIT_ASSERT( a.equals( b ) ); Lyric c = Lyric( "あ,a,1.0,0,0" ); CPPUNIT_ASSERT( false == a.equals( c ) ); }
void testGetConsonantAdjustmentList() { Lyric lyric = Lyric( "は,h a,1,64,0,0" ); const vector<int> actual = lyric.getConsonantAdjustmentList(); CPPUNIT_ASSERT_EQUAL( 2, (int)actual.size() ); CPPUNIT_ASSERT_EQUAL( 64, actual[0] ); CPPUNIT_ASSERT_EQUAL( 0, actual[1] ); }
void testConstructWithPhrase() { Lyric lyric = Lyric( "は", "h a" ); CPPUNIT_ASSERT_EQUAL( string( "は" ), lyric.phrase ); CPPUNIT_ASSERT_EQUAL( string( "h a" ), lyric.getPhoneticSymbol() ); CPPUNIT_ASSERT_EQUAL(string("64,0" ), lyric.getConsonantAdjustment()); CPPUNIT_ASSERT( false == lyric.isProtected ); }
void testGetPhoneticSymbolList() { Lyric lyric = Lyric( "は,h a,1.0,64,0,0" ); vector<string> actual = lyric.getPhoneticSymbolList(); CPPUNIT_ASSERT_EQUAL( (vector<string>::size_type)2, actual.size() ); CPPUNIT_ASSERT_EQUAL( string( "h" ), actual[0] ); CPPUNIT_ASSERT_EQUAL( string( "a" ), actual[1] ); }
void testSetPhoneticSymbol() { Lyric lyric = Lyric( "あ,a,1.0,0,0" ); lyric.setPhoneticSymbol( "h a" ); vector<string> actual = lyric.getPhoneticSymbolList(); CPPUNIT_ASSERT_EQUAL( 2, (int)actual.size() ); CPPUNIT_ASSERT_EQUAL( string( "h" ), actual[0] ); CPPUNIT_ASSERT_EQUAL( string( "a" ), actual[1] ); }
TEST(HandleTest, testCloneLyricHandle) { Handle handle(HandleType::LYRIC); handle.set(0, Lyric("ら", "4 a")); handle.index = 10; Handle copy = handle.clone(); EXPECT_EQ(handle.index, copy.index); Lyric original = handle.get(0); Lyric copied = copy.get(0); EXPECT_TRUE(original.equals(copied)); }
void testEqualsForSynth() { Lyric a = Lyric( "は,h a,1,64,0,0" ); Lyric b = Lyric( "あ,h a,0.5,64,0,1" ); CPPUNIT_ASSERT( a.equalsForSynth( b ) ); // consonantAdjustmentだけ違う場合 Lyric c = Lyric( "は,h a,1,64,1,0" ); CPPUNIT_ASSERT( false == a.equalsForSynth( c ) ); // 発音記号が違う場合 Lyric d = Lyric( "は,h e,1,64,0,0" ); CPPUNIT_ASSERT( false == a.equalsForSynth( d ) ); }
void testGetConsonantAdjustmentListWithNil() { Lyric lyric = Lyric( "は,h a,1,32,16,0" ); vector<int> actual = lyric.getConsonantAdjustmentList(); CPPUNIT_ASSERT_EQUAL( 2, (int)actual.size() ); CPPUNIT_ASSERT_EQUAL( 32, actual[0] ); CPPUNIT_ASSERT_EQUAL( 16, actual[1] ); lyric._consonantAdjustment.clear(); actual = lyric.getConsonantAdjustmentList(); CPPUNIT_ASSERT_EQUAL( 2, (int)actual.size() ); CPPUNIT_ASSERT_EQUAL( 64, actual[0] ); CPPUNIT_ASSERT_EQUAL( 0, actual[1] ); }
//-------------------------------------------------------------- void ofApp::setupLyrics(){ _lyrics.clear(); for(int i=0; i<_dummyLyric.getLyricNum();i++) { Lyric lyric; lyric.setup(_dummyLyric.getLyric(), (ofRandom(-90,90)), (ofRandom(-180,180)), (ofRandom(_sphereSize/2, _sphereSize))); _lyrics.push_back(lyric); } }
DWORD LyricSourceLRC::Save(const metadb_handle_ptr &track, Lyric &lyric) { std::wstring path = getSavePath(track); HANDLE hf = CreateFile(path.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL); if(hf == INVALID_HANDLE_VALUE) return 0; DWORD unused; //{"UTF-8", "UTF-8(BOM)", "UTF-16", "CP949"}; if(m_config["lrcsaveencoding"] == "1") { const unsigned char bomtemp[] = {0xEF, 0xBB, 0xBF}; WriteFile(hf, bomtemp, 3, &unused, NULL); } else if(m_config["lrcsaveencoding"] == "2") { const unsigned char bomtemp[] = {0xFF, 0xFE}; WriteFile(hf, bomtemp, 2, &unused, NULL); } for(std::vector<LyricLine>::const_iterator it = lyric.GetIteratorAt(0); !lyric.IsEndOfLyric(it); it ++) { std::stringstream str; str << "[" << std::setfill('0') << std::setw(2) << it->time / 60 / 100 << ":" << std::setw(2) << it->time / 100 % 60 << "." << std::setw(2) << it->time % 100 << "]" << it->lyric << "\r\n"; if(m_config["lrcsaveencoding"] == "0" || m_config["lrcsaveencoding"] == "1") WriteFile(hf, str.str().c_str(), str.str().size(), &unused, NULL); else if(m_config["lrcsaveencoding"] == "2") { std::wstring wstr = EncodingFunc::ToUTF16(str.str()); WriteFile(hf, wstr.c_str(), wstr.size(), &unused, NULL); } else if(m_config["lrcsaveencoding"] == "3") { std::wstring wstr = EncodingFunc::ToUTF16(str.str()); CHAR mbstr[512]; int len = WideCharToMultiByte(949, NULL, wstr.c_str(), -1, mbstr, 512, NULL, NULL); mbstr[len] = 0; WriteFile(hf, mbstr, len, &unused, NULL); } } CloseHandle(hf); return 1; }
void LyricsManiaAPI::onGetLyricPageResult() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender()); bool found = false; Lyric* lyric = 0; if (reply->error() != QNetworkReply::NoError) { qCritical() << "Cannot fetch lyric"; } else { QWebPage page; page.settings()->setAttribute(QWebSettings::AutoLoadImages, false); page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false); page.mainFrame()->setHtml(reply->readAll()); QWebElement lyricbox = page.mainFrame()->findFirstElement("div[class=lyrics-body]"); if (lyricbox.isNull()) { qCritical() << "Cannot find lyric text in HTML page"; } else { // Remove the video div lyricbox.findFirst(QStringLiteral("div")).removeFromDocument(); // Remove the song title lyricbox.findFirst(QStringLiteral("strong")).removeFromDocument(); lyric = lyrics.take(reply); if (!lyric) { qCritical() << "Got an invalid lyric object!"; } else { lyric->setText(lyricbox.toPlainText()); found = true; } } } qDebug() << "Lyric found:" << found; Q_EMIT lyricFetched(lyric, found); reply->deleteLater(); }
//-------------------------------------------------------------- void ofApp::addLyrics(){ Lyric lyric; lyric.setup(_dummyLyric.getLyric(), (ofRandom(-90,90)), (ofRandom(-180,180)), (ofRandom(_sphereSize/2, _sphereSize))); if(lyric.name != "ピ") { _lyrics.push_back(lyric); _bEmpty = false; } else { _lyrics.clear(); _bEmpty = true; } cout << _lyrics.size() << ", " << _bEmpty << endl; }
void LyricsManiaAPI::getLyric(const QString &artist, const QString &song) { qDebug() << "Requesting lyric for artist" << artist << ", song" << song; QString artNoSpaces(artist.toLower()); artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_')); QString songNoSpaces(song.toLower()); songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_')); QUrl url(BASE_URL + QStringLiteral("/%1_lyrics_%2.html").arg(songNoSpaces).arg(artNoSpaces)); qDebug() << url; QNetworkRequest req(url); QNetworkReply* reply = network->get(req); Lyric* lyric = new Lyric(); lyric->setArtist(artist); lyric->setSong(song); lyrics.insert(reply, lyric); connect(reply, &QNetworkReply::finished, this, &LyricsManiaAPI::onGetLyricPageResult); }
void AlsongLyricLinkDialog::PopulateListView() { HWND hListView = GetDlgItem(m_hWnd, IDC_LYRICLIST); Lyric *lrc = m_searchresult->Get(); int n = 0; ListView_DeleteAllItems(hListView); do { std::wstring artist = pfc::stringcvt::string_wide_from_utf8(lrc->GetArtist().c_str()).get_ptr(); std::wstring title = pfc::stringcvt::string_wide_from_utf8(lrc->GetTitle().c_str()).get_ptr(); LVITEM item; item.mask = LVIF_TEXT | LVIF_PARAM; item.iItem = n ++; item.iSubItem = 0; item.pszText = const_cast<WCHAR *>(artist.c_str()); item.lParam = lrc->GetInternalID(); ListView_InsertItem(hListView, &item); item.iSubItem = 1; item.mask = LVIF_TEXT; item.pszText = const_cast<WCHAR *>(title.c_str()); ListView_SetItem(hListView, &item); }while((lrc = m_searchresult->Get()), lrc->HasLyric()); }
UINT AlsongLyricLinkDialog::DialogProc(UINT iMessage, WPARAM wParam, LPARAM lParam) { switch(iMessage) { case WM_CLOSE: EndDialog(m_hWnd, 0); return TRUE; case WM_DESTROY: return TRUE; case WM_INITDIALOG: { uSetWindowText(m_hWnd, m_track->get_path()); //set artist, title field service_ptr_t<titleformat_object> to; pfc::string8 artist; pfc::string8 title; static_api_ptr_t<titleformat_compiler>()->compile_safe(to, "%artist%"); m_track->format_title(NULL, artist, to, NULL); static_api_ptr_t<titleformat_compiler>()->compile_safe(to, "%title%"); m_track->format_title(NULL, title, to, NULL); uSetDlgItemText(m_hWnd, IDC_ARTIST, artist.get_ptr()); uSetDlgItemText(m_hWnd, IDC_TITLE, title.get_ptr()); //perform listview initialization. LVCOLUMN lv; lv.mask = LVCF_WIDTH | LVCF_TEXT; lv.cx = 150; lv.pszText = TEXT("아티스트"); ListView_InsertColumn(GetDlgItem(m_hWnd, IDC_LYRICLIST), 0, &lv); lv.pszText = TEXT("제목"); ListView_InsertColumn(GetDlgItem(m_hWnd, IDC_LYRICLIST), 1, &lv); SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); //disable next, prev button SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); } return TRUE; case WM_NOTIFY: { NMHDR *hdr = (NMHDR *)lParam; if(hdr->code == LVN_ITEMCHANGED && hdr->idFrom == IDC_LYRICLIST) { int nSel; NMLISTVIEW *nlv = (NMLISTVIEW *)lParam; nSel = nlv->iItem; LVITEM litem; litem.mask = LVIF_PARAM; litem.iItem = nSel; litem.iSubItem = 0; ListView_GetItem(GetDlgItem(m_hWnd, IDC_LYRICLIST), &litem); Lyric *res = m_searchresult->Get((int)litem.lParam); std::string lyric = res->GetRawLyric(); boost::replace_all(lyric, "<br>", "\r\n"); uSetDlgItemText(m_hWnd, IDC_LYRIC, lyric.c_str()); } } return TRUE; case WM_COMMAND: if(HIWORD(wParam) == BN_CLICKED) { switch(LOWORD(wParam)) { case IDC_SEARCH: { pfc::string8 artist; uGetDlgItemText(m_hWnd, IDC_ARTIST, artist); pfc::string8 title; uGetDlgItemText(m_hWnd, IDC_TITLE, title); if(artist.get_length() == 0) { MessageBox(m_hWnd, TEXT("아티스트를 입력해 주세요"), TEXT("에러"), MB_OK); return TRUE; } if(title.get_length() == 0) { MessageBox(m_hWnd, TEXT("제목을 입력해 주세요"), TEXT("에러"), MB_OK); return TRUE; } m_page = 0; m_lyriccount = LyricSourceAlsong().SearchLyricGetCount(artist.toString(), title.toString()); std::stringstream str; str << m_page * 100 + 1 << "~" << min(m_lyriccount, (m_page + 1) * 100) << "/" << m_lyriccount; uSetDlgItemText(m_hWnd, IDC_STATUS, str.str().c_str()); LVITEM item; HWND hListView = GetDlgItem(m_hWnd, IDC_LYRICLIST); item.mask = LVIF_TEXT; item.iItem = 0; item.iSubItem = 0; item.pszText = L""; ListView_InsertItem(hListView, &item); item.iSubItem = 1; item.mask = LVIF_TEXT; item.pszText = L"잠시 기다려 주세요"; ListView_SetItem(hListView, &item); m_searchresult = LyricSourceAlsong().SearchLyric(artist.toString(), title.toString(), 0); PopulateListView(); SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE) | WS_DISABLED); if(m_lyriccount > 100) SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) & ~WS_DISABLED); else SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); } break; case IDC_RESET: SetDlgItemText(m_hWnd, IDC_ARTIST, TEXT("")); SetDlgItemText(m_hWnd, IDC_TITLE, TEXT("")); SetDlgItemText(m_hWnd, IDC_STATUS, TEXT("")); ListView_DeleteAllItems(GetDlgItem(m_hWnd, IDC_LYRICLIST)); SetDlgItemText(m_hWnd, IDC_LYRIC, TEXT("")); SetFocus(GetDlgItem(m_hWnd, IDC_ARTIST)); SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); SetWindowLong(GetDlgItem(m_hWnd, IDC_ARTIST), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_ARTIST), GWL_STYLE) & ~WS_DISABLED); SetWindowLong(GetDlgItem(m_hWnd, IDC_TITLE), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_ARTIST), GWL_STYLE) & ~WS_DISABLED); //reset; break; case IDC_NEWLYRIC: //something break; case IDC_PREV: { if(m_page == 0) return TRUE; m_page --; pfc::string8 artist; uGetDlgItemText(m_hWnd, IDC_ARTIST, artist); pfc::string8 title; uGetDlgItemText(m_hWnd, IDC_TITLE, title); std::stringstream str; str << m_page * 100 + 1 << "~" << min(m_lyriccount, (m_page + 1) * 100) << "/" << m_lyriccount; uSetDlgItemText(m_hWnd, IDC_STATUS, str.str().c_str()); m_searchresult = LyricSourceAlsong().SearchLyric(artist.toString(), title.toString(), 0); PopulateListView(); if(m_page != 0) SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE) & ~WS_DISABLED); else SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE) | WS_DISABLED); if(m_lyriccount / 100 != m_page) SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) & ~WS_DISABLED); else SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); } break; case IDC_NEXT: { if(m_page == m_lyriccount / 100) return TRUE; m_page ++; pfc::string8 artist; uGetDlgItemText(m_hWnd, IDC_ARTIST, artist); pfc::string8 title; uGetDlgItemText(m_hWnd, IDC_TITLE, title); std::stringstream str; str << m_page * 100 + 1 << "~" << min(m_lyriccount, (m_page + 1) * 100) << "/" << m_lyriccount; uSetDlgItemText(m_hWnd, IDC_STATUS, str.str().c_str()); m_searchresult = LyricSourceAlsong().SearchLyric(artist.toString(), title.toString(), 0); PopulateListView(); if(m_page != 0) SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE) & ~WS_DISABLED); else SetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_PREV), GWL_STYLE) | WS_DISABLED); if(m_lyriccount / 100 != m_page) SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) & ~WS_DISABLED); else SetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE, GetWindowLong(GetDlgItem(m_hWnd, IDC_NEXT), GWL_STYLE) | WS_DISABLED); } break; case IDC_SYNCEDIT: break; case IDC_REGISTER: { int nSel; nSel = SendMessage(GetDlgItem(m_hWnd, IDC_LYRICLIST), LVM_GETSELECTIONMARK, 0, 0); LVITEM litem; litem.mask = LVIF_PARAM; litem.iItem = nSel; litem.iSubItem = 0; ListView_GetItem(GetDlgItem(m_hWnd, IDC_LYRICLIST), &litem); if(LyricSourceAlsong().Save(m_track, *m_searchresult->Get(litem.lParam))) { MessageBox(m_hWnd, TEXT("등록 성공"), TEXT("안내"), MB_OK); static_api_ptr_t<play_control> pc; metadb_handle_ptr p_track; pc->get_now_playing(p_track); if(p_track == m_track) LyricManager::Reload(p_track); EndDialog(m_hWnd, 0); return TRUE; } MessageBox(m_hWnd, TEXT("등록 실패"), TEXT("안내"), MB_OK); } break; case IDC_CANCEL: EndDialog(m_hWnd, 0); break; } } return TRUE; } return FALSE; }
void testGetConsonantAdjustment() { Lyric lyric = Lyric( "は,h a,1,64,0,0" ); string actual = lyric.getConsonantAdjustment(); CPPUNIT_ASSERT_EQUAL(string("64,0"), actual); }
void testSetConsonantAdjustment() { Lyric lyric = Lyric("は,h a,1,64,0,0"); lyric.setConsonantAdjustment("61,0"); CPPUNIT_ASSERT_EQUAL(string("61,0"), lyric.getConsonantAdjustment()); }
void testToString() { string expected = "は,h a,1,64,0,0"; Lyric lyric = Lyric( expected ); CPPUNIT_ASSERT_EQUAL( expected, lyric.toString() ); }
void testGetPhoneticSymbol() { Lyric lyric = Lyric( "は,h a,1.0,64,0,0" ); string actual = lyric.getPhoneticSymbol(); CPPUNIT_ASSERT_EQUAL( string( "h a" ), actual ); }
void testClone(){ Lyric lyric( "は,h a,1,64,0,0" ); Lyric copy = lyric.clone(); CPPUNIT_ASSERT_EQUAL( lyric.toString(), copy.toString() ); }