openMSX
CassettePlayer.hh
Go to the documentation of this file.
1 #ifndef CASSETTEPLAYER_HH
2 #define CASSETTEPLAYER_HH
3 
4 #include "EventListener.hh"
5 #include "CassetteDevice.hh"
7 #include "Schedulable.hh"
8 #include "Filename.hh"
9 #include "EmuTime.hh"
10 #include "serialize_meta.hh"
11 #include <string>
12 #include <memory>
13 
14 namespace openmsx {
15 
16 class CassetteImage;
17 class HardwareConfig;
18 class MSXMotherBoard;
19 class Wav8Writer;
20 class LoadingIndicator;
21 class BooleanSetting;
22 class TapeCommand;
23 
25  , private EventListener, private Schedulable
26 {
27 public:
28  explicit CassettePlayer(const HardwareConfig& hwConf);
30 
31  // CassetteDevice
32  void setMotor(bool status, EmuTime::param time) override;
33  short readSample(EmuTime::param time) override;
34  void setSignal(bool output, EmuTime::param time) override;
35 
36  // Pluggable
37  const std::string& getName() const override;
38  string_ref getDescription() const override;
39  void plugHelper(Connector& connector, EmuTime::param time) override;
40  void unplugHelper(EmuTime::param time) override;
41 
42  // SoundDevice
43  void generateChannels(int** bufs, unsigned num) override;
44 
45  template<typename Archive>
46  void serialize(Archive& ar, unsigned version);
47 
48  enum State { PLAY, RECORD, STOP }; // public for serialization
49 
50 private:
51  State getState() const { return state; }
52  std::string getStateString() const;
53  void setState(State newState, const Filename& newImage,
54  EmuTime::param time);
55  void setImageName(const Filename& newImage);
56  const Filename& getImageName() const { return casImage; }
57  void checkInvariants() const;
58 
61  void playTape(const Filename& filename, EmuTime::param time);
62  void insertTape(const Filename& filename);
63 
66  void removeTape(EmuTime::param time);
67 
71  void recordTape(const Filename& filename, EmuTime::param time);
72 
77  void rewind(EmuTime::param time);
78 
81  void setMotorControl(bool status, EmuTime::param time);
82 
86  bool isRolling() const;
87 
92  void updateLoadingState(EmuTime::param time);
93 
96  double getTapePos(EmuTime::param time);
97 
102  double getTapeLength(EmuTime::param time);
103 
104  void sync(EmuTime::param time);
105  void updateTapePosition(EmuDuration::param duration, EmuTime::param time);
106  void generateRecordOutput(EmuDuration::param duration);
107 
108  void fillBuf(size_t length, double x);
109  void flushOutput();
110  void autoRun();
111 
112  // EventListener
113  int signalEvent(const std::shared_ptr<const Event>& event) override;
114 
115  // Schedulable
116  void executeUntil(EmuTime::param time, int userData) override;
117 
118  static const size_t BUF_SIZE = 1024;
119  unsigned char buf[BUF_SIZE];
120 
121  double lastX; // last unfiltered output
122  double lastY; // last filtered output
123  double partialOut;
124  double partialInterval;
125 
127  EmuTime tapePos;
128 
131  EmuTime prevSyncTime;
132 
133  // SoundDevice
134  unsigned audioPos;
135  Filename casImage;
136 
137  MSXMotherBoard& motherBoard;
138  const std::unique_ptr<TapeCommand> tapeCommand;
139  const std::unique_ptr<LoadingIndicator> loadingIndicator;
140  const std::unique_ptr<BooleanSetting> autoRunSetting;
141  std::unique_ptr<Wav8Writer> recordImage;
142  std::unique_ptr<CassetteImage> playImage;
143 
144  size_t sampcnt;
145  State state;
146  bool lastOutput;
147  bool motor, motorControl;
148  bool syncScheduled;
149 
150  friend class TapeCommand;
151 };
153 
154 } // namespace openmsx
155 
156 #endif
void plugHelper(Connector &connector, EmuTime::param time) override
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:281
Represents something you can plug devices into.
Definition: Connector.hh:21
const EmuDuration & param
Definition: EmuDuration.hh:24
void generateChannels(int **bufs, unsigned num) override
Abstract method to generate the actual sound data.
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void serialize(Archive &ar, unsigned version)
CassettePlayer(const HardwareConfig &hwConf)
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:16
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
const EmuTime & param
Definition: EmuTime.hh:20
void unplugHelper(EmuTime::param time) override
string_ref getDescription() const override
Description for this pluggable.
void setSignal(bool output, EmuTime::param time) override
Sets the cassette output signal false = low true = high.
short readSample(EmuTime::param time) override
Read wave data from cassette device.
const std::string & getName() const override
Name used to identify this pluggable.