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
SD_PlayerSkeleton.cpp@4:d730d024ac32, 2016-11-07 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Nov 07 00:54:55 2016 +0000
- Revision:
- 4:d730d024ac32
- Parent:
- 2:511479736d6e
- Child:
- 5:7c8f0fc9dfb6
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:d310bb78455d | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:d310bb78455d | 2 | // SD プレーヤー用抽象基底クラス |
MikamiUitOpen | 0:d310bb78455d | 3 | // |
MikamiUitOpen | 4:d730d024ac32 | 4 | // 2016/11/07, 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 | 1:c7968701f7b3 | 11 | SD_PlayerSkeleton::SD_PlayerSkeleton(string str, int fs, bool reset) |
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 | 1:c7968701f7b3 | 19 | 0, 2, 1), |
MikamiUitOpen | 1:c7968701f7b3 | 20 | resetActive_(reset) |
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 | 1:c7968701f7b3 | 27 | if (resetActive_) reset_ = new ResetButton(); |
MikamiUitOpen | 0:d310bb78455d | 28 | } |
MikamiUitOpen | 0:d310bb78455d | 29 | |
MikamiUitOpen | 0:d310bb78455d | 30 | void SD_PlayerSkeleton::Execute() |
MikamiUitOpen | 0:d310bb78455d | 31 | { |
MikamiUitOpen | 0:d310bb78455d | 32 | bool playOk = false; |
MikamiUitOpen | 0:d310bb78455d | 33 | bool whileFirst = true; |
MikamiUitOpen | 0:d310bb78455d | 34 | int32_t loopCount; |
MikamiUitOpen | 0:d310bb78455d | 35 | |
MikamiUitOpen | 0:d310bb78455d | 36 | while (true) |
MikamiUitOpen | 0:d310bb78455d | 37 | { |
MikamiUitOpen | 0:d310bb78455d | 38 | if (!playOk) |
MikamiUitOpen | 0:d310bb78455d | 39 | { |
MikamiUitOpen | 0:d310bb78455d | 40 | if (whileFirst) |
MikamiUitOpen | 0:d310bb78455d | 41 | { |
MikamiUitOpen | 0:d310bb78455d | 42 | whileFirst = false; |
MikamiUitOpen | 0:d310bb78455d | 43 | while (!menu_.Touched(0)) // OPEN がタッチされるまで待つ |
MikamiUitOpen | 1:c7968701f7b3 | 44 | CheckCtrl(); |
MikamiUitOpen | 0:d310bb78455d | 45 | SelectFile(); |
MikamiUitOpen | 0:d310bb78455d | 46 | } |
MikamiUitOpen | 0:d310bb78455d | 47 | else |
MikamiUitOpen | 0:d310bb78455d | 48 | { |
MikamiUitOpen | 0:d310bb78455d | 49 | menu_.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:d310bb78455d | 50 | int touch10; |
MikamiUitOpen | 0:d310bb78455d | 51 | while (!menu_.GetTouchedNumber(touch10)) |
MikamiUitOpen | 1:c7968701f7b3 | 52 | CheckCtrl(); |
MikamiUitOpen | 0:d310bb78455d | 53 | if (touch10 == 0) SelectFile(); |
MikamiUitOpen | 0:d310bb78455d | 54 | } |
MikamiUitOpen | 0:d310bb78455d | 55 | |
MikamiUitOpen | 0:d310bb78455d | 56 | loopCount = SD_Open(); |
MikamiUitOpen | 0:d310bb78455d | 57 | while (!menu_.Touched(1)) // PLAY がタッチされるまで待つ |
MikamiUitOpen | 1:c7968701f7b3 | 58 | CheckCtrl(); |
MikamiUitOpen | 0:d310bb78455d | 59 | } |
MikamiUitOpen | 0:d310bb78455d | 60 | else |
MikamiUitOpen | 0:d310bb78455d | 61 | loopCount = SD_Open(); |
MikamiUitOpen | 0:d310bb78455d | 62 | |
MikamiUitOpen | 0:d310bb78455d | 63 | selector_.Erase(0, 0, BG_LEFT_-4, 272); |
MikamiUitOpen | 0:d310bb78455d | 64 | title_.Draw(); |
MikamiUitOpen | 0:d310bb78455d | 65 | |
MikamiUitOpen | 0:d310bb78455d | 66 | Display(); // アプリ固有の表示処理 |
MikamiUitOpen | 1:c7968701f7b3 | 67 | if (resetActive_) reset_->Draw(); |
MikamiUitOpen | 0:d310bb78455d | 68 | |
MikamiUitOpen | 0:d310bb78455d | 69 | menu_.Inactivate(0); // OPEN 無効 |
MikamiUitOpen | 0:d310bb78455d | 70 | menu_.Activate(2); // PAUSE 有効 |
MikamiUitOpen | 0:d310bb78455d | 71 | menu_.Activate(4); // STOP 有効 |
MikamiUitOpen | 0:d310bb78455d | 72 | |
MikamiUitOpen | 0:d310bb78455d | 73 | playOk = false; |
MikamiUitOpen | 0:d310bb78455d | 74 | bool stopOk = false; |
MikamiUitOpen | 0:d310bb78455d | 75 | |
MikamiUitOpen | 0:d310bb78455d | 76 | Clear(); // アプリ固有のクリア処理 |
MikamiUitOpen | 0:d310bb78455d | 77 | |
MikamiUitOpen | 0:d310bb78455d | 78 | mySai_.PlayOut(); // Play 開始 |
MikamiUitOpen | 0:d310bb78455d | 79 | |
MikamiUitOpen | 0:d310bb78455d | 80 | for (int k=0; k<loopCount; k++) |
MikamiUitOpen | 0:d310bb78455d | 81 | { |
MikamiUitOpen | 0:d310bb78455d | 82 | int touch42 = -1; |
MikamiUitOpen | 0:d310bb78455d | 83 | menu_.GetTouchedNumber(touch42); |
MikamiUitOpen | 0:d310bb78455d | 84 | if (touch42 == 4) break; // STOP |
MikamiUitOpen | 0:d310bb78455d | 85 | if (touch42 == 2) // PAUSE |
MikamiUitOpen | 0:d310bb78455d | 86 | { |
MikamiUitOpen | 0:d310bb78455d | 87 | menu_.Inactivate(2); // PAUSE 無効 |
MikamiUitOpen | 0:d310bb78455d | 88 | menu_.Activate(3); // RESUME 有効 |
MikamiUitOpen | 0:d310bb78455d | 89 | mySai_.PauseOut(); |
MikamiUitOpen | 0:d310bb78455d | 90 | |
MikamiUitOpen | 0:d310bb78455d | 91 | // PLAY か RESUME か STOP がタッチされるまで待つ |
MikamiUitOpen | 0:d310bb78455d | 92 | int touch134 = -1; |
MikamiUitOpen | 0:d310bb78455d | 93 | while (!menu_.GetTouchedNumber(touch134)) |
MikamiUitOpen | 1:c7968701f7b3 | 94 | CheckCtrl(); |
MikamiUitOpen | 0:d310bb78455d | 95 | switch (touch134) |
MikamiUitOpen | 0:d310bb78455d | 96 | { |
MikamiUitOpen | 0:d310bb78455d | 97 | case 1: playOk = true; // 最初から PLAY |
MikamiUitOpen | 0:d310bb78455d | 98 | break; |
MikamiUitOpen | 0:d310bb78455d | 99 | case 3: mySai_.ResumeOut(); // PAUSE したところから PLAY 再開 |
MikamiUitOpen | 0:d310bb78455d | 100 | menu_.Activate(2); |
MikamiUitOpen | 0:d310bb78455d | 101 | menu_.Inactivate(3); |
MikamiUitOpen | 0:d310bb78455d | 102 | menu_.TouchedColor(1); |
MikamiUitOpen | 0:d310bb78455d | 103 | break; |
MikamiUitOpen | 0:d310bb78455d | 104 | case 4: stopOk = true; // STOP |
MikamiUitOpen | 0:d310bb78455d | 105 | break; |
MikamiUitOpen | 0:d310bb78455d | 106 | } |
MikamiUitOpen | 0:d310bb78455d | 107 | } |
MikamiUitOpen | 0:d310bb78455d | 108 | if (playOk || stopOk) break; |
MikamiUitOpen | 0:d310bb78455d | 109 | |
MikamiUitOpen | 1:c7968701f7b3 | 110 | CheckCtrl(); |
MikamiUitOpen | 0:d310bb78455d | 111 | // 1フレーム分の信号処理の実行 |
MikamiUitOpen | 0:d310bb78455d | 112 | SignalProcessing(); |
MikamiUitOpen | 0:d310bb78455d | 113 | } |
MikamiUitOpen | 0:d310bb78455d | 114 | mySai_.StopOut(); |
MikamiUitOpen | 0:d310bb78455d | 115 | menu_.Activate(0); // OPEN 有効 |
MikamiUitOpen | 0:d310bb78455d | 116 | if (!playOk) menu_.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:d310bb78455d | 117 | for (int n=2; n<5; n++) // その他は無効 |
MikamiUitOpen | 0:d310bb78455d | 118 | menu_.Inactivate(n); |
MikamiUitOpen | 0:d310bb78455d | 119 | sdReader_.Close(); // SD のファイルのクローズ |
MikamiUitOpen | 0:d310bb78455d | 120 | } |
MikamiUitOpen | 0:d310bb78455d | 121 | } |
MikamiUitOpen | 0:d310bb78455d | 122 | |
MikamiUitOpen | 4:d730d024ac32 | 123 | // 拡張子を除いたファイル名を取得 |
MikamiUitOpen | 4:d730d024ac32 | 124 | string SD_PlayerSkeleton::GetFileNameNoExt() |
MikamiUitOpen | 4:d730d024ac32 | 125 | { |
MikamiUitOpen | 4:d730d024ac32 | 126 | string fName = fileName_; |
MikamiUitOpen | 4:d730d024ac32 | 127 | int k = fName.rfind("."); |
MikamiUitOpen | 4:d730d024ac32 | 128 | if (k != string::npos) |
MikamiUitOpen | 4:d730d024ac32 | 129 | return fName.erase(k); |
MikamiUitOpen | 4:d730d024ac32 | 130 | else |
MikamiUitOpen | 4:d730d024ac32 | 131 | return fName; |
MikamiUitOpen | 4:d730d024ac32 | 132 | } |
MikamiUitOpen | 4:d730d024ac32 | 133 | |
MikamiUitOpen | 0:d310bb78455d | 134 | // SD カードのファイルのオープン |
MikamiUitOpen | 0:d310bb78455d | 135 | int32_t SD_PlayerSkeleton::SD_Open() |
MikamiUitOpen | 0:d310bb78455d | 136 | { |
MikamiUitOpen | 0:d310bb78455d | 137 | sdReader_.Open(fileName_); |
MikamiUitOpen | 0:d310bb78455d | 138 | sdReader_.IsWavFile(); |
MikamiUitOpen | 0:d310bb78455d | 139 | return sdReader_.GetSize()/FRAME_SIZE_; |
MikamiUitOpen | 0:d310bb78455d | 140 | } |
MikamiUitOpen | 0:d310bb78455d | 141 | |
MikamiUitOpen | 0:d310bb78455d | 142 | // ファイルの選択 |
MikamiUitOpen | 0:d310bb78455d | 143 | // selectedName: 選択されたファイル名 |
MikamiUitOpen | 0:d310bb78455d | 144 | void SD_PlayerSkeleton::SelectFile() |
MikamiUitOpen | 0:d310bb78455d | 145 | { |
MikamiUitOpen | 0:d310bb78455d | 146 | selector_.DisplayFileList(); |
MikamiUitOpen | 0:d310bb78455d | 147 | title_.Draw("Select file"); |
MikamiUitOpen | 0:d310bb78455d | 148 | do |
MikamiUitOpen | 0:d310bb78455d | 149 | { |
MikamiUitOpen | 0:d310bb78455d | 150 | if (selector_.Select(fileName_)) |
MikamiUitOpen | 0:d310bb78455d | 151 | menu_.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:d310bb78455d | 152 | wait_ms(200); |
MikamiUitOpen | 0:d310bb78455d | 153 | } while (!menu_.Touched(1)); // PLAY がタッチされるまで繰り返す |
MikamiUitOpen | 0:d310bb78455d | 154 | } |
MikamiUitOpen | 1:c7968701f7b3 | 155 | |
MikamiUitOpen | 1:c7968701f7b3 | 156 | // パネル操作のチェック |
MikamiUitOpen | 1:c7968701f7b3 | 157 | void SD_PlayerSkeleton::CheckCtrl() |
MikamiUitOpen | 1:c7968701f7b3 | 158 | { |
MikamiUitOpen | 1:c7968701f7b3 | 159 | if (resetActive_) reset_->Do(); |
MikamiUitOpen | 1:c7968701f7b3 | 160 | Modefy(); |
MikamiUitOpen | 1:c7968701f7b3 | 161 | } |
MikamiUitOpen | 0:d310bb78455d | 162 | } |
MikamiUitOpen | 4:d730d024ac32 | 163 |