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:
Wed Nov 09 13:19:52 2016 +0000
Revision:
6:6fe2b62f259d
Parent:
5:7c8f0fc9dfb6
Child:
7:930d50953ec2
7

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