| 1060 | |
| 1061 | |
| 1062 | wxBitmap* MixerBoard::GetMusicalInstrumentBitmap(const Track* pTrack) |
| 1063 | { |
| 1064 | if (mMusicalInstruments.empty()) |
| 1065 | return NULL; |
| 1066 | |
| 1067 | // random choice: return mMusicalInstruments[(int)pTrack % mMusicalInstruments.size()].mBitmap; |
| 1068 | |
| 1069 | const wxString strTrackName( |
| 1070 | wxString{ pTrack->GetName() }.MakeLower()); |
| 1071 | size_t nBestItemIndex = 0; |
| 1072 | unsigned int nBestScore = 0; |
| 1073 | unsigned int nInstrIndex = 0; |
| 1074 | unsigned int nKeywordIndex; |
| 1075 | unsigned int nNumKeywords; |
| 1076 | unsigned int nPointsPerMatch; |
| 1077 | unsigned int nScore; |
| 1078 | for (nInstrIndex = 0; nInstrIndex < mMusicalInstruments.size(); nInstrIndex++) |
| 1079 | { |
| 1080 | nScore = 0; |
| 1081 | |
| 1082 | nNumKeywords = mMusicalInstruments[nInstrIndex]->mKeywords.size(); |
| 1083 | if (nNumKeywords > 0) |
| 1084 | { |
| 1085 | nPointsPerMatch = 10 / nNumKeywords; |
| 1086 | for (nKeywordIndex = 0; nKeywordIndex < nNumKeywords; nKeywordIndex++) |
| 1087 | if (strTrackName.Contains(mMusicalInstruments[nInstrIndex]->mKeywords[nKeywordIndex])) |
| 1088 | { |
| 1089 | nScore += |
| 1090 | nPointsPerMatch + |
| 1091 | // Longer keywords get more points. |
| 1092 | (2 * mMusicalInstruments[nInstrIndex]->mKeywords[nKeywordIndex].length()); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | // Choose later one if just matching nBestScore, for better variety, |
| 1097 | // and so default works as last element. |
| 1098 | if (nScore >= nBestScore) |
| 1099 | { |
| 1100 | nBestScore = nScore; |
| 1101 | nBestItemIndex = nInstrIndex; |
| 1102 | } |
| 1103 | } |
| 1104 | return mMusicalInstruments[nBestItemIndex]->mBitmap.get(); |
| 1105 | } |
| 1106 | |
| 1107 | bool MixerBoard::HasSolo() |
| 1108 | { |