Library for Skeleton of SD card player. SD カードプレーヤのための骨組みとして使うためのライブラリ.このライブラリを登録した際のプログラム:「F746_SD_Player_Demo」

Dependencies:   SDFileSystem_Warning_Fixed

Dependents:   F746_SD_Player_Demo F746_SD_VarableFilter F746_SD_GraphicEqualizer F746_MySoundMachine ... more

Committer:
MikamiUitOpen
Date:
Mon Jan 16 00:40:08 2017 +0000
Revision:
9:1ba92e340dce
Parent:
8:59d3f9c81c4f
Child:
10:303d6435a09b
10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:d310bb78455d 1 //--------------------------------------------------------------
MikamiUitOpen 0:d310bb78455d 2 // SD プレーヤー用抽象基底クラス
MikamiUitOpen 0:d310bb78455d 3 //
MikamiUitOpen 9:1ba92e340dce 4 // 2017/01/16, Copyright (c) 2016 MIKAMI, Naoki
MikamiUitOpen 0:d310bb78455d 5 //--------------------------------------------------------------
MikamiUitOpen 0:d310bb78455d 6
MikamiUitOpen 0:d310bb78455d 7 #include "SD_PlayerSkeleton.hpp"
MikamiUitOpen 0:d310bb78455d 8
MikamiUitOpen 0:d310bb78455d 9 namespace Mikami
MikamiUitOpen 0:d310bb78455d 10 {
MikamiUitOpen 5:7c8f0fc9dfb6 11 SD_PlayerSkeleton::SD_PlayerSkeleton(string str, int fs, bool resetButton)
MikamiUitOpen 0:d310bb78455d 12 : FRAME_SIZE_(2048), sn_(FRAME_SIZE_),
MikamiUitOpen 0:d310bb78455d 13 mySai_(SaiIO::OUTPUT, FRAME_SIZE_, fs),
MikamiUitOpen 0:d310bb78455d 14 sdReader_(FRAME_SIZE_),
MikamiUitOpen 8:59d3f9c81c4f 15 fileName_(""),
MikamiUitOpen 0:d310bb78455d 16 title_(214, 4, str, Label::CENTER, Font16),
MikamiUitOpen 2:511479736d6e 17 selector_(0, 22, 256, 37, sdReader_),
MikamiUitOpen 0:d310bb78455d 18 menu_(BG_LEFT_, 2, BG_WIDTH_, BG_HEIGHT_, 5,
MikamiUitOpen 0:d310bb78455d 19 (string[]){"OPEN", "PLAY", "PAUSE", "RESUME", "STOP"},
MikamiUitOpen 5:7c8f0fc9dfb6 20 0, 2, 1)
MikamiUitOpen 0:d310bb78455d 21 {
MikamiUitOpen 0:d310bb78455d 22 if (!selector_.CreateTable())
MikamiUitOpen 0:d310bb78455d 23 BlinkLabel errLabel(240, 100, "SD CARD ERROR", Label::CENTER);
MikamiUitOpen 0:d310bb78455d 24
MikamiUitOpen 0:d310bb78455d 25 menu_.InactivateAll();
MikamiUitOpen 0:d310bb78455d 26 menu_.Activate(0);
MikamiUitOpen 5:7c8f0fc9dfb6 27 if (resetButton) reset_ = new ResetButton();
MikamiUitOpen 5:7c8f0fc9dfb6 28 else reset_ = NULL;
MikamiUitOpen 0:d310bb78455d 29 }
MikamiUitOpen 0:d310bb78455d 30
MikamiUitOpen 6:6fe2b62f259d 31 // SD プレーヤーの処理の実行
MikamiUitOpen 0:d310bb78455d 32 void SD_PlayerSkeleton::Execute()
MikamiUitOpen 0:d310bb78455d 33 {
MikamiUitOpen 5:7c8f0fc9dfb6 34 bool playAfterPause = false;
MikamiUitOpen 5:7c8f0fc9dfb6 35 int32_t loopCount;
MikamiUitOpen 5:7c8f0fc9dfb6 36
MikamiUitOpen 6:6fe2b62f259d 37 WaitTouched(0); // OPEN がタッチされるまで待つ
MikamiUitOpen 0:d310bb78455d 38
MikamiUitOpen 0:d310bb78455d 39 while (true)
MikamiUitOpen 0:d310bb78455d 40 {
MikamiUitOpen 8:59d3f9c81c4f 41 if (playAfterPause) // PAUSE 後の PLAY の場合
MikamiUitOpen 8:59d3f9c81c4f 42 loopCount = SD_Open();
MikamiUitOpen 8:59d3f9c81c4f 43 else // PAUSE 後の PLAY ではない場合
MikamiUitOpen 0:d310bb78455d 44 {
MikamiUitOpen 8:59d3f9c81c4f 45 if (WaitTouched() == 0) SelectFile();
MikamiUitOpen 0:d310bb78455d 46 loopCount = SD_Open();
MikamiUitOpen 6:6fe2b62f259d 47 WaitTouched(1); // PLAY がタッチされるまで待つ
MikamiUitOpen 0:d310bb78455d 48 }
MikamiUitOpen 0:d310bb78455d 49
MikamiUitOpen 0:d310bb78455d 50 selector_.Erase(0, 0, BG_LEFT_-4, 272);
MikamiUitOpen 0:d310bb78455d 51 title_.Draw();
MikamiUitOpen 0:d310bb78455d 52
MikamiUitOpen 5:7c8f0fc9dfb6 53 Display(); // アプリ固有の表示処理(仮想関数)
MikamiUitOpen 5:7c8f0fc9dfb6 54 if (reset_ != NULL) reset_->Draw();
MikamiUitOpen 0:d310bb78455d 55
MikamiUitOpen 5:7c8f0fc9dfb6 56 menu_.Inactivate(0); // OPEN ボタン無効
MikamiUitOpen 5:7c8f0fc9dfb6 57 menu_.Activate(2); // PAUSE ボタン有効
MikamiUitOpen 5:7c8f0fc9dfb6 58 menu_.Activate(4); // STOP ボタン有効
MikamiUitOpen 0:d310bb78455d 59
MikamiUitOpen 5:7c8f0fc9dfb6 60 playAfterPause = false;
MikamiUitOpen 0:d310bb78455d 61 bool stopOk = false;
MikamiUitOpen 0:d310bb78455d 62
MikamiUitOpen 5:7c8f0fc9dfb6 63 Clear(); // アプリ固有のクリア処理(仮想関数)
MikamiUitOpen 0:d310bb78455d 64
MikamiUitOpen 0:d310bb78455d 65 mySai_.PlayOut(); // Play 開始
MikamiUitOpen 0:d310bb78455d 66
MikamiUitOpen 6:6fe2b62f259d 67 // ファイルのデータがなくなるまで繰り返す
MikamiUitOpen 0:d310bb78455d 68 for (int k=0; k<loopCount; k++)
MikamiUitOpen 0:d310bb78455d 69 {
MikamiUitOpen 0:d310bb78455d 70 int touch42 = -1;
MikamiUitOpen 0:d310bb78455d 71 menu_.GetTouchedNumber(touch42);
MikamiUitOpen 0:d310bb78455d 72 if (touch42 == 4) break; // STOP
MikamiUitOpen 5:7c8f0fc9dfb6 73 if (touch42 == 2) // PAUSE ボタンがタッチされた場合の処理
MikamiUitOpen 0:d310bb78455d 74 {
MikamiUitOpen 5:7c8f0fc9dfb6 75 menu_.Inactivate(2); // PAUSE ボタン無効
MikamiUitOpen 5:7c8f0fc9dfb6 76 menu_.Activate(3); // RESUME ボタン有効
MikamiUitOpen 0:d310bb78455d 77 mySai_.PauseOut();
MikamiUitOpen 0:d310bb78455d 78
MikamiUitOpen 0:d310bb78455d 79 // PLAY か RESUME か STOP がタッチされるまで待つ
MikamiUitOpen 6:6fe2b62f259d 80 switch (WaitTouched())
MikamiUitOpen 0:d310bb78455d 81 {
MikamiUitOpen 5:7c8f0fc9dfb6 82 case 1: playAfterPause = true; // 最初から PLAY
MikamiUitOpen 0:d310bb78455d 83 break;
MikamiUitOpen 8:59d3f9c81c4f 84 case 3: mySai_.ResumeOut(); // PAUSE 箇所から PLAY 再開
MikamiUitOpen 8:59d3f9c81c4f 85 menu_.Activate(2);
MikamiUitOpen 0:d310bb78455d 86 menu_.Inactivate(3);
MikamiUitOpen 0:d310bb78455d 87 menu_.TouchedColor(1);
MikamiUitOpen 0:d310bb78455d 88 break;
MikamiUitOpen 5:7c8f0fc9dfb6 89 case 4: stopOk = true; // STOP
MikamiUitOpen 0:d310bb78455d 90 break;
MikamiUitOpen 0:d310bb78455d 91 }
MikamiUitOpen 0:d310bb78455d 92 }
MikamiUitOpen 5:7c8f0fc9dfb6 93 if (playAfterPause || stopOk) break;
MikamiUitOpen 0:d310bb78455d 94
MikamiUitOpen 6:6fe2b62f259d 95 DoIfHandled();
MikamiUitOpen 5:7c8f0fc9dfb6 96 // アプリ固有の1フレーム分の信号処理(純粋仮想関数)
MikamiUitOpen 0:d310bb78455d 97 SignalProcessing();
MikamiUitOpen 0:d310bb78455d 98 }
MikamiUitOpen 0:d310bb78455d 99 mySai_.StopOut();
MikamiUitOpen 8:59d3f9c81c4f 100 menu_.Activate(0); // OPEN ボタン有効
MikamiUitOpen 8:59d3f9c81c4f 101 menu_.Draw(1); // PLAY ボタンの色を初期状態にする
MikamiUitOpen 8:59d3f9c81c4f 102 for (int n=2; n<5; n++) // その他のボタンは無効
MikamiUitOpen 0:d310bb78455d 103 menu_.Inactivate(n);
MikamiUitOpen 5:7c8f0fc9dfb6 104
MikamiUitOpen 0:d310bb78455d 105 sdReader_.Close(); // SD のファイルのクローズ
MikamiUitOpen 0:d310bb78455d 106 }
MikamiUitOpen 0:d310bb78455d 107 }
MikamiUitOpen 0:d310bb78455d 108
MikamiUitOpen 6:6fe2b62f259d 109 // 選択されたファイル名から拡張子を除いたものを取得
MikamiUitOpen 4:d730d024ac32 110 string SD_PlayerSkeleton::GetFileNameNoExt()
MikamiUitOpen 4:d730d024ac32 111 {
MikamiUitOpen 4:d730d024ac32 112 string fName = fileName_;
MikamiUitOpen 4:d730d024ac32 113 int k = fName.rfind(".");
MikamiUitOpen 4:d730d024ac32 114 if (k != string::npos)
MikamiUitOpen 4:d730d024ac32 115 return fName.erase(k);
MikamiUitOpen 4:d730d024ac32 116 else
MikamiUitOpen 4:d730d024ac32 117 return fName;
MikamiUitOpen 4:d730d024ac32 118 }
MikamiUitOpen 4:d730d024ac32 119
MikamiUitOpen 0:d310bb78455d 120 // SD カードのファイルのオープン
MikamiUitOpen 0:d310bb78455d 121 int32_t SD_PlayerSkeleton::SD_Open()
MikamiUitOpen 0:d310bb78455d 122 {
MikamiUitOpen 8:59d3f9c81c4f 123 if (fileName_.empty()) SelectFile();
MikamiUitOpen 0:d310bb78455d 124 sdReader_.Open(fileName_);
MikamiUitOpen 0:d310bb78455d 125 sdReader_.IsWavFile();
MikamiUitOpen 0:d310bb78455d 126 return sdReader_.GetSize()/FRAME_SIZE_;
MikamiUitOpen 0:d310bb78455d 127 }
MikamiUitOpen 0:d310bb78455d 128
MikamiUitOpen 0:d310bb78455d 129 // ファイルの選択
MikamiUitOpen 0:d310bb78455d 130 void SD_PlayerSkeleton::SelectFile()
MikamiUitOpen 0:d310bb78455d 131 {
MikamiUitOpen 5:7c8f0fc9dfb6 132 selector_.DisplayFileList();
MikamiUitOpen 0:d310bb78455d 133 title_.Draw("Select file");
MikamiUitOpen 5:7c8f0fc9dfb6 134 menu_.Inactivate(1); // PLAY ボタン無効
MikamiUitOpen 0:d310bb78455d 135 do
MikamiUitOpen 0:d310bb78455d 136 if (selector_.Select(fileName_))
MikamiUitOpen 5:7c8f0fc9dfb6 137 menu_.Activate(1); // PLAY ボタン有効
MikamiUitOpen 5:7c8f0fc9dfb6 138 while (!menu_.Touched(1)); // PLAY ボタンがタッチされるまで繰り返す
MikamiUitOpen 0:d310bb78455d 139 }
MikamiUitOpen 1:c7968701f7b3 140
MikamiUitOpen 6:6fe2b62f259d 141 // パネルが操作された場合の処理
MikamiUitOpen 6:6fe2b62f259d 142 void SD_PlayerSkeleton::DoIfHandled()
MikamiUitOpen 1:c7968701f7b3 143 {
MikamiUitOpen 9:1ba92e340dce 144 if (reset_ != NULL) reset_->DoIfTouched();
MikamiUitOpen 5:7c8f0fc9dfb6 145 Modefy(); // アプリ固有のパラメータ変更(仮想関数)
MikamiUitOpen 1:c7968701f7b3 146 }
MikamiUitOpen 6:6fe2b62f259d 147
MikamiUitOpen 8:59d3f9c81c4f 148 // メニューのボタンがタッチされるまで DoIfHandled() を実行しながら待つ
MikamiUitOpen 6:6fe2b62f259d 149 int SD_PlayerSkeleton::WaitTouched()
MikamiUitOpen 6:6fe2b62f259d 150 {
MikamiUitOpen 6:6fe2b62f259d 151 int touchNum;
MikamiUitOpen 6:6fe2b62f259d 152 while (!menu_.GetTouchedNumber(touchNum)) DoIfHandled();
MikamiUitOpen 6:6fe2b62f259d 153 return touchNum;
MikamiUitOpen 6:6fe2b62f259d 154 }
MikamiUitOpen 0:d310bb78455d 155 }