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);
29  virtual ~CassettePlayer();
30 
31  // CassetteDevice
32  virtual void setMotor(bool status, EmuTime::param time);
33  virtual short readSample(EmuTime::param time);
34  virtual void setSignal(bool output, EmuTime::param time);
35 
36  // Pluggable
37  virtual const std::string& getName() const;
38  virtual string_ref getDescription() const;
39  virtual void plugHelper(Connector& connector, EmuTime::param time);
40  virtual void unplugHelper(EmuTime::param time);
41 
42  // SoundDevice
43  virtual void generateChannels(int** bufs, unsigned num);
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  virtual int signalEvent(const std::shared_ptr<const Event>& event);
114 
115  // Schedulable
116  virtual void executeUntil(EmuTime::param time, int userData);
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
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:281
virtual void plugHelper(Connector &connector, EmuTime::param time)
Represents something you can plug devices into.
Definition: Connector.hh:21
virtual void setMotor(bool status, EmuTime::param time)
Sets the cassette motor relay false = off true = on.
virtual void setSignal(bool output, EmuTime::param time)
Sets the cassette output signal false = low true = high.
const EmuDuration & param
Definition: EmuDuration.hh:24
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
virtual const std::string & getName() const
Name used to identify this pluggable.
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
const EmuTime & param
Definition: EmuTime.hh:20
virtual void unplugHelper(EmuTime::param time)
virtual short readSample(EmuTime::param time)
Read wave data from cassette device.
virtual string_ref getDescription() const
Description for this pluggable.
virtual void generateChannels(int **bufs, unsigned num)
Abstract method to generate the actual sound data.