openMSX
CassettePlayer.cc
Go to the documentation of this file.
1// TODO:
2// - improve consistency when a reset occurs: tape is removed when you were
3// recording, but it is not removed when you were playing
4// - specify prefix for auto file name generation when recording (setting?)
5// - append to existing wav files when recording (record command), but this is
6// basically a special case (pointer at the end) of:
7// - (partly) overwrite an existing wav file from any given time index
8// - seek in cassette images for the next and previous file (using empty space?)
9// - (partly) overwrite existing wav files with new tape data (not very hi prio)
10// - handle read-only cassette images (e.g.: CAS images or WAV files with a RO
11// flag): refuse to go to record mode when those are selected
12// - smartly auto-set the position of tapes: if you insert an existing WAV
13// file, it will have the position at the start, assuming PLAY mode by
14// default. When specifying record mode at insert (somehow), it should be
15// at the back.
16// Alternatively, we could remember the index in tape images by storing the
17// index in some persistent data file with its SHA1 sum as it was as we last
18// saw it. When there are write actions to the tape, the hash has to be
19// recalculated and replaced in the data file. An optimization would be to
20// first simply check on the length of the file and fall back to SHA1 if that
21// results in multiple matches.
22
23#include "CassettePlayer.hh"
24#include "Connector.hh"
25#include "CassettePort.hh"
26#include "CommandController.hh"
27#include "DeviceConfig.hh"
28#include "HardwareConfig.hh"
29#include "XMLElement.hh"
30#include "FileContext.hh"
31#include "FilePool.hh"
32#include "File.hh"
33#include "ReverseManager.hh"
34#include "WavImage.hh"
35#include "CasImage.hh"
36#include "MSXCliComm.hh"
37#include "MSXMotherBoard.hh"
38#include "Reactor.hh"
39#include "GlobalSettings.hh"
40#include "CommandException.hh"
41#include "FileOperations.hh"
42#include "WavWriter.hh"
43#include "TclObject.hh"
44#include "DynamicClock.hh"
45#include "EmuDuration.hh"
46#include "checked_cast.hh"
47#include "narrow.hh"
48#include "serialize.hh"
49#include "unreachable.hh"
50#include "xrange.hh"
51#include <algorithm>
52#include <cassert>
53#include <memory>
54
55using std::string;
56
57namespace openmsx {
58
59// TODO: this description is not entirely accurate, but it is used
60// as an identifier for this audio device in e.g. Catapult. We should
61// use another way to identify audio devices A.S.A.P.!
62static constexpr static_string_view DESCRIPTION = "Cassetteplayer, use to read .cas or .wav files.";
63
64static constexpr unsigned DUMMY_INPUT_RATE = 44100; // actual rate depends on .cas/.wav file
65static constexpr unsigned RECORD_FREQ = 44100;
66static constexpr double RECIP_RECORD_FREQ = 1.0 / RECORD_FREQ;
67static constexpr double OUTPUT_AMP = 60.0;
68
69static std::string_view getCassettePlayerName()
70{
71 return "cassetteplayer";
72}
73
75 : ResampledSoundDevice(hwConf.getMotherBoard(), getCassettePlayerName(), DESCRIPTION, 1, DUMMY_INPUT_RATE, false)
76 , syncEndOfTape(hwConf.getMotherBoard().getScheduler())
77 , syncAudioEmu (hwConf.getMotherBoard().getScheduler())
78 , motherBoard(hwConf.getMotherBoard())
79 , cassettePlayerCommand(
80 this,
81 motherBoard.getCommandController(),
82 motherBoard.getStateChangeDistributor(),
83 motherBoard.getScheduler())
84 , loadingIndicator(
85 motherBoard.getReactor().getGlobalSettings().getThrottleManager())
86 , autoRunSetting(
87 motherBoard.getCommandController(),
88 "autoruncassettes", "automatically try to run cassettes", true)
89{
90 static const XMLElement* xml = [] {
92 XMLElement* result = doc.allocateElement("cassetteplayer");
93 result->setFirstChild(doc.allocateElement("sound"))
94 ->setFirstChild(doc.allocateElement("volume", "5000"));
95 return result;
96 }();
97 registerSound(DeviceConfig(hwConf, *xml));
98
99 motherBoard.registerMediaInfo(getCassettePlayerName(), *this);
100 motherBoard.getMSXCliComm().update(CliComm::UpdateType::HARDWARE, getCassettePlayerName(), "add");
101
102 removeTape(EmuTime::zero());
103}
104
106{
108 if (auto* c = getConnector()) {
109 c->unplug(getCurrentTime());
110 }
111 motherBoard.unregisterMediaInfo(*this);
112 motherBoard.getMSXCliComm().update(CliComm::UpdateType::HARDWARE, getCassettePlayerName(), "remove");
113}
114
116{
117 result.addDictKeyValues("target", getImageName().getResolved(),
118 "state", getStateString(),
119 "position", getTapePos(getCurrentTime()),
120 "length", getTapeLength(getCurrentTime()),
121 "motorcontrol", motorControl);
122}
123
124void CassettePlayer::autoRun()
125{
126 if (!playImage) return;
127 if (motherBoard.getReverseManager().isReplaying()) {
128 // Don't execute the loading commands (keyboard type commands)
129 // when we're replaying a recording. Because the recording
130 // already contains those commands.
131 return;
132 }
133
134 // try to automatically run the tape, if that's set
135 CassetteImage::FileType type = playImage->getFirstFileType();
136 if (!autoRunSetting.getBoolean() || type == CassetteImage::UNKNOWN) {
137 return;
138 }
139 bool is_SVI = motherBoard.getMachineType() == "SVI"; // assume all other are 'MSX*' (might not be correct for 'Coleco')
140 string H_READ = is_SVI ? "0xFE8E" : "0xFF07"; // Hook for Ready
141 string H_MAIN = is_SVI ? "0xFE94" : "0xFF0C"; // Hook for Main Loop
142 string instr1, instr2;
143 switch (type) {
145 instr1 = R"({RUN\"CAS:\"\r})";
146 break;
148 instr1 = R"({BLOAD\"CAS:\",R\r})";
149 break;
151 // Note that CLOAD:RUN won't work: BASIC ignores stuff
152 // after the CLOAD command. That's why it's split in two.
153 instr1 = "{CLOAD\\r}";
154 instr2 = "{RUN\\r}";
155 break;
156 default:
157 UNREACHABLE; // Shouldn't be possible
158 }
159 string command = strCat(
160 "namespace eval ::openmsx {\n"
161 " variable auto_run_bp\n"
162
163 " proc auto_run_cb {args} {\n"
164 " variable auto_run_bp\n"
165 " debug remove_bp $auto_run_bp\n"
166 " unset auto_run_bp\n"
167
168 // Without the 0.2s delay here, the type command gets messed up
169 // on MSX1 machines for some reason (starting to type too early?)
170 // When using 0.1s delay only, the typing works, but still some
171 // things go wrong on some machines with some games (see #1509
172 // for instance)
173 " after time 0.2 \"type [lindex $args 0]\"\n"
174
175 " set next [lrange $args 1 end]\n"
176 " if {[llength $next] == 0} return\n"
177
178 // H_READ is used by some firmwares; we need to hook the
179 // H_MAIN that happens immediately after H_READ.
180 " set cmd \"openmsx::auto_run_cb $next\"\n"
181 " set openmsx::auto_run_bp [debug set_bp ", H_MAIN, " 1 \"$cmd\"]\n"
182 " }\n"
183
184 " if {[info exists auto_run_bp]} {debug remove_bp $auto_run_bp\n}\n"
185 " set auto_run_bp [debug set_bp ", H_READ, " 1 {\n"
186 " openmsx::auto_run_cb {{}} ", instr1, ' ', instr2, "\n"
187 " }]\n"
188
189 // re-trigger hook(s), needed when already booted in BASIC
190 " type_via_keyboard \'\\r\n"
191 "}");
192 try {
193 motherBoard.getCommandController().executeCommand(command);
194 } catch (CommandException& e) {
195 motherBoard.getMSXCliComm().printWarning(
196 "Error executing loading instruction using command \"",
197 command, "\" for AutoRun: ",
198 e.getMessage(), "\n Please report a bug.");
199 }
200}
201
202string CassettePlayer::getStateString() const
203{
204 switch (getState()) {
205 using enum State;
206 case PLAY: return "play";
207 case RECORD: return "record";
208 case STOP: return "stop";
209 }
211}
212
213bool CassettePlayer::isRolling() const
214{
215 // Is the tape 'rolling'?
216 // is true when:
217 // not in stop mode (there is a tape inserted and not at end-of-tape)
218 // AND [ user forced playing (motorControl=off) OR motor enabled by
219 // software (motor=on) ]
220 return (getState() != State::STOP) && (motor || !motorControl);
221}
222
223double CassettePlayer::getTapePos(EmuTime::param time)
224{
225 sync(time);
226 if (getState() == State::RECORD) {
227 // we record 8-bit mono, so bytes == samples
228 return (double(recordImage->getBytes()) + partialInterval) * RECIP_RECORD_FREQ;
229 } else {
230 return (tapePos - EmuTime::zero()).toDouble();
231 }
232}
233
234void CassettePlayer::setTapePos(EmuTime::param time, double newPos)
235{
236 assert(getState() != State::RECORD);
237 sync(time);
238 auto pos = std::clamp(newPos, 0.0, getTapeLength(time));
239 tapePos = EmuTime::zero() + EmuDuration(pos);
240 wind(time);
241}
242
243double CassettePlayer::getTapeLength(EmuTime::param time)
244{
245 if (playImage) {
246 return (playImage->getEndTime() - EmuTime::zero()).toDouble();
247 } else if (getState() == State::RECORD) {
248 return getTapePos(time);
249 } else {
250 return 0.0;
251 }
252}
253
254void CassettePlayer::checkInvariants() const
255{
256 switch (getState()) {
257 case State::STOP:
258 assert(!recordImage);
259 if (playImage) {
260 // we're at end-of tape
261 assert(!getImageName().empty());
262 } else {
263 // no tape inserted, imageName may or may not be empty
264 }
265 break;
266 case State::PLAY:
267 assert(!getImageName().empty());
268 assert(!recordImage);
269 assert(playImage);
270 break;
271 case State::RECORD:
272 assert(!getImageName().empty());
273 assert(recordImage);
274 assert(!playImage);
275 break;
276 default:
278 }
279}
280
281void CassettePlayer::setState(State newState, const Filename& newImage,
282 EmuTime::param time)
283{
284 sync(time);
285
286 // set new state if different from old state
287 State oldState = getState();
288 if (oldState == newState) return;
289
290 // cannot directly switch from PLAY to RECORD or vice-versa,
291 // (should always go via STOP)
292 assert(!((oldState == State::PLAY) && (newState == State::RECORD)));
293 assert(!((oldState == State::RECORD) && (newState == State::PLAY)));
294
295 // stuff for leaving the old state
296 // 'recordImage==nullptr' can happen in case of loadstate.
297 if ((oldState == State::RECORD) && recordImage) {
298 flushOutput();
299 bool empty = recordImage->isEmpty();
300 recordImage.reset();
301 if (empty) {
302 // delete the created WAV file, as it is useless
303 FileOperations::unlink(getImageName().getResolved()); // ignore errors
304 setImageName(Filename());
305 }
306 }
307
308 // actually switch state
309 state = newState;
310 setImageName(newImage);
311
312 // stuff for entering the new state
313 if (newState == State::RECORD) {
314 partialOut = 0.0;
315 partialInterval = 0.0;
316 lastX = lastOutput ? OUTPUT_AMP : -OUTPUT_AMP;
317 lastY = 0.0;
318 }
319 motherBoard.getMSXCliComm().update(
320 CliComm::UpdateType::STATUS, "cassetteplayer", getStateString());
321
322 updateLoadingState(time); // sets SP for tape-end detection
323
324 checkInvariants();
325}
326
327void CassettePlayer::updateLoadingState(EmuTime::param time)
328{
329 assert(prevSyncTime == time); // sync() must be called
330 // TODO also set loadingIndicator for RECORD?
331 // note: we don't use isRolling()
332 loadingIndicator.update(motor && (getState() == State::PLAY));
333
334 syncEndOfTape.removeSyncPoint();
335 if (isRolling() && (getState() == State::PLAY)) {
336 syncEndOfTape.setSyncPoint(time + (playImage->getEndTime() - tapePos));
337 }
338}
339
340void CassettePlayer::setImageName(const Filename& newImage)
341{
342 casImage = newImage;
343 motherBoard.getMSXCliComm().update(
344 CliComm::UpdateType::MEDIA, "cassetteplayer", casImage.getResolved());
345}
346
347void CassettePlayer::insertTape(const Filename& filename, EmuTime::param time)
348{
349 if (!filename.empty()) {
350 FilePool& filePool = motherBoard.getReactor().getFilePool();
351 try {
352 // first try WAV
353 playImage = std::make_unique<WavImage>(filename, filePool);
354 } catch (MSXException& e) {
355 try {
356 // if that fails use CAS
357 playImage = std::make_unique<CasImage>(
358 filename, filePool,
359 motherBoard.getMSXCliComm());
360 } catch (MSXException& e2) {
361 throw MSXException(
362 "Failed to insert WAV image: \"",
363 e.getMessage(),
364 "\" and also failed to insert CAS image: \"",
365 e2.getMessage(), '\"');
366 }
367 }
368 } else {
369 // This is a bit tricky, consider this scenario: we switch from
370 // RECORD->PLAY, but we didn't actually record anything: The
371 // removeTape() call above (indirectly) deletes the empty
372 // recorded wav image and also clears imageName. Now because
373 // the 'filename' parameter is passed by reference, and because
374 // getImageName() returns a reference, this 'filename'
375 // parameter now also is an empty string.
376 }
377
378 // possibly recreate resampler
379 if (unsigned inputRate = playImage ? playImage->getFrequency() : 44100;
380 inputRate != getInputRate()) {
381 setInputRate(inputRate);
383 }
384
385 // trigger (re-)query of getAmplificationFactorImpl()
386 setSoftwareVolume(1.0f, time);
387
388 setImageName(filename);
389}
390
391void CassettePlayer::playTape(const Filename& filename, EmuTime::param time)
392{
393 // Temporally go to STOP state:
394 // RECORD: First close the recorded image. Otherwise it goes wrong
395 // if you switch from RECORD->PLAY on the same image.
396 // PLAY: Go to stop because we temporally violate some invariants
397 // (tapePos can be beyond end-of-tape).
398 setState(State::STOP, getImageName(), time); // keep current image
399 insertTape(filename, time);
400 rewind(time); // sets PLAY mode
401}
402
403void CassettePlayer::rewind(EmuTime::param time)
404{
405 sync(time); // before tapePos changes
406 assert(getState() != State::RECORD);
407 tapePos = EmuTime::zero();
408 audioPos = 0;
409 wind(time);
410 autoRun();
411}
412
413void CassettePlayer::wind(EmuTime::param time)
414{
415 if (getImageName().empty()) {
416 // no image inserted, do nothing
417 assert(getState() == State::STOP);
418 } else {
419 // keep current image
420 setState(State::PLAY, getImageName(), time);
421 }
422 updateLoadingState(time);
423}
424
425void CassettePlayer::recordTape(const Filename& filename, EmuTime::param time)
426{
427 removeTape(time); // flush (possible) previous recording
428 recordImage = std::make_unique<Wav8Writer>(filename, 1, RECORD_FREQ);
429 tapePos = EmuTime::zero();
430 setState(State::RECORD, filename, time);
431}
432
433void CassettePlayer::removeTape(EmuTime::param time)
434{
435 // first stop with tape still inserted
436 setState(State::STOP, getImageName(), time);
437 // then remove the tape
438 playImage.reset();
439 tapePos = EmuTime::zero();
440 setImageName({});
441}
442
443void CassettePlayer::setMotor(bool status, EmuTime::param time)
444{
445 if (status != motor) {
446 sync(time);
447 motor = status;
448 updateLoadingState(time);
449 }
450}
451
452void CassettePlayer::setMotorControl(bool status, EmuTime::param time)
453{
454 if (status != motorControl) {
455 sync(time);
456 motorControl = status;
457 updateLoadingState(time);
458 }
459}
460
461int16_t CassettePlayer::readSample(EmuTime::param time)
462{
463 if (getState() == State::PLAY) {
464 // playing
465 sync(time);
466 return isRolling() ? playImage->getSampleAt(tapePos) : int16_t(0);
467 } else {
468 // record or stop
469 return 0;
470 }
471}
472
473void CassettePlayer::setSignal(bool output, EmuTime::param time)
474{
475 sync(time);
476 lastOutput = output;
477}
478
479void CassettePlayer::sync(EmuTime::param time)
480{
481 EmuDuration duration = time - prevSyncTime;
482 prevSyncTime = time;
483
484 updateTapePosition(duration, time);
485 generateRecordOutput(duration);
486}
487
488void CassettePlayer::updateTapePosition(
489 EmuDuration::param duration, EmuTime::param time)
490{
491 if (!isRolling() || (getState() != State::PLAY)) return;
492
493 tapePos += duration;
494 assert(tapePos <= playImage->getEndTime());
495
496 // synchronize audio with actual tape position
497 if (!syncScheduled) {
498 // don't sync too often, this improves sound quality
499 syncScheduled = true;
500 syncAudioEmu.setSyncPoint(time + EmuDuration::sec(1));
501 }
502}
503
504void CassettePlayer::generateRecordOutput(EmuDuration::param duration)
505{
506 if (!recordImage || !isRolling()) return;
507
508 double out = lastOutput ? OUTPUT_AMP : -OUTPUT_AMP;
509 double samples = duration.toDouble() * RECORD_FREQ;
510 if (auto rest = 1.0 - partialInterval; rest <= samples) {
511 // enough to fill next interval
512 partialOut += out * rest;
513 fillBuf(1, partialOut);
514 samples -= rest;
515
516 // fill complete intervals
517 auto count = int(samples);
518 if (count > 0) {
519 fillBuf(count, out);
520 }
521 samples -= count;
522 assert(samples < 1.0);
523
524 // partial last interval
525 partialOut = samples * out;
526 partialInterval = samples;
527 } else {
528 assert(samples < 1.0);
529 partialOut += samples * out;
530 partialInterval += samples;
531 }
532 assert(partialInterval < 1.0);
533}
534
535void CassettePlayer::fillBuf(size_t length, double x)
536{
537 assert(recordImage);
538 static constexpr double A = 252.0 / 256.0;
539
540 double y = lastY + (x - lastX);
541
542 while (length) {
543 size_t len = std::min(length, buf.size() - sampCnt);
544 repeat(len, [&] {
545 buf[sampCnt++] = narrow<uint8_t>(int(y) + 128);
546 y *= A;
547 });
548 length -= len;
549 assert(sampCnt <= buf.size());
550 if (sampCnt == buf.size()) {
551 flushOutput();
552 }
553 }
554 lastY = y;
555 lastX = x;
556}
557
558void CassettePlayer::flushOutput()
559{
560 try {
561 recordImage->write(subspan(buf, 0, sampCnt));
562 sampCnt = 0;
563 recordImage->flush(); // update wav header
564 } catch (MSXException& e) {
565 motherBoard.getMSXCliComm().printWarning(
566 "Failed to write to tape: ", e.getMessage());
567 }
568}
569
570
571std::string_view CassettePlayer::getName() const
572{
573 return getCassettePlayerName();
574}
575
576std::string_view CassettePlayer::getDescription() const
577{
578 return DESCRIPTION;
579}
580
581void CassettePlayer::plugHelper(Connector& conn, EmuTime::param time)
582{
583 sync(time);
584 lastOutput = checked_cast<CassettePort&>(conn).lastOut();
585}
586
587void CassettePlayer::unplugHelper(EmuTime::param time)
588{
589 // note: may not throw exceptions
590 setState(State::STOP, getImageName(), time); // keep current image
591}
592
593
594void CassettePlayer::generateChannels(std::span<float*> buffers, unsigned num)
595{
596 // Single channel device: replace content of buffers[0] (not add to it).
597 assert(buffers.size() == 1);
598 if ((getState() != State::PLAY) || !isRolling()) {
599 buffers[0] = nullptr;
600 return;
601 }
602 assert(buffers.size() == 1);
603 playImage->fillBuffer(audioPos, buffers.first<1>(), num);
604 audioPos += num;
605}
606
608{
609 return playImage ? playImage->getAmplificationFactorImpl() : 1.0f;
610}
611
612void CassettePlayer::execEndOfTape(EmuTime::param time)
613{
614 // tape ended
615 sync(time);
616 assert(tapePos == playImage->getEndTime());
617 motherBoard.getMSXCliComm().printWarning(
618 "Tape end reached... stopping. "
619 "You may need to insert another tape image "
620 "that contains side B. (Or you used the wrong "
621 "loading command.)");
622 setState(State::STOP, getImageName(), time); // keep current image
623}
624
625void CassettePlayer::execSyncAudioEmu(EmuTime::param time)
626{
627 if (getState() == State::PLAY) {
628 updateStream(time);
629 sync(time);
630 DynamicClock clk(EmuTime::zero());
631 clk.setFreq(playImage->getFrequency());
632 audioPos = clk.getTicksTill(tapePos);
633 }
634 syncScheduled = false;
635}
636
637static constexpr std::initializer_list<enum_string<CassettePlayer::State>> stateInfo = {
638 { "PLAY", CassettePlayer::State::PLAY },
639 { "RECORD", CassettePlayer::State::RECORD },
641};
643
644// version 1: initial version
645// version 2: added checksum
646template<typename Archive>
647void CassettePlayer::serialize(Archive& ar, unsigned version)
648{
649 if (recordImage) {
650 // buf, sampCnt
651 flushOutput();
652 }
653
654 ar.serialize("casImage", casImage);
655
656 Sha1Sum oldChecksum;
657 if constexpr (!Archive::IS_LOADER) {
658 if (playImage) {
659 oldChecksum = playImage->getSha1Sum();
660 }
661 }
662 if (ar.versionAtLeast(version, 2)) {
663 string oldChecksumStr = oldChecksum.empty()
664 ? string{}
665 : oldChecksum.toString();
666 ar.serialize("checksum", oldChecksumStr);
667 oldChecksum = oldChecksumStr.empty()
668 ? Sha1Sum()
669 : Sha1Sum(oldChecksumStr);
670 }
671
672 if constexpr (Archive::IS_LOADER) {
673 FilePool& filePool = motherBoard.getReactor().getFilePool();
674 auto time = getCurrentTime();
675 casImage.updateAfterLoadState();
676 if (!oldChecksum.empty() &&
677 !FileOperations::exists(casImage.getResolved())) {
678 auto file = filePool.getFile(FileType::TAPE, oldChecksum);
679 if (file.is_open()) {
680 casImage.setResolved(file.getURL());
681 }
682 }
683 try {
684 insertTape(casImage, time);
685 } catch (MSXException&) {
686 if (oldChecksum.empty()) {
687 // It's OK if we cannot reinsert an empty
688 // image. One likely scenario for this case is
689 // the following:
690 // - cassetteplayer new myfile.wav
691 // - don't actually start saving to tape yet
692 // - create a savestate and load that state
693 // Because myfile.wav contains no data yet, it
694 // is deleted from the filesystem. So on a
695 // loadstate it won't be found.
696 } else {
697 throw;
698 }
699 }
700
701 if (playImage && !oldChecksum.empty()) {
702 Sha1Sum newChecksum = playImage->getSha1Sum();
703 if (oldChecksum != newChecksum) {
704 motherBoard.getMSXCliComm().printWarning(
705 "The content of the tape ",
706 casImage.getResolved(),
707 " has changed since the time this "
708 "savestate was created. This might "
709 "result in emulation problems.");
710 }
711 }
712 }
713
714 // only for RECORD
715 //double lastX;
716 //double lastY;
717 //double partialOut;
718 //double partialInterval;
719 //std::unique_ptr<WavWriter> recordImage;
720
721 ar.serialize("tapePos", tapePos,
722 "prevSyncTime", prevSyncTime,
723 "audioPos", audioPos,
724 "state", state,
725 "lastOutput", lastOutput,
726 "motor", motor,
727 "motorControl", motorControl);
728
729 if constexpr (Archive::IS_LOADER) {
730 auto time = getCurrentTime();
731 if (playImage && (tapePos > playImage->getEndTime())) {
732 tapePos = playImage->getEndTime();
733 motherBoard.getMSXCliComm().printWarning("Tape position "
734 "beyond tape end! Setting tape position to end. "
735 "This can happen if you load a replay from an "
736 "older openMSX version with a different CAS-to-WAV "
737 "baud rate or when the tape image has been changed "
738 "compared to when the replay was created.");
739 }
740 if (state == State::RECORD) {
741 // TODO we don't support savestates in RECORD mode yet
742 motherBoard.getMSXCliComm().printWarning(
743 "Restoring a state where the MSX was saving to "
744 "tape is not yet supported. Emulation will "
745 "continue without actually saving.");
746 setState(State::STOP, getImageName(), time);
747 }
748 if (!playImage && (state == State::PLAY)) {
749 // This should only happen for manually edited
750 // savestates, though we shouldn't crash on it.
751 setState(State::STOP, getImageName(), time);
752 }
753 sync(time);
754 updateLoadingState(time);
755 }
756}
759
760} // namespace openmsx
bool getBoolean() const noexcept
void plugHelper(Connector &connector, EmuTime::param time) override
const Filename & getImageName() const
float getAmplificationFactorImpl() const override
Get amplification/attenuation factor for this device.
std::string_view getName() const override
Name used to identify this pluggable.
std::string_view getDescription() const override
Description for this pluggable.
double getTapePos(EmuTime::param time)
Returns the position of the tape, in seconds from the beginning of the tape.
void setSignal(bool output, EmuTime::param time) override
Sets the cassette output signal false = low true = high.
void unplugHelper(EmuTime::param time) override
void generateChannels(std::span< float * > buffers, unsigned num) override
Abstract method to generate the actual sound data.
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
CassettePlayer(const HardwareConfig &hwConf)
void serialize(Archive &ar, unsigned version)
int16_t readSample(EmuTime::param time) override
Read wave data from cassette device.
double getTapeLength(EmuTime::param time)
Returns the length of the tape in seconds.
void getMediaInfo(TclObject &result) override
This method gets called when information is required on the media inserted in the media slot of the p...
void printWarning(std::string_view message)
Definition CliComm.cc:12
virtual TclObject executeCommand(zstring_view command, CliConnection *connection=nullptr)=0
Execute the given command.
Represents something you can plug devices into.
Definition Connector.hh:21
static constexpr EmuDuration sec(unsigned x)
const EmuDuration & param
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
Definition FilePool.cc:53
void setResolved(std::string resolved)
Change the resolved part of this filename E.g.
Definition Filename.hh:58
const std::string & getResolved() const &
Definition Filename.hh:38
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition Filename.cc:8
void update(bool newState)
Called by the device to indicate its loading state may have changed.
void update(UpdateType type, std::string_view name, std::string_view value) override
Definition MSXCliComm.cc:21
void registerMediaInfo(std::string_view name, MediaInfoProvider &provider)
Register and unregister providers of media info, for the media info topic.
CommandController & getCommandController()
void unregisterMediaInfo(MediaInfoProvider &provider)
ReverseManager & getReverseManager()
std::string_view getMachineType() const
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
Definition Pluggable.hh:43
FilePool & getFilePool()
Definition Reactor.hh:98
This class represents the result of a sha1 calculation (a 160-bit value).
Definition sha1.hh:24
bool empty() const
std::string toString() const
void updateStream(EmuTime::param time)
unsigned getInputRate() const
void setInputRate(unsigned sampleRate)
void setSoftwareVolume(float volume, EmuTime::param time)
Change the 'software volume' of this sound device.
void unregisterSound()
Unregisters this sound device with the Mixer.
void registerSound(const DeviceConfig &config)
Registers this sound device with the Mixer.
void addDictKeyValues(Args &&... args)
Definition TclObject.hh:150
static XMLDocument & getStaticDocument()
XMLElement * setFirstChild(XMLElement *child)
static_string_view
constexpr double e
Definition Math.hh:21
T length(const vecN< N, T > &x)
Definition gl_vec.hh:505
bool exists(zstring_view filename)
Does this file (directory) exists?
int unlink(zstring_view path)
Call unlink() in a platform-independent manner.
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::array< const EDStorage, 4 > A
auto count(InputRange &&range, const T &value)
Definition ranges.hh:349
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
Definition ranges.hh:481
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define SERIALIZE_ENUM(TYPE, INFO)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)
std::string strCat()
Definition strCat.hh:703
#define UNREACHABLE
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.
Definition xrange.hh:147