![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Chapter006_Zara_F746NG
Dependencies: F746_GUI SRF08 Array_Matrix TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG SDFileSystem_Warning_Fixed FrequencyResponseDrawer F746_SAI_IO
MyClasses_Functions/FileSelectorWav.cpp@12:85e7363da26a, 2019-04-03 (annotated)
- Committer:
- SanYune
- Date:
- Wed Apr 03 04:44:32 2019 +0000
- Revision:
- 12:85e7363da26a
- Parent:
- 11:769d986c10fa
Chapter006_Zara_F746NG
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 11:769d986c10fa | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 11:769d986c10fa | 2 | // FileSelector class |
MikamiUitOpen | 11:769d986c10fa | 3 | // SD カード内のファイル名の一覧を表示し,ファイルを選択する |
MikamiUitOpen | 11:769d986c10fa | 4 | // |
MikamiUitOpen | 11:769d986c10fa | 5 | // 2016/06/30, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 11:769d986c10fa | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 11:769d986c10fa | 7 | |
MikamiUitOpen | 11:769d986c10fa | 8 | #include "FileSelectorWav.hpp" |
MikamiUitOpen | 11:769d986c10fa | 9 | |
MikamiUitOpen | 11:769d986c10fa | 10 | namespace Mikami |
MikamiUitOpen | 11:769d986c10fa | 11 | { |
MikamiUitOpen | 11:769d986c10fa | 12 | bool FileSelector::CreateTable() |
MikamiUitOpen | 11:769d986c10fa | 13 | { |
MikamiUitOpen | 11:769d986c10fa | 14 | DIR* dp = opendir("/sd"); |
MikamiUitOpen | 11:769d986c10fa | 15 | fileCount_ = 0; |
MikamiUitOpen | 11:769d986c10fa | 16 | if (dp != NULL) |
MikamiUitOpen | 11:769d986c10fa | 17 | { |
MikamiUitOpen | 11:769d986c10fa | 18 | dirent* entry; |
MikamiUitOpen | 11:769d986c10fa | 19 | for (int n=0; n<256; n++) |
MikamiUitOpen | 11:769d986c10fa | 20 | { |
MikamiUitOpen | 11:769d986c10fa | 21 | entry = readdir(dp); |
MikamiUitOpen | 11:769d986c10fa | 22 | if (entry == NULL) break; |
MikamiUitOpen | 11:769d986c10fa | 23 | |
MikamiUitOpen | 11:769d986c10fa | 24 | string strName = entry->d_name; |
MikamiUitOpen | 11:769d986c10fa | 25 | if ( (strName.find(".wav") != string::npos) || |
MikamiUitOpen | 11:769d986c10fa | 26 | (strName.find(".WAV") != string::npos) ) |
MikamiUitOpen | 11:769d986c10fa | 27 | { |
MikamiUitOpen | 11:769d986c10fa | 28 | sdReader_.Open(strName); // ファイルオープン |
MikamiUitOpen | 11:769d986c10fa | 29 | |
MikamiUitOpen | 11:769d986c10fa | 30 | // PCM,16 ビットステレオ,標本化周波数 44.1 kHz 以外のファイルは除外 |
MikamiUitOpen | 11:769d986c10fa | 31 | if (sdReader_.IsWavFile()) |
MikamiUitOpen | 11:769d986c10fa | 32 | fileNames_[fileCount_++] = strName; |
MikamiUitOpen | 11:769d986c10fa | 33 | sdReader_.Close(); |
MikamiUitOpen | 11:769d986c10fa | 34 | } |
MikamiUitOpen | 11:769d986c10fa | 35 | |
MikamiUitOpen | 11:769d986c10fa | 36 | if (fileCount_ >= MAX_FILES_) break; |
MikamiUitOpen | 11:769d986c10fa | 37 | } |
MikamiUitOpen | 11:769d986c10fa | 38 | closedir(dp); |
MikamiUitOpen | 11:769d986c10fa | 39 | } |
MikamiUitOpen | 11:769d986c10fa | 40 | else |
MikamiUitOpen | 11:769d986c10fa | 41 | return false; |
MikamiUitOpen | 11:769d986c10fa | 42 | |
MikamiUitOpen | 11:769d986c10fa | 43 | if (fileCount_ == 0) return false; |
MikamiUitOpen | 11:769d986c10fa | 44 | |
MikamiUitOpen | 11:769d986c10fa | 45 | if (rect_ != NULL) delete rect_; |
MikamiUitOpen | 11:769d986c10fa | 46 | Array<string> nonString(fileCount_, ""); |
MikamiUitOpen | 11:769d986c10fa | 47 | rect_ = new ButtonGroup(X_, Y_, W_H_, W_H_, fileCount_, |
MikamiUitOpen | 11:769d986c10fa | 48 | nonString, 0, V_L_-W_H_, 1, |
MikamiUitOpen | 11:769d986c10fa | 49 | -1, Font12, 0, GuiBase::ENUM_BACK, |
MikamiUitOpen | 11:769d986c10fa | 50 | BASE_COLOR_, TOUCHED_COLOR_); |
MikamiUitOpen | 11:769d986c10fa | 51 | for (int n=0; n<fileCount_; n++) rect_->Erase(n); |
MikamiUitOpen | 11:769d986c10fa | 52 | CreateLabels(); |
MikamiUitOpen | 11:769d986c10fa | 53 | prevFileCount_ = fileCount_; |
MikamiUitOpen | 11:769d986c10fa | 54 | return true; |
MikamiUitOpen | 11:769d986c10fa | 55 | } |
MikamiUitOpen | 11:769d986c10fa | 56 | |
MikamiUitOpen | 11:769d986c10fa | 57 | // ファイルを選択する |
MikamiUitOpen | 11:769d986c10fa | 58 | bool FileSelector::Select(string &fileName) |
MikamiUitOpen | 11:769d986c10fa | 59 | { |
MikamiUitOpen | 11:769d986c10fa | 60 | int n; |
MikamiUitOpen | 11:769d986c10fa | 61 | if (rect_->GetTouchedNumber(n)) |
MikamiUitOpen | 11:769d986c10fa | 62 | { |
MikamiUitOpen | 11:769d986c10fa | 63 | fileNameLabels_[n]->Draw(GetFileNameNoExt(n), TOUCHED_COLOR_); |
MikamiUitOpen | 11:769d986c10fa | 64 | if ((prev_ >= 0) && (prev_ != n)) |
MikamiUitOpen | 11:769d986c10fa | 65 | fileNameLabels_[prev_]->Draw(GetFileNameNoExt(prev_)); |
MikamiUitOpen | 11:769d986c10fa | 66 | prev_ = n; |
MikamiUitOpen | 11:769d986c10fa | 67 | fileName = fileNames_[n]; |
MikamiUitOpen | 11:769d986c10fa | 68 | return true; |
MikamiUitOpen | 11:769d986c10fa | 69 | } |
MikamiUitOpen | 11:769d986c10fa | 70 | else |
MikamiUitOpen | 11:769d986c10fa | 71 | return false; |
MikamiUitOpen | 11:769d986c10fa | 72 | } |
MikamiUitOpen | 11:769d986c10fa | 73 | |
MikamiUitOpen | 11:769d986c10fa | 74 | // ファイルの一覧の表示 |
MikamiUitOpen | 11:769d986c10fa | 75 | void FileSelector::DisplayFileList(bool sortEnable) |
MikamiUitOpen | 11:769d986c10fa | 76 | { |
MikamiUitOpen | 11:769d986c10fa | 77 | if (sortEnable) |
MikamiUitOpen | 11:769d986c10fa | 78 | std::sort((string *)fileNames_, |
MikamiUitOpen | 11:769d986c10fa | 79 | (string *)fileNames_+fileCount_); |
MikamiUitOpen | 11:769d986c10fa | 80 | |
MikamiUitOpen | 11:769d986c10fa | 81 | Erase(X_, Y_, MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 272-Y_); |
MikamiUitOpen | 11:769d986c10fa | 82 | rect_->DrawAll(); |
MikamiUitOpen | 11:769d986c10fa | 83 | for (int n=0; n<fileCount_; n++) |
MikamiUitOpen | 11:769d986c10fa | 84 | fileNameLabels_[n]->Draw(GetFileNameNoExt(n)); |
MikamiUitOpen | 11:769d986c10fa | 85 | } |
MikamiUitOpen | 11:769d986c10fa | 86 | |
MikamiUitOpen | 11:769d986c10fa | 87 | // ファイルの一覧の消去 |
MikamiUitOpen | 11:769d986c10fa | 88 | void FileSelector::Erase(uint16_t x, uint16_t y, uint16_t width, uint16_t height, |
MikamiUitOpen | 11:769d986c10fa | 89 | uint32_t color) |
MikamiUitOpen | 11:769d986c10fa | 90 | { |
MikamiUitOpen | 11:769d986c10fa | 91 | lcd_->SetTextColor(color); |
MikamiUitOpen | 11:769d986c10fa | 92 | lcd_->FillRect(x, y, width, height); |
MikamiUitOpen | 11:769d986c10fa | 93 | } |
MikamiUitOpen | 11:769d986c10fa | 94 | |
MikamiUitOpen | 11:769d986c10fa | 95 | // Label を生成 |
MikamiUitOpen | 11:769d986c10fa | 96 | void FileSelector::CreateLabels() |
MikamiUitOpen | 11:769d986c10fa | 97 | { |
MikamiUitOpen | 11:769d986c10fa | 98 | fileNameLabels_.SetSize(fileCount_); |
MikamiUitOpen | 11:769d986c10fa | 99 | |
MikamiUitOpen | 11:769d986c10fa | 100 | for (int n=0; n<fileCount_; n++) |
MikamiUitOpen | 11:769d986c10fa | 101 | fileNameLabels_[n] = new Label(X_+30, Y_+5+V_L_*n, "", |
MikamiUitOpen | 11:769d986c10fa | 102 | Label::LEFT, Font16, |
MikamiUitOpen | 11:769d986c10fa | 103 | BASE_COLOR_); |
MikamiUitOpen | 11:769d986c10fa | 104 | } |
MikamiUitOpen | 11:769d986c10fa | 105 | |
MikamiUitOpen | 11:769d986c10fa | 106 | // 拡張子を削除した文字列を取得 |
MikamiUitOpen | 11:769d986c10fa | 107 | string FileSelector::GetFileNameNoExt(int n) |
MikamiUitOpen | 11:769d986c10fa | 108 | { |
MikamiUitOpen | 11:769d986c10fa | 109 | string name = fileNames_[n]; |
MikamiUitOpen | 11:769d986c10fa | 110 | name.erase(name.find(".")); |
MikamiUitOpen | 11:769d986c10fa | 111 | return name.substr(0, MAX_NAME_LENGTH_); |
MikamiUitOpen | 11:769d986c10fa | 112 | } |
MikamiUitOpen | 11:769d986c10fa | 113 | |
MikamiUitOpen | 11:769d986c10fa | 114 | } |