mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-16 14:42:41 +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();
|
std::shared_ptr<IOutput> currentPlugin = outputs::SelectedOutput();
|
||||||
currentName = currentPlugin ? currentPlugin->Name() : currentName;
|
currentName = currentPlugin ? currentPlugin->Name() : currentName;
|
||||||
|
|
||||||
PlaybackOverlays::ShowOutputOverlay([this, currentName] {
|
PlaybackOverlays::ShowOutputOverlay(
|
||||||
std::string newName;
|
this->transport.GetType(),
|
||||||
std::shared_ptr<IOutput> newPlugin = outputs::SelectedOutput();
|
[this, currentName] {
|
||||||
newName = newPlugin ? newPlugin->Name() : newName;
|
std::string newName;
|
||||||
|
std::shared_ptr<IOutput> newPlugin = outputs::SelectedOutput();
|
||||||
|
newName = newPlugin ? newPlugin->Name() : newName;
|
||||||
|
|
||||||
if (currentName != newName) {
|
if (currentName != newName) {
|
||||||
this->LoadPreferences();
|
this->LoadPreferences();
|
||||||
this->transport.ReloadOutput();
|
this->transport.ReloadOutput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsLayout::OnTransportDropdownActivate(cursespp::TextLabel* label) {
|
void SettingsLayout::OnTransportDropdownActivate(cursespp::TextLabel* label) {
|
||||||
const MasterTransport::Type current = this->transport.GetType();
|
const MasterTransport::Type current = this->transport.GetType();
|
||||||
|
|
||||||
PlaybackOverlays::ShowTransportOverlay([this, current](int selected) {
|
PlaybackOverlays::ShowTransportOverlay(
|
||||||
if (selected != current) {
|
this->transport.GetType(),
|
||||||
this->transport.SwitchTo((MasterTransport::Type) selected);
|
[this, current](int selected) {
|
||||||
this->LoadPreferences();
|
if (selected != current) {
|
||||||
}
|
this->transport.SwitchTo((MasterTransport::Type) selected);
|
||||||
});
|
this->LoadPreferences();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsLayout::OnLayout() {
|
void SettingsLayout::OnLayout() {
|
||||||
|
@ -43,8 +43,6 @@
|
|||||||
#include <cursespp/ListOverlay.h>
|
#include <cursespp/ListOverlay.h>
|
||||||
#include <cursespp/DialogOverlay.h>
|
#include <cursespp/DialogOverlay.h>
|
||||||
|
|
||||||
#include <app/audio/MasterTransport.h>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace musik::box;
|
using namespace musik::box;
|
||||||
@ -87,7 +85,10 @@ static void showOutputCannotCrossfadeMessage(const std::string& outputName) {
|
|||||||
PlaybackOverlays::PlaybackOverlays() {
|
PlaybackOverlays::PlaybackOverlays() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
void PlaybackOverlays::ShowOutputOverlay(
|
||||||
|
MasterTransport::Type transportType,
|
||||||
|
std::function<void()> callback)
|
||||||
|
{
|
||||||
plugins = outputs::GetAllOutputs();
|
plugins = outputs::GetAllOutputs();
|
||||||
|
|
||||||
if (!plugins.size()) {
|
if (!plugins.size()) {
|
||||||
@ -98,9 +99,17 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
|||||||
using Adapter = cursespp::SimpleScrollAdapter;
|
using Adapter = cursespp::SimpleScrollAdapter;
|
||||||
using ListOverlay = cursespp::ListOverlay;
|
using ListOverlay = cursespp::ListOverlay;
|
||||||
|
|
||||||
|
std::string currentOutput = outputs::SelectedOutput()->Name();
|
||||||
|
size_t selectedIndex = 0;
|
||||||
|
|
||||||
std::shared_ptr<Adapter> adapter(new Adapter());
|
std::shared_ptr<Adapter> adapter(new Adapter());
|
||||||
for (size_t i = 0; i < plugins.size(); i++) {
|
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);
|
adapter->SetSelectable(true);
|
||||||
@ -109,9 +118,20 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
|||||||
|
|
||||||
dialog->SetAdapter(adapter)
|
dialog->SetAdapter(adapter)
|
||||||
.SetTitle("output plugins")
|
.SetTitle("output plugins")
|
||||||
|
.SetSelectedIndex(selectedIndex)
|
||||||
.SetItemSelectedCallback(
|
.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]);
|
outputs::SelectOutput(plugins[index]);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@ -120,7 +140,10 @@ void PlaybackOverlays::ShowOutputOverlay(std::function<void()> callback) {
|
|||||||
cursespp::App::Overlays().Push(dialog);
|
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 Adapter = cursespp::SimpleScrollAdapter;
|
||||||
using ListOverlay = cursespp::ListOverlay;
|
using ListOverlay = cursespp::ListOverlay;
|
||||||
|
|
||||||
@ -129,10 +152,13 @@ void PlaybackOverlays::ShowTransportOverlay(std::function<void(int)> callback) {
|
|||||||
adapter->AddEntry("crossfade");
|
adapter->AddEntry("crossfade");
|
||||||
adapter->SetSelectable(true);
|
adapter->SetSelectable(true);
|
||||||
|
|
||||||
|
size_t selectedIndex = (transportType == MasterTransport::Gapless) ? 0 : 1;
|
||||||
|
|
||||||
std::shared_ptr<ListOverlay> dialog(new ListOverlay());
|
std::shared_ptr<ListOverlay> dialog(new ListOverlay());
|
||||||
|
|
||||||
dialog->SetAdapter(adapter)
|
dialog->SetAdapter(adapter)
|
||||||
.SetTitle("playback transport")
|
.SetTitle("playback transport")
|
||||||
|
.SetSelectedIndex(selectedIndex)
|
||||||
.SetItemSelectedCallback(
|
.SetItemSelectedCallback(
|
||||||
[callback](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
[callback](cursespp::IScrollAdapterPtr adapter, size_t index) {
|
||||||
int result = (index == 0)
|
int result = (index == 0)
|
||||||
|
@ -35,13 +35,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <app/audio/MasterTransport.h>
|
||||||
|
|
||||||
namespace musik {
|
namespace musik {
|
||||||
namespace box {
|
namespace box {
|
||||||
class PlaybackOverlays {
|
class PlaybackOverlays {
|
||||||
public:
|
public:
|
||||||
static void ShowOutputOverlay(std::function<void()> callback);
|
static void ShowOutputOverlay(
|
||||||
static void ShowTransportOverlay(std::function<void(int)> callback);
|
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:
|
private:
|
||||||
PlaybackOverlays();
|
PlaybackOverlays();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user