mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-27 22:30:49 +00:00
Simplifies indentation, correcting flow while there.
This commit is contained in:
parent
3c896050fb
commit
74d1ca4fa8
@ -250,101 +250,104 @@ void MainWindow::launchMachine() {
|
|||||||
Machine::Error error;
|
Machine::Error error;
|
||||||
machine.reset(Machine::MachineForTargets(targets, rom_fetcher, error));
|
machine.reset(Machine::MachineForTargets(targets, rom_fetcher, error));
|
||||||
|
|
||||||
switch(error) {
|
if(error != Machine::Error::None) {
|
||||||
default: {
|
switch(error) {
|
||||||
// TODO: correct assumptions herein that this is the first machine to be
|
default: break;
|
||||||
// assigned to this window.
|
case Machine::Error::MissingROM: {
|
||||||
setVisibleWidgetSet(WidgetSet::RunningMachine);
|
setVisibleWidgetSet(WidgetSet::ROMRequester);
|
||||||
uiPhase = UIPhase::RunningMachine;
|
uiPhase = UIPhase::RequestingROMs;
|
||||||
|
|
||||||
// Supply the scan target.
|
// Populate request text.
|
||||||
// TODO: in the future, hypothetically, deal with non-scan producers.
|
QString requestText = romRequestBaseText;
|
||||||
const auto scan_producer = machine->scan_producer();
|
size_t index = 0;
|
||||||
if(scan_producer) {
|
for(const auto rom: missingRoms) {
|
||||||
ui->openGLWidget->setScanProducer(scan_producer);
|
requestText += "• ";
|
||||||
}
|
requestText += rom.descriptive_name.c_str();
|
||||||
|
|
||||||
// Install audio output if required.
|
++index;
|
||||||
const auto audio_producer = machine->audio_producer();
|
if(index == missingRoms.size()) {
|
||||||
if(audio_producer) {
|
requestText += ".\n";
|
||||||
static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically.
|
continue;
|
||||||
const auto speaker = audio_producer->get_speaker();
|
}
|
||||||
if(speaker) {
|
if(index == missingRoms.size() - 1) {
|
||||||
const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
|
requestText += "; and\n";
|
||||||
QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat();
|
continue;
|
||||||
|
}
|
||||||
// Use the ideal format's sample rate, provide stereo as long as at least two channels
|
requestText += ";\n";
|
||||||
// are available, and — at least for now — assume a good buffer size.
|
|
||||||
audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo();
|
|
||||||
audioIs8bit = idealFormat.sampleSize() < 16;
|
|
||||||
idealFormat.setChannelCount(1 + int(audioIsStereo));
|
|
||||||
idealFormat.setSampleSize(audioIs8bit ? 8 : 16);
|
|
||||||
|
|
||||||
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
|
|
||||||
speaker->set_delegate(this);
|
|
||||||
|
|
||||||
audioThread.performAsync([this, idealFormat] {
|
|
||||||
// Create an audio output.
|
|
||||||
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
|
|
||||||
|
|
||||||
// Start the output. The additional `audioBuffer` is meant to minimise latency,
|
|
||||||
// believe it or not, given Qt's semantics.
|
|
||||||
audioOutput->setBufferSize(samplesPerBuffer * sizeof(int16_t));
|
|
||||||
audioOutput->start(&audioBuffer);
|
|
||||||
audioBuffer.setDepth(audioOutput->bufferSize());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
ui->missingROMsBox->setPlainText(requestText);
|
||||||
// Set user-friendly default options.
|
} break;
|
||||||
const std::string longMachineName = Machine::LongNameForTargetMachine(targets[0]->machine);
|
}
|
||||||
const auto configurable = machine->configurable_device();
|
return;
|
||||||
if(configurable) {
|
|
||||||
configurable->set_options(Machine::AllOptionsByMachineName()[longMachineName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the window title. TODO: clearly I need a proper functional solution for this.
|
|
||||||
setWindowTitle(QString::fromStdString(longMachineName));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this is a timed machine, start up the timer.
|
|
||||||
const auto timedMachine = machine->timed_machine();
|
|
||||||
if(timedMachine) {
|
|
||||||
timer = std::make_unique<Timer>(this);
|
|
||||||
timer->startWithMachine(timedMachine, &machineMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the machine can accept new media while running, enable
|
|
||||||
// the inert action.
|
|
||||||
if(machine->media_target()) {
|
|
||||||
insertAction->setEnabled(true);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case Machine::Error::MissingROM: {
|
|
||||||
setVisibleWidgetSet(WidgetSet::ROMRequester);
|
|
||||||
uiPhase = UIPhase::RequestingROMs;
|
|
||||||
|
|
||||||
// Populate request text.
|
|
||||||
QString requestText = romRequestBaseText;
|
|
||||||
size_t index = 0;
|
|
||||||
for(const auto rom: missingRoms) {
|
|
||||||
requestText += "• ";
|
|
||||||
requestText += rom.descriptive_name.c_str();
|
|
||||||
|
|
||||||
++index;
|
|
||||||
if(index == missingRoms.size()) {
|
|
||||||
requestText += ".\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(index == missingRoms.size() - 1) {
|
|
||||||
requestText += "; and\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
requestText += ";\n";
|
|
||||||
}
|
|
||||||
ui->missingROMsBox->setPlainText(requestText);
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setVisibleWidgetSet(WidgetSet::RunningMachine);
|
||||||
|
uiPhase = UIPhase::RunningMachine;
|
||||||
|
|
||||||
|
// Supply the scan target.
|
||||||
|
// TODO: in the future, hypothetically, deal with non-scan producers.
|
||||||
|
const auto scan_producer = machine->scan_producer();
|
||||||
|
if(scan_producer) {
|
||||||
|
ui->openGLWidget->setScanProducer(scan_producer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install audio output if required.
|
||||||
|
const auto audio_producer = machine->audio_producer();
|
||||||
|
if(audio_producer) {
|
||||||
|
static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically.
|
||||||
|
const auto speaker = audio_producer->get_speaker();
|
||||||
|
if(speaker) {
|
||||||
|
const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||||
|
QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat();
|
||||||
|
|
||||||
|
// Use the ideal format's sample rate, provide stereo as long as at least two channels
|
||||||
|
// are available, and — at least for now — assume a good buffer size.
|
||||||
|
audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo();
|
||||||
|
audioIs8bit = idealFormat.sampleSize() < 16;
|
||||||
|
idealFormat.setChannelCount(1 + int(audioIsStereo));
|
||||||
|
idealFormat.setSampleSize(audioIs8bit ? 8 : 16);
|
||||||
|
|
||||||
|
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
|
||||||
|
speaker->set_delegate(this);
|
||||||
|
|
||||||
|
audioThread.performAsync([this, idealFormat] {
|
||||||
|
// Create an audio output.
|
||||||
|
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
|
||||||
|
|
||||||
|
// Start the output. The additional `audioBuffer` is meant to minimise latency,
|
||||||
|
// believe it or not, given Qt's semantics.
|
||||||
|
audioOutput->setBufferSize(samplesPerBuffer * sizeof(int16_t));
|
||||||
|
audioOutput->start(&audioBuffer);
|
||||||
|
audioBuffer.setDepth(audioOutput->bufferSize());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set user-friendly default options.
|
||||||
|
const std::string longMachineName = Machine::LongNameForTargetMachine(targets[0]->machine);
|
||||||
|
const auto configurable = machine->configurable_device();
|
||||||
|
if(configurable) {
|
||||||
|
configurable->set_options(Machine::AllOptionsByMachineName()[longMachineName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If this is a timed machine, start up the timer.
|
||||||
|
const auto timedMachine = machine->timed_machine();
|
||||||
|
if(timedMachine) {
|
||||||
|
timer = std::make_unique<Timer>(this);
|
||||||
|
timer->startWithMachine(timedMachine, &machineMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the machine can accept new media while running, enable
|
||||||
|
// the inert action.
|
||||||
|
if(machine->media_target()) {
|
||||||
|
insertAction->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the window title. TODO: clearly I need a proper functional solution for the window title.
|
||||||
|
setWindowTitle(QString::fromStdString(longMachineName));
|
||||||
|
|
||||||
|
// TODO: add machine-specific UI.
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::speaker_did_complete_samples(Outputs::Speaker::Speaker *, const std::vector<int16_t> &buffer) {
|
void MainWindow::speaker_did_complete_samples(Outputs::Speaker::Speaker *, const std::vector<int16_t> &buffer) {
|
||||||
@ -742,7 +745,7 @@ void MainWindow::launchTarget(std::unique_ptr<Analyser::Static::Target> &&target
|
|||||||
launchMachine();
|
launchMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK - UI state
|
// MARK: - UI state
|
||||||
|
|
||||||
// An assumption made widely below is that it's more likely I'll preserve combo box text
|
// An assumption made widely below is that it's more likely I'll preserve combo box text
|
||||||
// than indices. This has historically been true on the Mac, as I tend to add additional
|
// than indices. This has historically been true on the Mac, as I tend to add additional
|
||||||
|
Loading…
x
Reference in New Issue
Block a user