From 5d4abb5fb1e2675ced080da714e444b183b7c103 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 30 Sep 2019 21:34:12 -1000 Subject: [PATCH] Code style improvements --- Editor/ProjectModel.cpp | 12 +- Editor/SoundMacroEditor.cpp | 2 +- Editor/resources/lang_de.ts | 252 ++++++++++++++++++------------------ VST/VSTBackend.cpp | 2 +- include/amuse/Common.hpp | 2 +- lib/AudioGroupPool.cpp | 24 ++-- lib/AudioGroupProject.cpp | 18 +-- lib/Common.cpp | 38 +++--- 8 files changed, 175 insertions(+), 175 deletions(-) diff --git a/Editor/ProjectModel.cpp b/Editor/ProjectModel.cpp index 8d0a733..832d9a7 100644 --- a/Editor/ProjectModel.cpp +++ b/Editor/ProjectModel.cpp @@ -651,7 +651,7 @@ void ProjectModel::saveSongsIndex() { QFileInfo songsFile(m_dir, QStringLiteral("!songs.yaml")); athena::io::YAMLDocWriter dw("amuse::Songs"); for (auto& p : amuse::SortUnorderedMap(m_midiFiles)) - dw.writeString(fmt::format(fmt("{}"), p.first).c_str(), p.second.get().m_path.toUtf8().data()); + dw.writeString(fmt::format(fmt("{}"), p.first), p.second.get().m_path.toUtf8().data()); athena::io::FileWriter w(QStringToSysString(songsFile.filePath())); if (!w.hasError()) dw.finish(&w); @@ -1592,7 +1592,7 @@ static void WriteMimeYAML(athena::io::YAMLDocWriter& w, ProjectModel::CurveNode* static void WriteMimeYAML(athena::io::YAMLDocWriter& w, ProjectModel::KeymapNode* n) { if (auto __v = w.enterSubVector("entries")) { for (const auto& km : *n->m_obj) { - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); km.write(w); } @@ -1602,7 +1602,7 @@ static void WriteMimeYAML(athena::io::YAMLDocWriter& w, ProjectModel::KeymapNode static void WriteMimeYAML(athena::io::YAMLDocWriter& w, ProjectModel::LayersNode* n) { if (auto __v = w.enterSubVector("entries")) { for (const auto& lm : *n->m_obj) { - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); lm.write(w); } @@ -1670,7 +1670,7 @@ EditorUndoCommand* ProjectModel::readMimeYAML(athena:: size_t entryCount; if (auto __v = r.enterSubVector("entries", entryCount)) { for (size_t i = 0; i < entryCount; ++i) { - if (auto __r2 = r.enterSubRecord(nullptr)) { + if (auto __r2 = r.enterSubRecord()) { (*dataNode)[i].read(r); } } @@ -1686,7 +1686,7 @@ EditorUndoCommand* ProjectModel::readMimeYAML(athena:: if (auto __v = r.enterSubVector("entries", entryCount)) { dataNode->resize(entryCount); for (size_t i = 0; i < entryCount; ++i) { - if (auto __r2 = r.enterSubRecord(nullptr)) { + if (auto __r2 = r.enterSubRecord()) { (*dataNode)[i].read(r); } } @@ -1710,7 +1710,7 @@ template QMimeData* MakeMimeData(NT* n, const QString& mimeType) { QMimeData* data = new QMimeData; athena::io::VectorWriter vw; - athena::io::YAMLDocWriter w(nullptr); + athena::io::YAMLDocWriter w; w.writeString("name", n->name().toStdString()); WriteMimeYAML(w, n); w.finish(&vw); diff --git a/Editor/SoundMacroEditor.cpp b/Editor/SoundMacroEditor.cpp index d99f4fa..e5a49a4 100644 --- a/Editor/SoundMacroEditor.cpp +++ b/Editor/SoundMacroEditor.cpp @@ -207,7 +207,7 @@ CommandWidget::CommandWidget(QWidget* parent, amuse::SoundMacro::ICmd* cmd, amus if (field.m_tp == amuse::SoundMacro::CmdIntrospection::Field::Type::SoundMacroId) { collectionType = ProjectModel::INode::Type::SoundMacro; } else if (field.m_tp == amuse::SoundMacro::CmdIntrospection::Field::Type::TableId) { - if (!field.m_name.compare("ADSR")) + if (field.m_name == "ADSR") collectionType = ProjectModel::INode::Type::ADSR; else collectionType = ProjectModel::INode::Type::Curve; diff --git a/Editor/resources/lang_de.ts b/Editor/resources/lang_de.ts index b5c4af1..9380d99 100644 --- a/Editor/resources/lang_de.ts +++ b/Editor/resources/lang_de.ts @@ -162,26 +162,26 @@ EffectCatalogue - - + + Reverb Standard - - + + Reverb High - - + + Delay - - + + Chorus @@ -197,47 +197,47 @@ KeymapControls - + SoundMacro - + Transpose - + Offset resulting MIDI note - + Pan - + Set initial pan - + Surround - + Initially play through surround channels - + Prio Offset - + Offset resulting priority @@ -1021,7 +1021,7 @@ ModulationSlider - + Modulation: %1 @@ -1184,17 +1184,17 @@ PageObjectProxyModel - + SoundMacros: - + Keymaps: - + Layers: @@ -1215,7 +1215,7 @@ PaintButton - + Activate brush to apply values to keys @@ -1223,7 +1223,7 @@ PitchSlider - + Pitch: %1 @@ -1231,341 +1231,341 @@ ProjectModel - - - - - - + + + + + + Export Error - - - + + + Unable to find group %1 - + Unable to export %1.proj - + Unable to export %1.pool - + Unable to export %1.sdir - + Unable to export %1.samp - + Import Error - + Export Header Error - + Unable to open %1 for reading - + File Exists - + %1 already exists. Overwrite? - + Sound Macros - + ADSRs - + Curves - + Keymaps - + Layers - + Samples - + Naming Conflict - + %1 already exists in this context - + Rename %1 - + Subproject Conflict - + The subproject %1 is already defined - - - + + + Add Subproject %1 - + Sound Group Conflict - - + + The group %1 is already defined - - - + + + Add Sound Group %1 - + Song Group Conflict - - - + + + Add Song Group %1 - + Sound Macro Conflict - + The macro %1 is already defined - - + + Add Sound Macro %1 - + ADSR Conflict - + The ADSR %1 is already defined - - - + + + Add ADSR %1 - + Curve Conflict - + The Curve %1 is already defined - - - + + + Add Curve %1 - + Keymap Conflict - + The Keymap %1 is already defined - - - + + + Add Keymap %1 - + Layers Conflict - + Layers %1 is already defined - - - + + + Add Layers %1 - - + + -copy - + Add SoundMacro %1 - + Cut SongGroup %1 - + Cut SFXGroup %1 - + Cut SoundMacro %1 - + Cut ADSR %1 - + Cut Curve %1 - + Cut Keymap %1 - + Cut Layers %1 - + Delete Subproject - + <p>The subproject %1 will be permanently deleted from the project. Sample files will be permanently removed from the file system.</p><p><strong>This action cannot be undone!</strong></p><p>Continue?</p> - + Delete SongGroup %1 - + Delete SFXGroup %1 - + Delete SoundMacro %1 - + Delete ADSR %1 - + Delete Curve %1 - + Delete Keymap %1 - + Delete Layers %1 - + Delete Sample - + <p>The sample %1 will be permanently deleted from the file system. <p><strong>This action cannot be undone!</strong></p><p>Continue?</p> @@ -1997,17 +1997,17 @@ - + Aux A send level for all voices - + Aux B send level for all voices - + Master volume level @@ -2015,17 +2015,17 @@ StudioSetupWidget - + Studio Setup - + Aux A - + Aux B @@ -2094,7 +2094,7 @@ Uint32X8Button - + Channels @@ -2102,42 +2102,42 @@ Uint32X8Popup - + Front Left - + Front Right - + Rear Left - + Rear Right - + Front Center - + LFE - + Side Left - + Side Right @@ -2145,7 +2145,7 @@ VelocitySlider - + Velocity: %1 diff --git a/VST/VSTBackend.cpp b/VST/VSTBackend.cpp index 70372a3..d3ead5b 100644 --- a/VST/VSTBackend.cpp +++ b/VST/VSTBackend.cpp @@ -330,7 +330,7 @@ VstInt32 VSTBackend::setChunk(void* data, VstInt32 byteSize, bool) { for (auto& collection : m_filePresenter.m_audioGroupCollections) { size_t fileIdx = 0; for (auto& file : collection.second->m_groups) { - if (!file.second->m_path.compare(targetPath)) { + if (file.second->m_path == targetPath) { m_editor.selectCollection(LPARAM(0x80000000 | (colIdx << 16) | fileIdx)); m_editor.selectGroup(groupIdx); m_editor.selectPage(pageIdx); diff --git a/include/amuse/Common.hpp b/include/amuse/Common.hpp index 185a3b2..053d94f 100644 --- a/include/amuse/Common.hpp +++ b/include/amuse/Common.hpp @@ -149,7 +149,7 @@ protected: virtual ~IObj() = default; public: - void increment() noexcept { m_refCount.fetch_add(std::memory_order_relaxed); } + void increment() noexcept { m_refCount.fetch_add(1, std::memory_order_relaxed); } void decrement() noexcept { if (m_refCount.fetch_sub(1, std::memory_order_release) == 1) { std::atomic_thread_fence(std::memory_order_acquire); diff --git a/lib/AudioGroupPool.cpp b/lib/AudioGroupPool.cpp index 7e5f4dc..c63f044 100644 --- a/lib/AudioGroupPool.cpp +++ b/lib/AudioGroupPool.cpp @@ -211,7 +211,7 @@ AudioGroupPool AudioGroupPool::CreateAudioGroupPool(SystemStringView groupPath) if (!fi.hasError()) { athena::io::YAMLDocReader r; - if (r.parse(&fi) && !r.readString("DNAType").compare("amuse::Pool")) { + if (r.parse(&fi) && r.readString("DNAType") == "amuse::Pool") { if (auto __r = r.enterSubRecord("soundMacros")) { for (const auto& sm : r.getCurNode()->m_mapChildren) { ObjectId macroId = SoundMacroId::CurNameDB->generateId(NameDB::Type::SoundMacro); @@ -289,7 +289,7 @@ AudioGroupPool AudioGroupPool::CreateAudioGroupPool(SystemStringView groupPath) auto& kmOut = ret.m_keymaps[KeymapId::CurNameDB->resolveIdFromName(k.first)]; kmOut = MakeObj>(); for (size_t i = 0; i < mappingCount && i < 128; ++i) - if (auto __r2 = r.enterSubRecord(nullptr)) + if (auto __r2 = r.enterSubRecord()) (*kmOut)[i].read(r); } } @@ -304,7 +304,7 @@ AudioGroupPool AudioGroupPool::CreateAudioGroupPool(SystemStringView groupPath) layOut = MakeObj>(); layOut->reserve(mappingCount); for (size_t lm = 0; lm < mappingCount; ++lm) { - if (auto __r2 = r.enterSubRecord(nullptr)) { + if (auto __r2 = r.enterSubRecord()) { layOut->emplace_back(); layOut->back().read(r); } @@ -363,7 +363,7 @@ void SoundMacro::buildFromPrototype(const SoundMacro& other) { void SoundMacro::toYAML(athena::io::YAMLDocWriter& w) const { for (const auto& c : m_cmds) { - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); w.writeString("cmdOp", SoundMacro::CmdOpToStr(c->Isa())); c->write(w); @@ -374,7 +374,7 @@ void SoundMacro::toYAML(athena::io::YAMLDocWriter& w) const { void SoundMacro::fromYAML(athena::io::YAMLDocReader& r, size_t cmdCount) { m_cmds.reserve(cmdCount); for (size_t c = 0; c < cmdCount; ++c) - if (auto __r2 = r.enterSubRecord(nullptr)) + if (auto __r2 = r.enterSubRecord()) m_cmds.push_back(SoundMacro::CmdDo>(r)); } @@ -948,7 +948,7 @@ std::vector AudioGroupPool::toYAML() const { if (!m_soundMacros.empty()) { if (auto __r = w.enterSubRecord("soundMacros")) { for (const auto& p : SortUnorderedMap(m_soundMacros)) { - if (auto __v = w.enterSubVector(SoundMacroId::CurNameDB->resolveNameFromId(p.first).data())) { + if (auto __v = w.enterSubVector(SoundMacroId::CurNameDB->resolveNameFromId(p.first))) { p.second.get()->toYAML(w); } } @@ -958,7 +958,7 @@ std::vector AudioGroupPool::toYAML() const { if (!m_tables.empty()) { if (auto __r = w.enterSubRecord("tables")) { for (const auto& p : SortUnorderedMap(m_tables)) { - if (auto __v = w.enterSubRecord(TableId::CurNameDB->resolveNameFromId(p.first).data())) { + if (auto __v = w.enterSubRecord(TableId::CurNameDB->resolveNameFromId(p.first))) { w.setStyle(athena::io::YAMLNodeStyle::Flow); (*p.second.get())->write(w); } @@ -969,9 +969,9 @@ std::vector AudioGroupPool::toYAML() const { if (!m_keymaps.empty()) { if (auto __r = w.enterSubRecord("keymaps")) { for (const auto& p : SortUnorderedMap(m_keymaps)) { - if (auto __v = w.enterSubVector(KeymapId::CurNameDB->resolveNameFromId(p.first).data())) { + if (auto __v = w.enterSubVector(KeymapId::CurNameDB->resolveNameFromId(p.first))) { for (const auto& km : *p.second.get()) { - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); km.write(w); } @@ -984,9 +984,9 @@ std::vector AudioGroupPool::toYAML() const { if (!m_layers.empty()) { if (auto __r = w.enterSubRecord("layers")) { for (const auto& p : SortUnorderedMap(m_layers)) { - if (auto __v = w.enterSubVector(LayersId::CurNameDB->resolveNameFromId(p.first).data())) { + if (auto __v = w.enterSubVector(LayersId::CurNameDB->resolveNameFromId(p.first))) { for (const auto& lm : *p.second.get()) { - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); lm.write(w); } @@ -1129,6 +1129,6 @@ void amuse::Curve::Enumerate(athena::io::YAMLDocWriter& w) w.enumerate("data", data); } -const char* amuse::Curve::DNAType() { return "amuse::Curve"; } +std::string_view amuse::Curve::DNAType() { return "amuse::Curve"sv; } } // namespace amuse diff --git a/lib/AudioGroupProject.cpp b/lib/AudioGroupProject.cpp index e7a28a2..30d0993 100644 --- a/lib/AudioGroupProject.cpp +++ b/lib/AudioGroupProject.cpp @@ -348,7 +348,7 @@ void SongGroupIndex::fromYAML(athena::io::YAMLDocReader& r) { std::array& setup = m_midiSetups[songId]; for (size_t i = 0; i < 16 && i < chanCount; ++i) - if (auto __r2 = r.enterSubRecord(nullptr)) + if (auto __r2 = r.enterSubRecord()) setup[i].read(r); } } @@ -375,7 +375,7 @@ AudioGroupProject AudioGroupProject::CreateAudioGroupProject(SystemStringView gr if (!fi.hasError()) { athena::io::YAMLDocReader r; - if (r.parse(&fi) && !r.readString("DNAType").compare("amuse::Project")) { + if (r.parse(&fi) && r.readString("DNAType") == "amuse::Project") { if (auto __v = r.enterSubRecord("songGroups")) { ret.m_songGroups.reserve(r.getCurNode()->m_mapChildren.size()); for (const auto& grp : r.getCurNode()->m_mapChildren) { @@ -609,7 +609,7 @@ void SongGroupIndex::toYAML(athena::io::YAMLDocWriter& w) const { if (!m_normPages.empty()) { if (auto __v2 = w.enterSubRecord("normPages")) { for (const auto& pg : SortUnorderedMap(m_normPages)) { - if (auto __r2 = w.enterSubRecord(fmt::format(fmt("{}"), pg.first).c_str())) { + if (auto __r2 = w.enterSubRecord(fmt::format(fmt("{}"), pg.first))) { w.setStyle(athena::io::YAMLNodeStyle::Flow); pg.second.get().write(w); } @@ -619,7 +619,7 @@ void SongGroupIndex::toYAML(athena::io::YAMLDocWriter& w) const { if (!m_drumPages.empty()) { if (auto __v2 = w.enterSubRecord("drumPages")) { for (const auto& pg : SortUnorderedMap(m_drumPages)) { - if (auto __r2 = w.enterSubRecord(fmt::format(fmt("{}"), pg.first).c_str())) { + if (auto __r2 = w.enterSubRecord(fmt::format(fmt("{}"), pg.first))) { w.setStyle(athena::io::YAMLNodeStyle::Flow); pg.second.get().write(w); } @@ -631,9 +631,9 @@ void SongGroupIndex::toYAML(athena::io::YAMLDocWriter& w) const { for (const auto& song : SortUnorderedMap(m_midiSetups)) { std::string songString = fmt::format(fmt("{}/0x{}"), SongId::CurNameDB->resolveNameFromId(song.first), song.first); - if (auto __v3 = w.enterSubVector(songString.c_str())) + if (auto __v3 = w.enterSubVector(songString)) for (int i = 0; i < 16; ++i) - if (auto __r2 = w.enterSubRecord(nullptr)) { + if (auto __r2 = w.enterSubRecord()) { w.setStyle(athena::io::YAMLNodeStyle::Flow); song.second.get()[i].write(w); } @@ -646,7 +646,7 @@ void SFXGroupIndex::toYAML(athena::io::YAMLDocWriter& w) const { for (const auto& sfx : SortUnorderedMap(m_sfxEntries)) { std::string sfxString = fmt::format(fmt("{}/0x{}"), SFXId::CurNameDB->resolveNameFromId(sfx.first), sfx.first); - if (auto __r2 = w.enterSubRecord(sfxString.c_str())) { + if (auto __r2 = w.enterSubRecord(sfxString)) { w.setStyle(athena::io::YAMLNodeStyle::Flow); sfx.second.get().write(w); } @@ -661,7 +661,7 @@ std::vector AudioGroupProject::toYAML() const { for (const auto& p : SortUnorderedMap(m_songGroups)) { std::string groupString = fmt::format(fmt("{}/0x{}"), GroupId::CurNameDB->resolveNameFromId(p.first), p.first); - if (auto __r = w.enterSubRecord(groupString.c_str())) { + if (auto __r = w.enterSubRecord(groupString)) { p.second.get()->toYAML(w); } } @@ -673,7 +673,7 @@ std::vector AudioGroupProject::toYAML() const { for (const auto& p : SortUnorderedMap(m_sfxGroups)) { std::string groupString = fmt::format(fmt("{}/0x{}"), GroupId::CurNameDB->resolveNameFromId(p.first), p.first); - if (auto __r = w.enterSubRecord(groupString.c_str())) { + if (auto __r = w.enterSubRecord(groupString)) { p.second.get()->toYAML(w); } } diff --git a/lib/Common.cpp b/lib/Common.cpp index 2822589..50cb4bd 100644 --- a/lib/Common.cpp +++ b/lib/Common.cpp @@ -99,7 +99,7 @@ bool Copy(const SystemChar* from, const SystemChar* to) { } \ template \ void type##DNA::_read(athena::io::YAMLDocReader& r) { \ - std::string name = r.readString(nullptr); \ + std::string name = r.readString(); \ if (!type::CurNameDB) \ Log.report(logvisor::Fatal, fmt("Unable to resolve " typeName " name {}, no database present"), name); \ if (name.empty()) { \ @@ -116,11 +116,11 @@ bool Copy(const SystemChar* from, const SystemChar* to) { return; \ std::string_view name = type::CurNameDB->resolveNameFromId(id); \ if (!name.empty()) \ - w.writeString(nullptr, name); \ + w.writeString(name); \ } \ template \ - const char* type##DNA::DNAType() { \ - return "amuse::" #type "DNA"; \ + std::string_view type##DNA::DNAType() { \ + return "amuse::" #type "DNA"sv; \ } \ template struct type##DNA; \ template struct type##DNA; @@ -187,7 +187,7 @@ void PageObjectIdDNA::Enumerate(athena::io::YAML } template void PageObjectIdDNA::_read(athena::io::YAMLDocReader& r) { - std::string name = r.readString(nullptr); + std::string name = r.readString(); if (!KeymapId::CurNameDB || !LayersId::CurNameDB) Log.report(logvisor::Fatal, fmt("Unable to resolve keymap or layers name {}, no database present"), name); if (name.empty()) { @@ -217,20 +217,20 @@ void PageObjectIdDNA::_write(athena::io::YAMLDocWriter& w) { if (id.id & 0x8000) { std::string_view name = LayersId::CurNameDB->resolveNameFromId(id); if (!name.empty()) - w.writeString(nullptr, name); + w.writeString(name); } else if (id.id & 0x4000) { std::string_view name = KeymapId::CurNameDB->resolveNameFromId(id); if (!name.empty()) - w.writeString(nullptr, name); + w.writeString(name); } else { std::string_view name = SoundMacroId::CurNameDB->resolveNameFromId(id); if (!name.empty()) - w.writeString(nullptr, name); + w.writeString(name); } } template -const char* PageObjectIdDNA::DNAType() { - return "amuse::PageObjectIdDNA"; +std::string_view PageObjectIdDNA::DNAType() { + return "amuse::PageObjectIdDNA"sv; } template struct PageObjectIdDNA; template struct PageObjectIdDNA; @@ -253,12 +253,12 @@ void SoundMacroStepDNA::Enumerate(size_t& sz template <> template <> void SoundMacroStepDNA::Enumerate(athena::io::YAMLDocReader& reader) { - step = reader.readUint16(nullptr); + step = reader.readUint16(); } template <> template <> void SoundMacroStepDNA::Enumerate(athena::io::YAMLDocWriter& writer) { - writer.writeUint16(nullptr, step); + writer.writeUint16(step); } template <> template <> @@ -278,16 +278,16 @@ void SoundMacroStepDNA::Enumerate(size_t& sz) { template <> template <> void SoundMacroStepDNA::Enumerate(athena::io::YAMLDocReader& reader) { - step = reader.readUint16(nullptr); + step = reader.readUint16(); } template <> template <> void SoundMacroStepDNA::Enumerate(athena::io::YAMLDocWriter& writer) { - writer.writeUint16(nullptr, step); + writer.writeUint16(step); } template -const char* SoundMacroStepDNA::DNAType() { - return "amuse::SoundMacroStepDNA"; +std::string_view SoundMacroStepDNA::DNAType() { + return "amuse::SoundMacroStepDNA"sv; } template struct SoundMacroStepDNA; template struct SoundMacroStepDNA; @@ -411,14 +411,14 @@ void LittleUInt24::Enumerate(size_t& sz) { template <> void LittleUInt24::Enumerate(athena::io::YAMLDocReader& reader) { - val = reader.readUint32(nullptr); + val = reader.readUint32(); } template <> void LittleUInt24::Enumerate(athena::io::YAMLDocWriter& writer) { - writer.writeUint32(nullptr, val); + writer.writeUint32(val); } -const char* LittleUInt24::DNAType() { return "amuse::LittleUInt24"; } +std::string_view LittleUInt24::DNAType() { return "amuse::LittleUInt24"sv; } } // namespace amuse