diff --git a/CMakeLists.txt b/CMakeLists.txt index 969f715..00352f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,47 @@ endif() message(STATUS "Minixer: 使用 JUCE 目录: ${JUCE_DIR}") add_subdirectory("${JUCE_DIR}" JUCE) +# ============================================================================== +# 1.5 ASIO 支持 +# ============================================================================== +# 本项目使用 Steinberg ASIO SDK 提供 ASIO 音频设备支持。 +# 使用 ASIO SDK 即表示你同意 Steinberg 的许可协议: +# https://www.steinberg.net/en/company/developers.html +# ASIO 是 Steinberg Media Technologies GmbH 的注册商标。 +if(NOT DEFINED ASIO_DIR) + if(DEFINED ENV{ASIO_DIR}) + file(TO_CMAKE_PATH "$ENV{ASIO_DIR}" ASIO_DIR) + endif() +endif() + +if(NOT ASIO_DIR) + set(_asio_candidates + "${CMAKE_CURRENT_SOURCE_DIR}/../SDK/asiosdk_2.3.3_2019-06-14" + "${CMAKE_CURRENT_SOURCE_DIR}/../../SDK/asiosdk_2.3.3_2019-06-14" + "${CMAKE_CURRENT_SOURCE_DIR}/../../../SDK/asiosdk_2.3.3_2019-06-14" + "$ENV{USERPROFILE}/SDK/asiosdk_2.3.3_2019-06-14" + "C:/SDK/asiosdk_2.3.3_2019-06-14" + "D:/CodePacks/Store/SDK/asiosdk_2.3.3_2019-06-14") + + foreach(_candidate IN LISTS _asio_candidates) + if(EXISTS "${_candidate}/common/iasiodrv.h") + set(ASIO_DIR "${_candidate}") + break() + endif() + endforeach() +endif() + +if(NOT ASIO_DIR OR NOT EXISTS "${ASIO_DIR}/common/iasiodrv.h") + message(FATAL_ERROR + "找不到 Steinberg ASIO SDK。请通过以下任一方式指定:\n" + " 1. 设置环境变量 ASIO_DIR=\n" + " 2. 配置时传入 -D ASIO_DIR=\n" + " 3. 将 ASIO SDK 放在常见位置(如 ../SDK/asiosdk_2.3.3_2019-06-14)。") +endif() + +message(STATUS "Minixer: 使用 ASIO SDK 目录: ${ASIO_DIR}") +set(_asio_include_dir "${ASIO_DIR}/common") + # ============================================================================== # 2. 源文件 # ============================================================================== @@ -118,7 +159,9 @@ set(_minixer_sources Source/Components/KeyCaptureButton.cpp Source/Components/KeyCaptureButton.h Source/Components/ShortcutsSettingsComponent.cpp - Source/Components/ShortcutsSettingsComponent.h) + Source/Components/ShortcutsSettingsComponent.h + Source/Components/AboutComponent.cpp + Source/Components/AboutComponent.h) set(_pluginhost_sources Source/PluginHost/Main.cpp @@ -137,60 +180,65 @@ set(_pluginhost_sources # ============================================================================== # 3. 主程序 Minixer (GUI app) # ============================================================================== -juce_add_gui_app(Minixer - VERSION 1.0.0 - COMPANY_NAME "" - PRODUCT_NAME "Minixer" - IS_SYNTHESIZER FALSE - NEEDS_MIDI_INPUT FALSE - NEEDS_MIDI_OUTPUT FALSE - IS_MIDI_EFFECT FALSE - EDITOR_WANTS_KEYBOARD_FOCUS FALSE) +# Minixer 主程序固定为 64 位。32 位构建仅用于生成 PluginHost32.exe。 +if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + juce_add_gui_app(Minixer + VERSION 1.0.0 + COMPANY_NAME "" + PRODUCT_NAME "Minixer" + IS_SYNTHESIZER FALSE + NEEDS_MIDI_INPUT FALSE + NEEDS_MIDI_OUTPUT FALSE + IS_MIDI_EFFECT FALSE + EDITOR_WANTS_KEYBOARD_FOCUS FALSE) -# 应用图标(Windows .ico)。JUCE 的 ICON_BIG 在 Windows 上会调用 juceaide 转换图片格式, -# 因此这里直接生成 resources.rc 并链接,避免对输入格式的额外要求。 -if(WIN32 AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/minixer_06_warm_orange.ico") - set(_minixer_rc "${CMAKE_CURRENT_BINARY_DIR}/Minixer_generated_resources.rc") - file(WRITE "${_minixer_rc}" - "// Auto-generated by CMake\n" - "IDI_ICON1 ICON \"${CMAKE_CURRENT_SOURCE_DIR}/assets/minixer_06_warm_orange.ico\"\n") - target_sources(Minixer PRIVATE "${_minixer_rc}") + # 应用图标(Windows .ico)。JUCE 的 ICON_BIG 在 Windows 上会调用 juceaide 转换图片格式, + # 因此这里直接生成 resources.rc 并链接,避免对输入格式的额外要求。 + if(WIN32 AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/minixer_06_warm_orange.ico") + set(_minixer_rc "${CMAKE_CURRENT_BINARY_DIR}/Minixer_generated_resources.rc") + file(WRITE "${_minixer_rc}" + "// Auto-generated by CMake\n" + "IDI_ICON1 ICON \"${CMAKE_CURRENT_SOURCE_DIR}/assets/minixer_06_warm_orange.ico\"\n") + target_sources(Minixer PRIVATE "${_minixer_rc}") + endif() + + target_sources(Minixer PRIVATE ${_minixer_sources}) + + target_include_directories(Minixer PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Source + ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode + ${_asio_include_dir}) + + target_compile_definitions(Minixer PRIVATE + JUCE_STRICT_REFCOUNTEDPOINTER=1 + JUCE_PLUGINHOST_VST3=1 + JUCE_ASIO=1 + JUCE_WEB_BROWSER=0 + JUCE_USE_CURL=0 + JUCE_DISPLAY_SPLASH_SCREEN=0 + DONT_SET_USING_JUCE_NAMESPACE=1) + + if(MSVC) + target_compile_definitions(Minixer PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_options(Minixer PRIVATE /utf-8 /W4) + else() + target_compile_options(Minixer PRIVATE -Wall -Wextra) + endif() + + target_link_libraries(Minixer PRIVATE + juce::juce_audio_basics + juce::juce_audio_devices + juce::juce_audio_formats + juce::juce_audio_processors + juce::juce_audio_utils + juce::juce_core + juce::juce_data_structures + juce::juce_events + juce::juce_graphics + juce::juce_gui_basics + juce::juce_gui_extra) endif() -target_sources(Minixer PRIVATE ${_minixer_sources}) - -target_include_directories(Minixer PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/Source - ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode) - -target_compile_definitions(Minixer PRIVATE - JUCE_STRICT_REFCOUNTEDPOINTER=1 - JUCE_PLUGINHOST_VST3=1 - JUCE_WEB_BROWSER=0 - JUCE_USE_CURL=0 - JUCE_DISPLAY_SPLASH_SCREEN=0 - DONT_SET_USING_JUCE_NAMESPACE=1) - -if(MSVC) - target_compile_definitions(Minixer PRIVATE _CRT_SECURE_NO_WARNINGS) - target_compile_options(Minixer PRIVATE /utf-8 /W4) -else() - target_compile_options(Minixer PRIVATE -Wall -Wextra) -endif() - -target_link_libraries(Minixer PRIVATE - juce::juce_audio_basics - juce::juce_audio_devices - juce::juce_audio_formats - juce::juce_audio_processors - juce::juce_audio_utils - juce::juce_core - juce::juce_data_structures - juce::juce_events - juce::juce_graphics - juce::juce_gui_basics - juce::juce_gui_extra) - # ============================================================================== # 4. PluginHost 子进程 (console app) # ============================================================================== @@ -217,11 +265,13 @@ target_sources(PluginHost PRIVATE ${_pluginhost_sources}) target_include_directories(PluginHost PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source - ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode) + ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode + ${_asio_include_dir}) target_compile_definitions(PluginHost PRIVATE JUCE_STRICT_REFCOUNTEDPOINTER=1 JUCE_PLUGINHOST_VST3=1 + JUCE_ASIO=1 JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_DISPLAY_SPLASH_SCREEN=0 @@ -256,19 +306,34 @@ endif() # 5. 构建后:将 PluginHost 复制到 Minixer 输出目录 # ============================================================================== # 运行期要求 PluginHost64.exe / PluginHost32.exe 与 Minixer.exe 位于同一目录。 +# x64 构建时复制到同目录 Minixer 旁边;x86 构建时复制到 64 位 Minixer 的固定输出目录。 if(WIN32) - add_custom_command(TARGET PluginHost POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "$" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "$" - "$/") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + add_custom_command(TARGET PluginHost POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" + "$/") + else() + set(_minixer_release_dir "${CMAKE_CURRENT_SOURCE_DIR}/build/Minixer_artefacts/Release") + add_custom_command(TARGET PluginHost POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${_minixer_release_dir}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" + "${_minixer_release_dir}/") + endif() endif() # ============================================================================== # 6. 安装/打包辅助(可选) # ============================================================================== -install(TARGETS Minixer PluginHost - RUNTIME DESTINATION bin) +if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + install(TARGETS Minixer PluginHost + RUNTIME DESTINATION bin) +else() + install(TARGETS PluginHost + RUNTIME DESTINATION bin) +endif() if(WIN32) install(FILES "$" DESTINATION bin) diff --git a/Source/Components/AboutComponent.cpp b/Source/Components/AboutComponent.cpp new file mode 100644 index 0000000..9f1f35e --- /dev/null +++ b/Source/Components/AboutComponent.cpp @@ -0,0 +1,96 @@ +#include "AboutComponent.h" +#include "../LookAndFeel/MixerLookAndFeel.h" + +namespace minixer +{ + +//============================================================================== +AboutComponent::AboutComponent() +{ + titleLabel.setText (TRANS("Minixer"), juce::dontSendNotification); + titleLabel.setFont (juce::Font (juce::FontOptions (24.0f)).boldened()); + titleLabel.setColour (juce::Label::textColourId, MixerLookAndFeel::getAccentColour()); + titleLabel.setJustificationType (juce::Justification::centred); + addAndMakeVisible (titleLabel); + + versionLabel.setText (TRANS("Version 1.0.0"), juce::dontSendNotification); + versionLabel.setFont (juce::Font (juce::FontOptions (14.0f))); + versionLabel.setColour (juce::Label::textColourId, MixerLookAndFeel::getMutedTextColour()); + versionLabel.setJustificationType (juce::Justification::centred); + addAndMakeVisible (versionLabel); + + descriptionLabel.setText (TRANS("A lightweight single-channel standalone audio mixer"), + juce::dontSendNotification); + descriptionLabel.setFont (juce::Font (juce::FontOptions (14.0f))); + descriptionLabel.setColour (juce::Label::textColourId, MixerLookAndFeel::getTextColour()); + descriptionLabel.setJustificationType (juce::Justification::centred); + addAndMakeVisible (descriptionLabel); + + githubLink.setButtonText (TRANS("GitHub: github.com/XmengMD/Minixer")); + githubLink.setURL (juce::URL ("https://github.com/XmengMD/Minixer")); + githubLink.setColour (juce::HyperlinkButton::textColourId, MixerLookAndFeel::getAccentColour()); + githubLink.setFont (juce::Font (juce::FontOptions (14.0f)), false); + addAndMakeVisible (githubLink); + + noticeEditor.setMultiLine (true); + noticeEditor.setReadOnly (true); + noticeEditor.setCaretVisible (false); + noticeEditor.setFont (juce::Font (juce::FontOptions (12.0f))); + noticeEditor.setColour (juce::TextEditor::backgroundColourId, MixerLookAndFeel::getSurfaceColour()); + noticeEditor.setColour (juce::TextEditor::textColourId, MixerLookAndFeel::getTextColour()); + noticeEditor.setColour (juce::TextEditor::outlineColourId, MixerLookAndFeel::getBorderColour()); + noticeEditor.setColour (juce::TextEditor::focusedOutlineColourId, MixerLookAndFeel::getBorderColour()); + + noticeEditor.setText ( + TRANS("License\n") + + TRANS("-------\n") + + TRANS("Minixer is licensed under the GNU Affero General Public License v3.0 (AGPLv3).\n") + + TRANS("Source code is available at the GitHub repository above.\n\n") + + TRANS("Third-Party Notices\n") + + TRANS("-------------------\n") + + TRANS("JUCE framework: Copyright Raw Material Software Limited. " + "Dual-licensed under AGPLv3 and the JUCE commercial licence.\n\n") + + TRANS("ASIO: ASIO is a trademark and software of Steinberg Media Technologies GmbH. " + "This application uses the Steinberg ASIO SDK under the terms of the " + "Steinberg ASIO Licensing Agreement. Redistribution of the ASIO SDK is not permitted.\n\n") + + TRANS("VST3: VST is a trademark of Steinberg Media Technologies GmbH. " + "This application uses the Steinberg VST3 SDK under the terms of the " + "Steinberg VST3 License or GPLv3.\n\n") + + TRANS("This software is provided \"as is\", without warranty of any kind.\n")); + addAndMakeVisible (noticeEditor); + + closeButton.setLookAndFeel (&getLookAndFeel()); + closeButton.setColour (juce::TextButton::buttonColourId, MixerLookAndFeel::getSurfaceColour()); + closeButton.setColour (juce::TextButton::textColourOffId, MixerLookAndFeel::getTextColour()); + closeButton.onClick = [this] + { + if (onClose != nullptr) + onClose(); + }; + addAndMakeVisible (closeButton); +} + +//============================================================================== +void AboutComponent::resized() +{ + auto bounds = getLocalBounds().reduced (20, 20); + + titleLabel.setBounds (bounds.removeFromTop (34)); + bounds.removeFromTop (4); + versionLabel.setBounds (bounds.removeFromTop (18)); + bounds.removeFromTop (8); + descriptionLabel.setBounds (bounds.removeFromTop (20)); + bounds.removeFromTop (12); + + auto linkBounds = bounds.removeFromTop (24); + githubLink.setBounds (linkBounds.withSizeKeepingCentre ( + juce::jmin (linkBounds.getWidth(), 320), 24)); + bounds.removeFromTop (12); + + closeButton.setBounds (bounds.removeFromBottom (30).withSizeKeepingCentre (100, 30)); + bounds.removeFromBottom (12); + + noticeEditor.setBounds (bounds); +} + +} // namespace minixer diff --git a/Source/Components/AboutComponent.h b/Source/Components/AboutComponent.h new file mode 100644 index 0000000..174ac70 --- /dev/null +++ b/Source/Components/AboutComponent.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +namespace minixer +{ + +//============================================================================== +/** 关于页面组件。 + + 展示软件信息、开源协议、GitHub 地址以及第三方 SDK(ASIO、VST3、JUCE)的许可声明。 +*/ +class AboutComponent : public juce::Component +{ +public: + //============================================================================== + AboutComponent(); + ~AboutComponent() override = default; + + //============================================================================== + void resized() override; + + //============================================================================== + std::function onClose; + +private: + //============================================================================== + juce::Label titleLabel; + juce::Label versionLabel; + juce::Label descriptionLabel; + juce::HyperlinkButton githubLink; + juce::TextEditor noticeEditor; + juce::TextButton closeButton { TRANS("Close") }; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AboutComponent) +}; + +} // namespace minixer diff --git a/Source/Components/LevelMeterComponent.cpp b/Source/Components/LevelMeterComponent.cpp index 0e88434..04e8070 100644 --- a/Source/Components/LevelMeterComponent.cpp +++ b/Source/Components/LevelMeterComponent.cpp @@ -148,8 +148,8 @@ void LevelMeterComponent::showStandardMenu() menu.addSeparator(); menu.addItem (resetStandardMenuId, - juce::String::fromUTF8 ("\xe6\x81\xa2\xe5\xa4\x8d\xe9\xbb\x98\xe8\xae\xa4 (dBFS)")); - + TRANS("Reset to Default (dBFS)")); + menu.showMenuAsync (juce::PopupMenu::Options(), [this] (int result) { diff --git a/Source/Components/SettingsComponent.cpp b/Source/Components/SettingsComponent.cpp index f495f43..3822890 100644 --- a/Source/Components/SettingsComponent.cpp +++ b/Source/Components/SettingsComponent.cpp @@ -20,6 +20,13 @@ SettingsComponent::SettingsComponent (juce::AudioDeviceManager& manager) setupLabel (outputDeviceLabel, TRANS ("Output Device")); setupComboBox (outputDeviceComboBox); + asioControlPanelButton.setLookAndFeel (&getLookAndFeel()); + asioControlPanelButton.setColour (juce::TextButton::buttonColourId, MixerLookAndFeel::getSurfaceColour()); + asioControlPanelButton.setColour (juce::TextButton::textColourOffId, MixerLookAndFeel::getTextColour()); + asioControlPanelButton.addListener (this); + asioControlPanelButton.setVisible (false); + addAndMakeVisible (asioControlPanelButton); + setupLabel (sampleRateLabel, TRANS ("Sample Rate")); setupComboBox (sampleRateComboBox); @@ -62,6 +69,14 @@ SettingsComponent::SettingsComponent (juce::AudioDeviceManager& manager) configureShortcutsButton.addListener (this); addAndMakeVisible (configureShortcutsButton); + // 关于 + setupSectionLabel (aboutSectionLabel, TRANS ("About")); + aboutButton.setLookAndFeel (&getLookAndFeel()); + aboutButton.setColour (juce::TextButton::buttonColourId, MixerLookAndFeel::getSurfaceColour()); + aboutButton.setColour (juce::TextButton::textColourOffId, MixerLookAndFeel::getTextColour()); + aboutButton.addListener (this); + addAndMakeVisible (aboutButton); + auto& settings = AppSettings::getInstance(); updatingUI = true; launchOnStartupToggle.setToggleState (settings.getLaunchOnStartup(), juce::dontSendNotification); @@ -95,8 +110,8 @@ void SettingsComponent::resized() auto bounds = getLocalBounds().reduced (16, 16); const auto labelWidth = juce::jmin (120, bounds.getWidth() / 3); const auto gap = 8; - const int numRows = 17; - const int numGaps = 16; + const int numRows = 19; + const int numGaps = 18; const auto rowHeight = juce::jmax (1, juce::jmin (32, (bounds.getHeight() - numGaps * gap) / juce::jmax (1, numRows))); @@ -122,7 +137,12 @@ void SettingsComponent::resized() layoutFullRow (audioSectionLabel); layoutRow (driverLabel, driverComboBox); layoutRow (inputDeviceLabel, inputDeviceComboBox); - layoutRow (outputDeviceLabel, outputDeviceComboBox); + + if (isAsioMode()) + layoutRow (outputDeviceLabel, asioControlPanelButton); + else + layoutRow (outputDeviceLabel, outputDeviceComboBox); + layoutRow (sampleRateLabel, sampleRateComboBox); layoutRow (bufferSizeLabel, bufferSizeComboBox); @@ -153,6 +173,9 @@ void SettingsComponent::resized() layoutFullRow (shortcutsSectionLabel); layoutFullRow (configureShortcutsButton); + + layoutFullRow (aboutSectionLabel); + layoutFullRow (aboutButton); } //============================================================================== @@ -176,6 +199,12 @@ void SettingsComponent::comboBoxChanged (juce::ComboBox* comboBox) updatingUI = false; } } + else if (comboBox == &inputDeviceComboBox && isAsioMode()) + { + // ASIO 模式下 input 下拉框实际上用于选择单一 ASIO 设备 + // 选择后需要同时更新 input/output 设备名 + applyAsioDeviceSelection(); + } else { applyAudioSetup(); @@ -220,6 +249,16 @@ void SettingsComponent::buttonClicked (juce::Button* button) { showShortcutsSettingsWindow(); } + else if (button == &aboutButton) + { + showAboutWindow(); + return; + } + else if (button == &asioControlPanelButton) + { + openAsioControlPanel(); + return; + } notifyPreferencesChanged(); } @@ -351,6 +390,43 @@ void SettingsComponent::refreshDeviceLists() type->scanForDevices(); + if (isAsioMode()) + { + // ASIO 模式下 input 下拉框用于选择单一 ASIO 设备 + auto names = type->getDeviceNames (true); + + for (auto& name : names) + { + if (allDeviceNames.indexOf (name) < 0) + { + allDeviceNames.add (name); + deviceIsInput.add (true); + deviceIsOutput.add (true); + } + } + + // 若输入列表为空,尝试输出列表(ASIO 通常一致,但为防万一) + if (allDeviceNames.isEmpty()) + { + names = type->getDeviceNames (false); + + for (auto& name : names) + { + if (allDeviceNames.indexOf (name) < 0) + { + allDeviceNames.add (name); + deviceIsInput.add (true); + deviceIsOutput.add (true); + } + } + } + + for (int i = 0; i < allDeviceNames.size(); ++i) + inputDeviceComboBox.addItem (allDeviceNames[i], i + 1); + + return; + } + auto inputNames = type->getDeviceNames (true); auto outputNames = type->getDeviceNames (false); @@ -449,6 +525,70 @@ void SettingsComponent::applyAudioSetup() notifyAudioSettingsChanged(); } +//============================================================================== +void SettingsComponent::applyAsioDeviceSelection() +{ + if (updatingUI) + return; + + auto setup = deviceManager.getAudioDeviceSetup(); + + auto inputId = inputDeviceComboBox.getSelectedId(); + if (juce::isPositiveAndBelow (inputId - 1, allDeviceNames.size())) + { + // ASIO 设备同时作为输入和输出 + setup.inputDeviceName = allDeviceNames[inputId - 1]; + setup.outputDeviceName = allDeviceNames[inputId - 1]; + } + + auto sampleRateId = sampleRateComboBox.getSelectedId(); + if (sampleRateId > 0) + setup.sampleRate = static_cast (sampleRateId); + + auto bufferSizeId = bufferSizeComboBox.getSelectedId(); + if (bufferSizeId > 0) + setup.bufferSize = bufferSizeId; + + auto error = deviceManager.setAudioDeviceSetup (setup, true); + + if (error.isNotEmpty()) + { + juce::AlertWindow::showMessageBoxAsync (juce::AlertWindow::WarningIcon, + TRANS ("Audio Device Error"), + error); + } + + notifyAudioSettingsChanged(); +} + +//============================================================================== +void SettingsComponent::openAsioControlPanel() +{ + auto* device = deviceManager.getCurrentAudioDevice(); + + if (device == nullptr) + { + juce::AlertWindow::showMessageBoxAsync (juce::AlertWindow::WarningIcon, + TRANS ("ASIO Control Panel"), + TRANS ("No ASIO device is currently open.")); + return; + } + + if (! device->hasControlPanel()) + { + juce::AlertWindow::showMessageBoxAsync (juce::AlertWindow::WarningIcon, + TRANS ("ASIO Control Panel"), + TRANS ("The current device does not provide a control panel.")); + return; + } + + device->showControlPanel(); + + // 控制面板关闭后重新枚举,因为用户可能改动了采样率/缓冲区大小 + refreshSampleRatesAndBufferSizes(); + updateUIFromSetup(); +} + //============================================================================== void SettingsComponent::updateUIFromSetup() { @@ -470,6 +610,17 @@ void SettingsComponent::updateUIFromSetup() // 重新枚举当前类型的设备 refreshDeviceLists(); + const bool asio = isAsioMode(); + + // 切换 ASIO 模式下的控件显示/文本 + inputDeviceLabel.setText (asio ? TRANS ("ASIO Device") : TRANS ("Input Device"), + juce::dontSendNotification); + outputDeviceLabel.setText (asio ? TRANS ("ASIO Settings") : TRANS ("Output Device"), + juce::dontSendNotification); + + outputDeviceComboBox.setVisible (! asio); + asioControlPanelButton.setVisible (asio); + // 同步 Input / Output 选择 auto setup = deviceManager.getAudioDeviceSetup(); @@ -477,9 +628,12 @@ void SettingsComponent::updateUIFromSetup() if (inputIdx >= 0) inputDeviceComboBox.setSelectedId (inputIdx + 1, juce::dontSendNotification); - auto outputIdx = findDeviceIndex (setup.outputDeviceName); - if (outputIdx >= 0) - outputDeviceComboBox.setSelectedId (outputIdx + 1, juce::dontSendNotification); + if (! asio) + { + auto outputIdx = findDeviceIndex (setup.outputDeviceName); + if (outputIdx >= 0) + outputDeviceComboBox.setSelectedId (outputIdx + 1, juce::dontSendNotification); + } // 同步采样率/缓冲区 refreshSampleRatesAndBufferSizes(); @@ -490,6 +644,9 @@ void SettingsComponent::updateUIFromSetup() if (setup.bufferSize > 0) bufferSizeComboBox.setSelectedId (setup.bufferSize, juce::dontSendNotification); + // 模式切换后需要重新布局,确保 ASIO 控制面板按钮获得正确 bounds + resized(); + updatingUI = false; } @@ -529,6 +686,12 @@ juce::AudioIODeviceType* SettingsComponent::getCurrentDeviceType() const return types.isEmpty() ? nullptr : types[0]; } +//============================================================================== +bool SettingsComponent::isAsioMode() const +{ + return deviceManager.getCurrentAudioDeviceType().equalsIgnoreCase ("ASIO"); +} + //============================================================================== int SettingsComponent::findDeviceIndex (const juce::String& deviceName) const { @@ -670,6 +833,50 @@ void SettingsComponent::shortcutsSettingsCancelled() shortcutsSettingsWindow->setVisible (false); } +//============================================================================== +namespace +{ + //============================================================================== + /** 关于窗口:关闭按钮仅隐藏窗口,便于再次打开。 */ + struct AboutWindow : public juce::DocumentWindow + { + AboutWindow (const juce::String& name, juce::Colour bg) + : juce::DocumentWindow (name, bg, juce::DocumentWindow::closeButton) + { + } + + void closeButtonPressed() override + { + setVisible (false); + } + }; +} + +//============================================================================== +void SettingsComponent::showAboutWindow() +{ + if (aboutWindow == nullptr) + { + auto* content = new AboutComponent(); + + content->onClose = [this] + { + if (aboutWindow != nullptr) + aboutWindow->setVisible (false); + }; + + aboutWindow.reset (new AboutWindow (TRANS ("About Minixer"), + MixerLookAndFeel::getBackgroundColour())); + aboutWindow->setContentOwned (content, true); + aboutWindow->setUsingNativeTitleBar (true); + aboutWindow->setResizable (false, false); + aboutWindow->centreWithSize (520, 440); + } + + aboutWindow->setVisible (true); + aboutWindow->toFront (true); +} + //============================================================================== void SettingsComponent::notifyShortcutsChanged() { diff --git a/Source/Components/SettingsComponent.h b/Source/Components/SettingsComponent.h index 0894bd9..8076e9a 100644 --- a/Source/Components/SettingsComponent.h +++ b/Source/Components/SettingsComponent.h @@ -4,6 +4,7 @@ #include "../Settings/AppSettings.h" #include "../Plugin/PluginManagerComponent.h" #include "ShortcutsSettingsComponent.h" +#include "AboutComponent.h" namespace minixer { @@ -60,6 +61,8 @@ private: void refreshDeviceLists(); void refreshSampleRatesAndBufferSizes(); void applyAudioSetup(); + void applyAsioDeviceSelection(); + void openAsioControlPanel(); void updateUIFromSetup(); void updateAutoLoadPresetEnabledState(); void launchAutoLoadPresetFileChooser(); @@ -68,6 +71,7 @@ private: void notifyShortcutsChanged(); void showPluginManagerWindow(); void showShortcutsSettingsWindow(); + void showAboutWindow(); void refreshPluginCount(); //============================================================================== @@ -92,6 +96,7 @@ private: juce::Label outputDeviceLabel; juce::ComboBox outputDeviceComboBox; + juce::TextButton asioControlPanelButton { TRANS("Open ASIO Control Panel") }; juce::Label sampleRateLabel; juce::ComboBox sampleRateComboBox; @@ -99,6 +104,9 @@ private: juce::Label bufferSizeLabel; juce::ComboBox bufferSizeComboBox; + //============================================================================== + bool isAsioMode() const; + // 应用偏好 juce::Label preferencesSectionLabel; juce::ToggleButton launchOnStartupToggle; @@ -114,10 +122,14 @@ private: juce::TextButton managePluginsButton { TRANS("Manage Plugins") }; juce::Label pluginCountLabel; - // 快捷键设置 + // 快捷键设置区 juce::Label shortcutsSectionLabel; juce::TextButton configureShortcutsButton { TRANS("Configure Shortcuts...") }; + // 关于 + juce::Label aboutSectionLabel; + juce::TextButton aboutButton { TRANS("About Minixer") }; + juce::StringArray allDeviceNames; juce::Array deviceIsInput; juce::Array deviceIsOutput; @@ -126,6 +138,7 @@ private: std::unique_ptr pluginManagerWindow; std::unique_ptr shortcutsSettingsWindow; + std::unique_ptr aboutWindow; juce::ListenerList listeners; diff --git a/Source/Plugin/PluginManagerComponent.cpp b/Source/Plugin/PluginManagerComponent.cpp index da7c4e7..c398f0a 100644 --- a/Source/Plugin/PluginManagerComponent.cpp +++ b/Source/Plugin/PluginManagerComponent.cpp @@ -29,7 +29,7 @@ PluginManagerComponent::PluginManagerComponent() // 的 JUCE_ASSERT_MESSAGE_THREAD)必须在消息线程执行。将扫描线程数设为 0, // PluginListComponent 会改为在消息线程上通过 Timer 轮询同步扫描;进度对话 // 框仍会正常显示,并在每个插件扫描间隙刷新进度。 - pluginListComponent.setScanDialogText (TRANS ("Scanning for VST3 plugins…"), + pluginListComponent.setScanDialogText (TRANS ("Scanning for VST3 plugins"), TRANS ("Please wait while the plugins are scanned.")); pluginListComponent.setNumberOfThreadsForScanning (0); @@ -40,9 +40,18 @@ PluginManagerComponent::PluginManagerComponent() addAndMakeVisible (pluginListComponent); + scanStatusLabel.setFont (juce::Font (juce::FontOptions (12.0f))); + scanStatusLabel.setColour (juce::Label::textColourId, MixerLookAndFeel::getTextColour()); + scanStatusLabel.setJustificationType (juce::Justification::centredLeft); + scanStatusLabel.setText (TRANS ("Ready"), juce::dontSendNotification); + addAndMakeVisible (scanStatusLabel); + // 监听 KnownPluginList 变化,在扫描结束后展示扫描报告。 PluginRegistry::getInstance().getKnownPluginList().addChangeListener (this); + // 启动状态轮询定时器,用于在扫描期间更新 scanStatusLabel。 + startTimer (scanStatusTimerMs); + setSize (600, 500); } @@ -68,9 +77,15 @@ void PluginManagerComponent::resized() auto bounds = getLocalBounds().reduced (8); auto buttonHeight = 28; - rescanFailedPluginsButton.setBounds (bounds.removeFromTop (buttonHeight)); + auto statusHeight = 22; - pluginListComponent.setBounds (bounds.withTrimmedTop (8)); + rescanFailedPluginsButton.setBounds (bounds.removeFromTop (buttonHeight)); + bounds.removeFromTop (8); + + scanStatusLabel.setBounds (bounds.removeFromBottom (statusHeight)); + bounds.removeFromBottom (4); + + pluginListComponent.setBounds (bounds); } //============================================================================== @@ -79,32 +94,61 @@ void PluginManagerComponent::changeListenerCallback (juce::ChangeBroadcaster* so if (source != &PluginRegistry::getInstance().getKnownPluginList()) return; - // 每次列表变化都重新启动防抖定时器,扫描真正结束后再展示报告。 - startTimer (scanReportDelayMs); + // 每次列表变化都重置防抖计数器,扫描真正结束后再展示报告。 + scanReportDelayCounter = 5; } //============================================================================== void PluginManagerComponent::timerCallback() { - stopTimer(); - auto& registry = PluginRegistry::getInstance(); - // 让 PluginRegistry 检测扫描是否已空闲,若已空闲则结束本次报告。 - registry.checkAndFinishIdleScan(); - - // 扫描仍在进行中则继续等待。 - if (registry.isScanInProgress()) + // 更新扫描状态标签:PluginListComponent 已创建 Scanner 但 PluginRegistry + // 尚未开始记录单个文件时,说明正处于 JUCE 的目录枚举阶段。 + if (pluginListComponent.isScanning()) { - startTimer (scanReportDelayMs); - return; + if (registry.isScanInProgress()) + { + auto currentFile = registry.getCurrentScanningFile(); + + if (currentFile.isNotEmpty()) + { + scanStatusLabel.setText (TRANS ("Scanning: ") + juce::File (currentFile).getFileName(), + juce::dontSendNotification); + } + else + { + scanStatusLabel.setText (TRANS ("Scanning plugins"), + juce::dontSendNotification); + } + } + else + { + scanStatusLabel.setText (TRANS ("Enumerating plugin directories"), + juce::dontSendNotification); + } + } + else + { + scanStatusLabel.setText (TRANS ("Ready"), juce::dontSendNotification); } - // 扫描已真正结束,且存在未展示的报告时,弹出最终报告并清理一次性状态。 - if (registry.getLastScanReport().hasUnshownReport) + // 扫描报告防抖:每次 KnownPluginList 变化时计数器重置为 5(约 500ms)。 + // 计数器归零且扫描真正空闲时,弹出扫描报告。 + if (scanReportDelayCounter > 0) { - rescanFailedPluginsButton.setToggleState (false, juce::dontSendNotification); - showScanReportIfNeeded(); + --scanReportDelayCounter; + + if (scanReportDelayCounter == 0) + { + registry.checkAndFinishIdleScan(); + + if (! registry.isScanInProgress() && registry.getLastScanReport().hasUnshownReport) + { + rescanFailedPluginsButton.setToggleState (false, juce::dontSendNotification); + showScanReportIfNeeded(); + } + } } } @@ -137,7 +181,7 @@ juce::String PluginManagerComponent::formatScanReport (const PluginScanReport& r if (report.failedEntries.size() > maxFailedEntriesToShow) { - text << " " << TRANS ("…and") << " " + text << " " << TRANS ("and") << " " << (report.failedEntries.size() - maxFailedEntriesToShow) << " " << TRANS ("more") << "\n"; } diff --git a/Source/Plugin/PluginManagerComponent.h b/Source/Plugin/PluginManagerComponent.h index 80d3407..1418a72 100644 --- a/Source/Plugin/PluginManagerComponent.h +++ b/Source/Plugin/PluginManagerComponent.h @@ -54,9 +54,13 @@ private: //============================================================================== juce::ToggleButton rescanFailedPluginsButton; juce::PluginListComponent pluginListComponent; + juce::Label scanStatusLabel; - /** 扫描报告防抖定时器:KnownPluginList 变化后延迟展示报告,避免扫描过程中频繁弹窗。 */ - static constexpr int scanReportDelayMs = 500; + /** 扫描报告防抖计数器(以 timer tick 为单位,5 ticks × 100ms = 500ms)。 */ + int scanReportDelayCounter = 0; + + /** 扫描状态轮询与报告防抖定时器间隔(ms)。 */ + static constexpr int scanStatusTimerMs = 100; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginManagerComponent) }; diff --git a/Source/Plugin/PluginRegistry.cpp b/Source/Plugin/PluginRegistry.cpp index c7c0f7a..9ae0d76 100644 --- a/Source/Plugin/PluginRegistry.cpp +++ b/Source/Plugin/PluginRegistry.cpp @@ -426,7 +426,17 @@ public: int& c; }; + // 记录当前正在扫描的文件路径,供 UI 状态标签显示。 + struct CurrentFileGuard + { + CurrentFileGuard (juce::String& target, const juce::String& value) + : target (target) { target = value; } + ~CurrentFileGuard() { target.clear(); } + juce::String& target; + }; + const ActiveScanGuard guard (registry.activeScanCount); + const CurrentFileGuard fileGuard (registry.currentScanningFile, fileOrIdentifier); const auto file = juce::File (fileOrIdentifier); const auto now = juce::Time::getCurrentTime(); @@ -815,6 +825,12 @@ void PluginRegistry::checkAndFinishIdleScan() finishScanReport(); } +//============================================================================== +juce::String PluginRegistry::getCurrentScanningFile() const noexcept +{ + return currentScanningFile; +} + //============================================================================== void PluginRegistry::recordScanSuccess (const juce::File& file, const juce::OwnedArray& descriptions, diff --git a/Source/Plugin/PluginRegistry.h b/Source/Plugin/PluginRegistry.h index d29eed4..e169a0e 100644 --- a/Source/Plugin/PluginRegistry.h +++ b/Source/Plugin/PluginRegistry.h @@ -117,6 +117,9 @@ public: /** 返回是否正在扫描中。 */ bool isScanInProgress() const noexcept { return scanInProgress; } + /** 返回当前正在扫描的文件路径(仅在单个文件扫描期间有效)。 */ + juce::String getCurrentScanningFile() const noexcept; + private: //============================================================================== PluginRegistry(); @@ -170,6 +173,9 @@ private: /** 最近一次扫描活动的时间,用于在消息线程扫描中自动识别扫描开始/结束。 */ juce::Time lastScanActivityTime; + /** 当前正在扫描的文件路径(仅在消息线程访问)。 */ + juce::String currentScanningFile; + /** 当前正在执行的 findPluginTypesFor 调用数;>0 表示有扫描尚未返回。 */ int activeScanCount = 0;