Merge pull request #43 from lioncash/array2

AudioGroupPool: Use std::array where applicable
This commit is contained in:
Phillip Stephens 2019-09-10 23:53:38 -07:00 committed by GitHub
commit 757defee7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 41 deletions

View File

@ -239,14 +239,15 @@ CommandWidget::CommandWidget(QWidget* parent, amuse::SoundMacro::ICmd* cmd, amus
break; break;
} }
case amuse::SoundMacro::CmdIntrospection::Field::Type::Choice: { case amuse::SoundMacro::CmdIntrospection::Field::Type::Choice: {
FieldComboBox* cb = new FieldComboBox(this); auto* const cb = new FieldComboBox(this);
cb->setFixedHeight(30); cb->setFixedHeight(30);
cb->setProperty("fieldIndex", f); cb->setProperty("fieldIndex", f);
cb->setProperty("fieldName", fieldName); cb->setProperty("fieldName", fieldName);
for (int j = 0; j < 4; ++j) { for (const auto choice : field.m_choices) {
if (field.m_choices[j].empty()) if (choice.empty()) {
break; break;
cb->addItem(tr(field.m_choices[j].data())); }
cb->addItem(tr(choice.data()));
} }
cb->setCurrentIndex(int(amuse::AccessField<int8_t>(m_cmd, field))); cb->setCurrentIndex(int(amuse::AccessField<int8_t>(m_cmd, field)));
connect(cb, qOverload<int>(&FieldComboBox::currentIndexChanged), this, &CommandWidget::numChanged); connect(cb, qOverload<int>(&FieldComboBox::currentIndexChanged), this, &CommandWidget::numChanged);

View File

@ -150,12 +150,12 @@ struct SoundMacro {
size_t m_offset; size_t m_offset;
std::string_view m_name; std::string_view m_name;
int64_t m_min, m_max, m_default; int64_t m_min, m_max, m_default;
std::string_view m_choices[4]; std::array<std::string_view, 4> m_choices;
}; };
CmdType m_tp; CmdType m_tp;
std::string_view m_name; std::string_view m_name;
std::string_view m_description; std::string_view m_description;
Field m_fields[7]; std::array<Field, 7> m_fields;
}; };
/** Base command interface. All versions of MusyX encode little-endian parameters */ /** Base command interface. All versions of MusyX encode little-endian parameters */

View File

@ -37,41 +37,42 @@ struct MakeDefaultCmdOp {
static std::unique_ptr<SoundMacro::ICmd> Do(R& r) { static std::unique_ptr<SoundMacro::ICmd> Do(R& r) {
std::unique_ptr<SoundMacro::ICmd> ret = std::make_unique<Tp>(); std::unique_ptr<SoundMacro::ICmd> ret = std::make_unique<Tp>();
if (const SoundMacro::CmdIntrospection* introspection = SoundMacro::GetCmdIntrospection(r)) { if (const SoundMacro::CmdIntrospection* introspection = SoundMacro::GetCmdIntrospection(r)) {
for (int f = 0; f < 7; ++f) { for (const auto& field : introspection->m_fields) {
const amuse::SoundMacro::CmdIntrospection::Field& field = introspection->m_fields[f]; if (field.m_name.empty()) {
if (!field.m_name.empty()) { continue;
switch (field.m_tp) { }
case amuse::SoundMacro::CmdIntrospection::Field::Type::Bool:
AccessField<bool>(ret.get(), field) = bool(field.m_default); switch (field.m_tp) {
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::Bool:
case amuse::SoundMacro::CmdIntrospection::Field::Type::Int8: AccessField<bool>(ret.get(), field) = bool(field.m_default);
case amuse::SoundMacro::CmdIntrospection::Field::Type::Choice: break;
AccessField<int8_t>(ret.get(), field) = int8_t(field.m_default); case amuse::SoundMacro::CmdIntrospection::Field::Type::Int8:
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::Choice:
case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt8: AccessField<int8_t>(ret.get(), field) = int8_t(field.m_default);
AccessField<uint8_t>(ret.get(), field) = uint8_t(field.m_default); break;
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt8:
case amuse::SoundMacro::CmdIntrospection::Field::Type::Int16: AccessField<uint8_t>(ret.get(), field) = uint8_t(field.m_default);
AccessField<int16_t>(ret.get(), field) = int16_t(field.m_default); break;
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::Int16:
case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt16: AccessField<int16_t>(ret.get(), field) = int16_t(field.m_default);
AccessField<uint16_t>(ret.get(), field) = uint16_t(field.m_default); break;
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt16:
case amuse::SoundMacro::CmdIntrospection::Field::Type::Int32: AccessField<uint16_t>(ret.get(), field) = uint16_t(field.m_default);
AccessField<int32_t>(ret.get(), field) = int32_t(field.m_default); break;
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::Int32:
case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt32: AccessField<int32_t>(ret.get(), field) = int32_t(field.m_default);
AccessField<uint32_t>(ret.get(), field) = uint32_t(field.m_default); break;
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::UInt32:
case amuse::SoundMacro::CmdIntrospection::Field::Type::SoundMacroId: AccessField<uint32_t>(ret.get(), field) = uint32_t(field.m_default);
case amuse::SoundMacro::CmdIntrospection::Field::Type::SoundMacroStep: break;
case amuse::SoundMacro::CmdIntrospection::Field::Type::TableId: case amuse::SoundMacro::CmdIntrospection::Field::Type::SoundMacroId:
case amuse::SoundMacro::CmdIntrospection::Field::Type::SampleId: case amuse::SoundMacro::CmdIntrospection::Field::Type::SoundMacroStep:
AccessField<SoundMacroIdDNA<athena::Endian::Little>>(ret.get(), field).id = uint16_t(field.m_default); case amuse::SoundMacro::CmdIntrospection::Field::Type::TableId:
break; case amuse::SoundMacro::CmdIntrospection::Field::Type::SampleId:
default: AccessField<SoundMacroIdDNA<athena::Endian::Little>>(ret.get(), field).id = uint16_t(field.m_default);
break; break;
} default:
break;
} }
} }
} }