![](/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
Diff: MyClasses_Functions/FileSelectorWav.hpp
- Revision:
- 11:769d986c10fa
- Parent:
- 5:3e8ca1ed31a1
--- a/MyClasses_Functions/FileSelectorWav.hpp Wed Jun 15 13:16:49 2016 +0000 +++ b/MyClasses_Functions/FileSelectorWav.hpp Mon Jul 04 05:59:44 2016 +0000 @@ -1,18 +1,16 @@ //-------------------------------------------------------------- -// FileSelector class +// FileSelector class ---- Header ---- // SD カード内のファイル名の一覧を表示し,ファイルを選択する // -// 2016/04/18, Copyright (c) 2016 MIKAMI, Naoki +// 2016/06/30, Copyright (c) 2016 MIKAMI, Naoki //-------------------------------------------------------------- #ifndef FILE_SELECTOR_HPP #define FILE_SELECTOR_HPP -#include "mbed.h" #include "Label.hpp" #include "ButtonGroup.hpp" #include "SD_WavReader.hpp" -#include "SDFileSystem.h" #include <algorithm> // sort() で使用 #include <string> @@ -26,22 +24,68 @@ : X_(x0), Y_(y0), W_H_(24), V_L_(36), MAX_FILES_(maxFiles), MAX_NAME_LENGTH_(maxNameLength), BASE_COLOR_(0xFF80FFA0), TOUCHED_COLOR_(0xFF80FFFF), - fileNames_(new string[maxFiles]), - sortedFileNames_(new string[maxFiles]), - nonString_(NULL), rect_(NULL), fileNameLabels_(NULL), - lcd_(GuiBase::GetLcdPtr()), + fileNames_(maxFiles), + rect_(NULL), lcd_(GuiBase::GetLcdPtr()), sdReader_(reader), prevFileCount_(0), prev_(-1) {} ~FileSelector() - { - for (int n=0; n<fileCount_; n++) - delete fileNameLabels_[n]; - delete[] fileNameLabels_; - delete rect_; - delete[] nonString_; - delete[] sortedFileNames_; - delete[] fileNames_; - } + { delete rect_; } + + bool CreateTable(); + + // ファイルを選択する + bool Select(string &fileName); + + // ファイルの一覧の表示 + void DisplayFileList(bool sortEnable = true); + + // ファイルの一覧の消去 + void Erase(uint16_t x, uint16_t y, uint16_t width, uint16_t height, + uint32_t color = GuiBase::ENUM_BACK); + + private: + const uint8_t X_, Y_, W_H_, V_L_; + const int MAX_FILES_; + const int MAX_NAME_LENGTH_; + const uint32_t BASE_COLOR_; + const uint32_t TOUCHED_COLOR_; + + Array<string> fileNames_; + ButtonGroup *rect_; + Array<Label *> fileNameLabels_; + LCD_DISCO_F746NG *lcd_; + SD_WavReader &sdReader_; + int fileCount_, prevFileCount_; + int prev_; + + // Label を生成 + void CreateLabels(); + + // 拡張子を削除した文字列を取得 + string GetFileNameNoExt(int n); + + // disallow copy constructor and assignment operator + FileSelector(const FileSelector&); + FileSelector& operator=(const FileSelector&); + }; +} +/* +namespace Mikami +{ + class FileSelector + { + public: + FileSelector(uint8_t x0, uint8_t y0, int maxFiles, + int maxNameLength, SD_WavReader &reader) + : X_(x0), Y_(y0), W_H_(24), V_L_(36), + MAX_FILES_(maxFiles), MAX_NAME_LENGTH_(maxNameLength), + BASE_COLOR_(0xFF80FFA0), TOUCHED_COLOR_(0xFF80FFFF), + fileNames_(maxFiles), + rect_(NULL), lcd_(GuiBase::GetLcdPtr()), + sdReader_(reader), prevFileCount_(0), prev_(-1) {} + + ~FileSelector() + { delete rect_; } bool CreateTable() { @@ -63,30 +107,23 @@ // PCM,16 ビットステレオ,標本化周波数 44.1 kHz 以外のファイルは除外 if (sdReader_.IsWavFile()) - { - fileNames_[fileCount_] = strName; - fileCount_++; - } + fileNames_[fileCount_++] = strName; sdReader_.Close(); } - if (fileCount_ >= MAX_FILES_) break; } closedir(dp); } else return false; - + if (fileCount_ == 0) return false; - if (nonString_ == NULL) delete[] nonString_; - nonString_ = new string[fileCount_]; - for (int n=0; n<fileCount_; n++) nonString_[n] = ""; - if (rect_ != NULL) delete rect_; + Array<string> nonString(fileCount_, ""); rect_ = new ButtonGroup(X_, Y_, W_H_, W_H_, fileCount_, - nonString_, 0, V_L_-W_H_, 1, + nonString, 0, V_L_-W_H_, 1, -1, Font12, 0, GuiBase::ENUM_BACK, BASE_COLOR_, TOUCHED_COLOR_); for (int n=0; n<fileCount_; n++) rect_->Erase(n); @@ -105,7 +142,7 @@ if ((prev_ >= 0) && (prev_ != n)) fileNameLabels_[prev_]->Draw(GetFileNameNoExt(prev_)); prev_ = n; - fileName = sortedFileNames_[n]; + fileName = fileNames_[n]; return true; } else @@ -113,34 +150,26 @@ } // ファイルの一覧の表示 - void DisplayFileList(bool sort = true) + void DisplayFileList(bool sortEnable = true) { - for (int n=0; n<fileCount_; n++) - sortedFileNames_[n] = fileNames_[n]; - if (sort) - std::sort(sortedFileNames_, sortedFileNames_+fileCount_); + if (sortEnable) + std::sort((string *)fileNames_, + (string *)fileNames_+fileCount_); -//// Erase(MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 270-Y_); - Erase(X_, 0, MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 288); + Erase(X_, Y_, MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 272-Y_); rect_->DrawAll(); for (int n=0; n<fileCount_; n++) fileNameLabels_[n]->Draw(GetFileNameNoExt(n)); } -/* - void Erase(uint16_t width, uint16_t height, - uint32_t color = GuiBase::ENUM_BACK) - { - lcd_->SetTextColor(color); - lcd_->FillRect(X_, Y_, width, height); - } -*/ + // ファイルの一覧の消去 void Erase(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color = GuiBase::ENUM_BACK) { lcd_->SetTextColor(color); lcd_->FillRect(x, y, width, height); } + private: const uint8_t X_, Y_, W_H_, V_L_; const int MAX_FILES_; @@ -148,11 +177,9 @@ const uint32_t BASE_COLOR_; const uint32_t TOUCHED_COLOR_; - string *fileNames_; - string *sortedFileNames_; - string *nonString_; + Array<string> fileNames_; ButtonGroup *rect_; - Label **fileNameLabels_; + Array<Label *> fileNameLabels_; LCD_DISCO_F746NG *lcd_; SD_WavReader &sdReader_; int fileCount_, prevFileCount_; @@ -161,13 +188,8 @@ // Label を生成 void CreateLabels() { - if (fileNameLabels_ != NULL) - { - for (int n=0; n<prevFileCount_; n++) - delete fileNameLabels_[n]; - delete[] fileNameLabels_; - } - fileNameLabels_ = new Label *[fileCount_+1]; + fileNameLabels_.SetSize(fileCount_); + for (int n=0; n<fileCount_; n++) fileNameLabels_[n] = new Label(X_+30, Y_+5+V_L_*n, "", Label::LEFT, Font16, @@ -177,7 +199,7 @@ // 拡張子を削除した文字列を取得 string GetFileNameNoExt(int n) { - string name = sortedFileNames_[n]; + string name = fileNames_[n]; name.erase(name.find(".")); return name.substr(0, MAX_NAME_LENGTH_); } @@ -187,4 +209,6 @@ FileSelector& operator=(const FileSelector&); }; } +*/ #endif // FILE_SELECTOR_HPP +