boting ren / Mbed 2 deprecated F746_SD_GraphicEqualizer_ren0620

Dependencies:   BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Fork of F746_SD_GraphicEqualizer by 不韋 呂

Files at this revision

API Documentation at this revision

Comitter:
edamame22
Date:
Wed Jun 22 03:50:38 2016 +0000
Parent:
9:0d5bd1539291
Child:
11:2286f2668e8c
Commit message:
auto play is enabled

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
F746_GUI.lib Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/FileSelectorWav.hpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/MyFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/MyFunctions.hpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/SD_WavReader.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/SD_WavReader.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BSP_DISCO_F746NG.lib	Mon May 09 13:48:33 2016 +0000
+++ b/BSP_DISCO_F746NG.lib	Wed Jun 22 03:50:38 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#458ab1edf6b2
+http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#286943c42d38
--- a/F746_GUI.lib	Mon May 09 13:48:33 2016 +0000
+++ b/F746_GUI.lib	Wed Jun 22 03:50:38 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#687ec6183385
+http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#95544440b46c
--- a/MyClasses_Functions/FileSelectorWav.hpp	Mon May 09 13:48:33 2016 +0000
+++ b/MyClasses_Functions/FileSelectorWav.hpp	Wed Jun 22 03:50:38 2016 +0000
@@ -16,6 +16,7 @@
 #include <algorithm>    // sort() で使用
 #include <string>
 
+
 namespace Mikami
 {
     class FileSelector
@@ -25,7 +26,7 @@
                      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),
+              BASE_COLOR_(0xFFDBAD17), TOUCHED_COLOR_(0xFFF8F8FB),
               fileNames_(new string[maxFiles]),
               sortedFileNames_(new string[maxFiles]),
               nonString_(NULL), rect_(NULL), fileNameLabels_(NULL),
@@ -42,7 +43,15 @@
             delete[] sortedFileNames_;
             delete[] fileNames_;
         }
-        
+// ren: show a string        
+       void ren_Msg(int pos, char msg[])
+        {  int lin, y_pos[7]= {0,70,130,160,190,220,250};
+        if(pos<0) lin=0;
+        else if (pos>6)  lin=6;
+        else lin=pos;
+        Label renLabel(240, y_pos[lin], msg, Label::CENTER,Font20);
+        }  
+              
         bool CreateTable()
         {
             DIR* dp = opendir("/sd");
@@ -50,7 +59,8 @@
             if (dp != NULL)
             {
                 dirent* entry;
-                for (int n=0; n<256; n++)
+                // ren: change n<256 to n<2560
+                for (int n=0; n<2560; n++)
                 {
                     entry = readdir(dp);
                     if (entry == NULL) break;
@@ -60,13 +70,24 @@
                          (strName.find(".WAV") != string::npos) )
                     {
                         sdReader_.Open(strName);        // ファイルオープン
-
+/**{
+char tmpmsg[500];
+sprintf(tmpmsg, "1..found a file: %s", strName.c_str()); 
+ren_Msg(1,tmpmsg);
+sprintf(tmpmsg, "2..fileCount_: %d", fileCount_);
+ren_Msg(2,tmpmsg);
+}**/
                         // PCM,16 ビットステレオ,標本化周波数 44.1 kHz 以外のファイルは除外
                         if (sdReader_.IsWavFile())
                         {
                             fileNames_[fileCount_] = strName;
                             fileCount_++;
                         }
+/**{
+char tmpmsg[500];
+sprintf(tmpmsg, "fileCount_: %d", fileCount_); 
+ren_Msg(3, tmpmsg);
+}**/
                         sdReader_.Close();
                     }
 
@@ -87,16 +108,17 @@
             if (rect_ != NULL) delete rect_;
             rect_ = new ButtonGroup(X_, Y_, W_H_, W_H_, fileCount_,
                                     nonString_, 0, V_L_-W_H_, 1,
-                                    -1, Font12, 0, GuiBase::ENUM_BACK,
+                                    -1, true,Font12, 0, GuiBase::ENUM_BACK,
                                     BASE_COLOR_, TOUCHED_COLOR_);
             for (int n=0; n<fileCount_; n++) rect_->Erase(n);
             CreateLabels();   
             prevFileCount_ = fileCount_;
+ 
             return true;
         }
 
         // ファイルを選択する
-        bool Select(string &fileName)
+        bool Select(string fileList[],int *idx)
         {
             int n;
             if (rect_->GetTouchedNumber(n))
@@ -105,7 +127,10 @@
                 if ((prev_ >= 0) && (prev_ != n))
                     fileNameLabels_[prev_]->Draw(GetFileNameNoExt(prev_));
                 prev_ = n;
-                fileName = sortedFileNames_[n];
+                *idx = n;
+                for (int n=0; n<fileCount_; n++) fileList[n] = sortedFileNames_[n];
+//                fileName = sortedFileNames_[n];
+//printf("\nSelected file : %s", fileName);
                 return true;
             }
             else
--- a/MyClasses_Functions/MyFunctions.cpp	Mon May 09 13:48:33 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.cpp	Wed Jun 22 03:50:38 2016 +0000
@@ -43,15 +43,16 @@
 // ファイルの選択
 //      selectedName:   選択されたファイル名
 void SelectFile(ButtonGroup &menu, FileSelector &selector,
-                Label &msg, string &selectedName)
+                Label &msg, string fileList[], int *selected)
 {
     selector.DisplayFileList();   
     msg.Draw("Select file");
     do
     {
-        if (selector.Select(selectedName))
+        if (selector.Select(fileList, selected))
             menu.Activate(1);   // PLAY 有効
-        wait_ms(200);
+ // ren: change wait timer 200 to 60
+        wait_ms(60);
     } while (!menu.Touched(1)); // PLAY がタッチされるまで繰り返す
 }
 
--- a/MyClasses_Functions/MyFunctions.hpp	Mon May 09 13:48:33 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.hpp	Wed Jun 22 03:50:38 2016 +0000
@@ -28,7 +28,7 @@
 
 // ファイルの選択
 void SelectFile(ButtonGroup &menu, FileSelector &selector,
-                Label &msg, string &selectedName);
+                Label &msg, string fileList[], int *selected);
 
 // フィルタの変更
 void ModifyFilter(DesignerDrawer &drawerObj,
--- a/MyClasses_Functions/SD_WavReader.cpp	Mon May 09 13:48:33 2016 +0000
+++ b/MyClasses_Functions/SD_WavReader.cpp	Wed Jun 22 03:50:38 2016 +0000
@@ -48,7 +48,10 @@
 
         // "RIFF", "WAVE", "fmt " が存在することを確認
         if (strRead != "RIFFWAVEfmt ") return false;
-
+/**{
+ char dump[500]; strcpy(dump, strRead.c_str());
+ren_Msg1(4, dump);
+}**/
         // fmt chunck のサイズを取得
         uint32_t fmtChunkSize;
         fread(&fmtChunkSize, sizeof(uint32_t), 1, fp_);
@@ -56,18 +59,35 @@
         // PCM, Stereo, 44.1 kHz, 16 bit であることを確認
         WaveFormatEx fmtData;
         fread(&fmtData, fmtChunkSize, 1, fp_);
+
         if ((fmtData.wFormatTag     != 1)     ||
             (fmtData.nChannels      != 2)     ||
             (fmtData.nSamplesPerSec != 44100) ||
             (fmtData.wBitsPerSample != 16)
-           ) return false;
-
+           )
+           return false;
+/**{
+    char dump[500];
+sprintf(dump, "wFormatTag: %d", fmtData.wFormatTag);
+ren_Msg1(1, dump);
+sprintf(dump, "nChannels: %d", fmtData.nChannels);
+ren_Msg1(2, dump);
+sprintf(dump, "nSamplesPerSec: %d", fmtData.nSamplesPerSec);
+ren_Msg1(3, dump);
+sprintf(dump, "wBitsPerSample: %d", fmtData.wBitsPerSample);
+ren_Msg1(4, dump); 
+}**/
         // data chunk を探す
         char dataId[5];
         dataId[4] = 0;
         fread(dataId, 1, 4, fp_);
+/**{
+    char dump[500];
+sprintf(dump, "dataId: %s", dataId);
+ren_Msg1(5, dump); wait(20.0f);
+}**/
         if ("data" != (string)dataId)
-            for (int n=0; n<100; n++)
+            for (int n=0; n<1000; n++)
             {
                 char oneByte;
                 fread(&oneByte, 1, 1, fp_);
@@ -76,7 +96,7 @@
                 dataId[3] = oneByte;
                 if ("data" == (string)dataId) break;
                 
-                if (n == 99) return false;
+                if (n == 999) return false;
             }
 
         // データサイズ (byte) を取得
--- a/MyClasses_Functions/SD_WavReader.hpp	Mon May 09 13:48:33 2016 +0000
+++ b/MyClasses_Functions/SD_WavReader.hpp	Wed Jun 22 03:50:38 2016 +0000
@@ -39,7 +39,21 @@
         
         // データサイズ(標本化点の数)の取得
         int32_t GetSize();
-
+        
+        // ren: show a string        
+/*       void ren_Msg1(int pos, char msg[])
+        {  int lin, str_ln, y_pos[7]= {0,70,130,160,190,220,250};
+//        char msg[501];
+//        strcpy(msg, str_msg.c_str());
+//        str_ln=str_msg.size();
+//        if(str_ln>500) str_ln=500;
+//        msg[str_ln]='\0';
+        if(pos<0) lin=0;
+        else if (pos>6)  lin=6;
+        else lin=pos;
+        Label renLabel(0, y_pos[lin], msg, Label::LEFT,Font20);
+        }  
+*/
     private:
         const string STR_;
         
--- a/main.cpp	Mon May 09 13:48:33 2016 +0000
+++ b/main.cpp	Wed Jun 22 03:50:38 2016 +0000
@@ -12,6 +12,9 @@
 #include "BlinkLabel.hpp"
 
 using namespace Mikami;
+enum ts_State {
+    IDLE_NOPALY, SELECTED_PREPARE_PALY, PALYING, PAUSED, STOPPED, RESUMED
+};
 
 int main()
 {
@@ -23,6 +26,8 @@
 
     SD_WavReader sdReader(mySai.GetLength());   // SD カード読み込み用オブジェクト
     const int MAX_FILES = 7;
+    string PlayList[MAX_FILES];
+    int list_id = 0;
     FileSelector selector(4, 26, MAX_FILES, 37, sdReader);
     if (!selector.CreateTable())
         BlinkLabel errLabel(240, 100, "SD CARD ERROR", Label::CENTER);
@@ -39,8 +44,8 @@
     // OPEN のみアクティブ
     menu.Activate(0);
     for (int n=1; n<5; n++) menu.Inactivate(n);
-
-    Button flat(BG_LEFT, 197, BG_WIDTH, BG_HEIGHT, "FLAT");
+//    printf("Button flat with 0 expanded detection Area\n");
+    Button flat(BG_LEFT, 197, BG_WIDTH, BG_HEIGHT, 0, "FLAT");
 
     const string ON_OFF[2] = {"ON", "OFF"};
     ButtonGroup onOff(BG_LEFT, 235, BG_WIDTH/2, BG_HEIGHT,
@@ -49,12 +54,12 @@
     // フィルタの設計と周波数特性描画用
     const int STAGES = 9;       // バンド数
     DesignerDrawer drawerObj(
-                     28,        // グラフの左端の位置
-                     130,       // グラフの下端の位置
-                     STAGES,    // バンド数
-                     62.5f,     // 最低域バンドの中心周波数
-                     FS,        // 標本化周波数
-                     2.5f);     // 1 dB 当たりのピクセル数
+        28,        // グラフの左端の位置
+        130,       // グラフの下端の位置
+        STAGES,    // バンド数
+        62.5f,     // 最低域バンドの中心周波数
+        FS,        // 標本化周波数
+        2.5f);     // 1 dB 当たりのピクセル数
 
     // 周波数特性変更用スライダ
     SeekbarGroup myBars(drawerObj.GetX0(), 178, 82, STAGES,
@@ -69,94 +74,103 @@
 
     int32_t frameSize = mySai.GetLength();
     int16_t *sn = new int16_t[frameSize+1]; // フレームバッファ
-    bool playOk = false;
     bool on = true;
-    bool whileFirst = true;
     string fileName;
     int32_t loopCount;
-
-    while (true)
-    {
-        if (!playOk)
-        {
-            if (whileFirst)
-            {
-                whileFirst = false;
+    ts_State ui_mode = IDLE_NOPALY;
+    int k;
+    while (true) {
+        switch(ui_mode) {
+            case IDLE_NOPALY:
                 while (!menu.Touched(0))    // OPEN がタッチされるまで待つ
                     ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
-                SelectFile(menu, selector, myLabel1, fileName);
+                for(int m=0; m<MAX_FILES; m++)  PlayList[m]="";      // clear playlist
+                SelectFile(menu, selector, myLabel1, PlayList, &list_id);   // returned playlist and selected ID
+                ui_mode = SELECTED_PREPARE_PALY ;
+            case SELECTED_PREPARE_PALY:
+            printf(" current track is %s  ******\n", PlayList[list_id].c_str());
+                loopCount = SD_Open(sdReader, PlayList[list_id], frameSize);
+                // while (!menu.Touched(1))   // PLAY がタッチされるまで待つ
+                //     ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
+                selector.Erase(0, 0, BG_LEFT-4, 288);
+                myLabel1.Draw("9-band Graphic Equalizer");
+                myBars.RedrawAll();
+                drawerObj.DrawResponse();
+                menu.Inactivate(0); // OPEN 無効
+                menu.Activate(2);   // PAUSE 有効
+                menu.Activate(4);   // STOP 有効
+                // IIR フィルタの内部の遅延器のクリア
+                for (int j=0; j<STAGES; j++) hn[j].Clear();
+                mySai.PlayOut();    // Play 開始
+                ui_mode = PALYING ;
+                k=0;
+            case PALYING:
+                for (; k<loopCount && ui_mode==PALYING; k++) {
+                    int touch42 = -1;
+                    menu.GetTouchedNumber(touch42);
+                    if (touch42 == 4)     ui_mode = STOPPED;      // STOP
+                    else if (touch42 == 2)   ui_mode = PAUSED;    // PAUSE
+                    ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
+                    // 1フレーム分の信号処理 (イコライザ) の実行
+                    SignalProcessing(sdReader, mySai, sn, hn, STAGES, on);
+                }
+                if(ui_mode == PAUSED)   break;   // Paused 
+                mySai.StopOut();    // current track play ended
+                sdReader.Close();   // SD のファイルのクローズ
+                if(ui_mode == STOPPED)   break;   // Stopped 
+                
+                if (list_id < MAX_FILES-1) {  // goto next track
+                    if (PlayList[list_id+1].empty())   list_id=0;
+                    else  list_id++;
+                } else list_id=0;
+                ui_mode = SELECTED_PREPARE_PALY;
+                break;
+            case PAUSED: {
+                menu.Inactivate(2); // PAUSE 無効
+                menu.Activate(3);   // RESUME 有効
+                mySai.PauseOut();
+                // PLAY か RESUME か STOP がタッチされるまで待つ
+                int touch134 = -1;
+                while (!menu.GetTouchedNumber(touch134))
+                    ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
+                if(touch134 == 3) {
+                    ui_mode = RESUMED;
+                    break;  // PAUSE したところから PLAY 再開
+                }
+                mySai.ResumeOut();  // PAUSE したところから PLAY 再開 またはSTOPの後処理
+                mySai.StopOut();
+                sdReader.Close();   // SD のファイルのクローズ
+
+                if(touch134 == 4) {
+                    ui_mode = STOPPED;      break;    // STOP
+                }
+                if(touch134 == 1) {
+                    ui_mode = SELECTED_PREPARE_PALY;      // 最初から PLAY
+                    menu.Inactivate(3);      // RESUME disable to start play
+                    break;
+                }
+                printf("a very bad wrong point\n");
+                break;
             }
-            else
-            {
-                menu.Activate(1);       // PLAY 有効
+            case STOPPED:
+                menu.Activate(0);               // OPEN 有効
+                menu.Activate(1);               // PLAY 有効
+                for (int n=2; n<5; n++)         // その他は無効
+                    menu.Inactivate(n);
                 int touch10;
                 while (!menu.GetTouchedNumber(touch10))
                     ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
                 if (touch10 == 0)
-                    SelectFile(menu, selector, myLabel1, fileName);
-            }
-
-            loopCount = SD_Open(sdReader, fileName, frameSize);
-            while (!menu.Touched(1))   // PLAY がタッチされるまで待つ
-                ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
+                    SelectFile(menu, selector, myLabel1, PlayList, &list_id);
+                ui_mode = SELECTED_PREPARE_PALY;
+                break;
+            case RESUMED:
+                mySai.ResumeOut();  // PAUSE したところから PLAY 再開
+                menu.Activate(2);
+                menu.Inactivate(3);
+                menu.TouchedColor(1);
+                ui_mode = PALYING;
+                break;
         }
-        else
-            loopCount = SD_Open(sdReader, fileName, frameSize);
-
-        selector.Erase(0, 0, BG_LEFT-4, 288);
-        myLabel1.Draw("9-band Graphic Equalizer");
-        myBars.RedrawAll();
-        drawerObj.DrawResponse();
-        menu.Inactivate(0); // OPEN 無効
-        menu.Activate(2);   // PAUSE 有効
-        menu.Activate(4);   // STOP 有効
-
-        playOk = false;
-        bool stopOk = false;
-
-        // IIR フィルタの内部の遅延器のクリア
-        for (int k=0; k<STAGES; k++) hn[k].Clear();
-        mySai.PlayOut();    // Play 開始
-
-        for (int k=0; k<loopCount; k++)
-        {
-            int touch42 = -1;
-            menu.GetTouchedNumber(touch42);
-            if (touch42 == 4) break;    // STOP
-            if (touch42 == 2)           // PAUSE
-            {
-                menu.Inactivate(2); // PAUSE 無効
-                menu.Activate(3);   // RESUME 有効
-                mySai.PauseOut();
-
-                // PLAY か RESUME か STOP がタッチされるまで待つ
-                int touch134 = -1;
-                while (!menu.GetTouchedNumber(touch134))
-                    ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
-                switch (touch134)
-                {
-                    case 1: playOk = true;      // 最初から PLAY
-                            break;
-                    case 3: mySai.ResumeOut();  // PAUSE したところから PLAY 再開
-                            menu.Activate(2);
-                            menu.Inactivate(3);
-                            menu.TouchedColor(1);
-                            break;
-                    case 4: stopOk = true;      // STOP
-                            break;
-                }
-            }
-            if (playOk || stopOk) break;
-
-            ModifyFilter(drawerObj, myBars, hn, flat, onOff, on);
-            // 1フレーム分の信号処理 (イコライザ) の実行
-            SignalProcessing(sdReader, mySai, sn, hn, STAGES, on);
-        }
-        mySai.StopOut();
-        menu.Activate(0);               // OPEN 有効
-        if (!playOk) menu.Activate(1);  // PLAY 有効
-        for (int n=2; n<5; n++)         // その他は無効
-            menu.Inactivate(n);
-        sdReader.Close();   // SD のファイルのクローズ
     }
 }