mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-15 20:42:33 +00:00
Added more error handling to PlaybackOverlays -- also, ensure we set the
selected index on the transport and output device overlays.
This commit is contained in:
parent
76fbc5e6bd
commit
1be4e3fd70
@ -123,27 +123,31 @@ void SettingsLayout::OnOutputDropdownActivated(cursespp::TextLabel* label) {
|
||||
std::shared_ptr<IOutput> currentPlugin = outputs::SelectedOutput();
|
||||
currentName = currentPlugin ? currentPlugin->Name() : currentName;
|
||||
|
||||
PlaybackOverlays::ShowOutputOverlay([this, currentName] {
|
||||
std::string newName;
|
||||
std::shared_ptr<IOutput> newPlugin = outputs::SelectedOutput();
|
||||
newName = newPlugin ? newPlugin->Name() : newName;
|
||||
PlaybackOverlays::ShowOutputOverlay(
|
||||
this->transport.GetType(),
|
||||
[this, currentName] {
|
||||
std::string newName;
|
||||
std::shared_ptr<IOutput> newPlugin = outputs::SelectedOutput();
|
||||
newName = newPlugin ? newPlugin->Name() : newName;
|
||||
|
||||
if (currentName != newName) {
|
||||
this->LoadPreferences();
|
||||
this->transport.ReloadOutput();
|
||||
}
|
||||
});
|
||||
if (currentName != newName) {
|
||||
this->LoadPreferences();
|
||||
this->transport.ReloadOutput();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsLayout::OnTransportDropdownActivate(cursespp::TextLabel* label) {
|
||||
const MasterTransport::Type current = this->transport.GetType();
|
||||
|
||||
PlaybackOverlays::ShowTransportOverlay([this, current](int selected) {
|
||||
if (selected != current) {
|
||||
this->transport.SwitchTo((MasterTransport::Type) selected);
|
||||
this->LoadPreferences();
|
||||
}
|
||||
});
|
||||
PlaybackOverlays::ShowTransportOverlay(
|
||||
this->transport.GetType(),
|
||||
[this, current](int selected) {
|
||||
if (selected != current) {
|
||||
this->transport.SwitchTo((MasterTransport::Type) selected);
|
||||
this->LoadPreferences();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsLayout::OnLayout() {
|
||||
|
@ -43,8 +43,6 @@
|
||||
#include <cursespp/ListOverlay.h>
|
||||
#include <cursespp/DialogOverlay.h>
|
||||
|
||||
#include <app/audio/MasterTransport.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace musik::box;
|
||||
@ -87,7 +85,10 @@ static void showOutputCannotCrossfadeMessage(const std::string& outputName) {
|
||||
PlaybackOverlays::PlaybackOverlays() {
|
||||
}
|
||||
|
||||
void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
||||
void PlaybackOverlays::ShowOutputOverlay(
|
||||
MasterTransport::Type transportType,
|
||||
std::function<void()> callback)
|
||||
{
|
||||
plugins = outputs::GetAllOutputs();
|
||||
|
||||
if (!plugins.size()) {
|
||||
@ -98,9 +99,17 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
||||
using Adapter = cursespp::SimpleScrollAdapter;
|
||||
using ListOverlay = cursespp::ListOverlay;
|
||||
|
||||
std::string currentOutput = outputs::SelectedOutput()->Name();
|
||||
size_t selectedIndex = 0;
|
||||
|
||||
std::shared_ptr<Adapter> adapter(new Adapter());
|
||||
for (size_t i = 0; i < plugins.size(); i++) {
|
||||
adapter->AddEntry(plugins[i]->Name());
|
||||
const std::string name = plugins[i]->Name();
|
||||
adapter->AddEntry(name);
|
||||
|
||||
if (name == currentOutput) {
|
||||
selectedIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
adapter->SetSelectable(true);
|
||||
@ -109,9 +118,20 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
||||
|
||||
dialog->SetAdapter(adapter)
|
||||
.SetTitle("output plugins")
|
||||
.SetSelectedIndex(selectedIndex)
|
||||
.SetItemSelectedCallback(
|
||||
[callback](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||
[callback, transportType](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||
|
||||
if (transportType == MasterTransport::Crossfade) {
|
||||
std::string output = outputs::GetAllOutputs().at(index)->Name();
|
||||
if (invalidCrossfadeOutputs.find(output) != invalidCrossfadeOutputs.end()) {
|
||||
showOutputCannotCrossfadeMessage(output);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
outputs::SelectOutput(plugins[index]);
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
@ -120,7 +140,10 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
||||
cursespp::App::Overlays().Push(dialog);
|
||||
}
|
||||
|
||||
void PlaybackOverlays::ShowTransportOverlay(std::function<void(int)> callback) {
|
||||
void PlaybackOverlays::ShowTransportOverlay(
|
||||
MasterTransport::Type transportType,
|
||||
std::function<void(int)> callback)
|
||||
{
|
||||
using Adapter = cursespp::SimpleScrollAdapter;
|
||||
using ListOverlay = cursespp::ListOverlay;
|
||||
|
||||
@ -129,10 +152,13 @@ void PlaybackOverlays::ShowTransportOverlay(std::function<void(int)> callback) {
|
||||
adapter->AddEntry("crossfade");
|
||||
adapter->SetSelectable(true);
|
||||
|
||||
size_t selectedIndex = (transportType == MasterTransport::Gapless) ? 0 : 1;
|
||||
|
||||
std::shared_ptr<ListOverlay> dialog(new ListOverlay());
|
||||
|
||||
dialog->SetAdapter(adapter)
|
||||
.SetTitle("playback transport")
|
||||
.SetSelectedIndex(selectedIndex)
|
||||
.SetItemSelectedCallback(
|
||||
[callback](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||
int result = (index == 0)
|
||||
|
@ -35,13 +35,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <app/audio/MasterTransport.h>
|
||||
|
||||
namespace musik {
|
||||
namespace box {
|
||||
class PlaybackOverlays {
|
||||
public:
|
||||
static void ShowOutputOverlay(std::function<void()> callback);
|
||||
static void ShowTransportOverlay(std::function<void(int)> callback);
|
||||
static void ShowOutputOverlay(
|
||||
musik::box::audio::MasterTransport::Type transportType,
|
||||
std::function<void()> callback);
|
||||
|
||||
static void ShowTransportOverlay(
|
||||
musik::box::audio::MasterTransport::Type transportType,
|
||||
std::function<void(int)> callback);
|
||||
|
||||
private:
|
||||
PlaybackOverlays();
|
||||
|
Loading…
x
Reference in New Issue
Block a user