MCPcopy Create free account
hub / github.com/TheWaveWarden/odin2 / loadPatchFromOpenedFileStream

Method loadPatchFromOpenedFileStream

Source/gui/PatchBrowser.cpp:608–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608void PatchBrowser::loadPatchFromOpenedFileStream(juce::FileInputStream &p_file_stream) {
609 //first see if the patch is of a higher version than we know about:
610 std::string version_string;
611 if (checkForBiggerVersion(p_file_stream, version_string)) {
612 //abort with icon
613 AlertWindow::showMessageBox(AlertWindow::AlertIconType::WarningIcon,
614 "Cannot load patch!",
615 "The bad news: You cannot load this patch, because you are on version " + ODIN_VERSION_STRING +
616 ".\nThe good news: The patch you're trying to load was created on version " + version_string +
617 ". So go to www.thewavewarden.com and download the latest version of Odin2!",
618 "Thanks, I will!");
619 return;
620 }
621
622 // if we're reading an older patch version we set the default patch first
623 // since new params might not exist and will only be set
624 if (checkForSmallerVersion(p_file_stream, version_string)) {
625 DBG("Reading older patch, setting init patch first");
626 MemoryInputStream init_stream(BinaryData::init_patch_odin, BinaryData::init_patch_odinSize, false);
627 m_audio_processor.readPatch(ValueTree::readFromStream(init_stream));
628 }
629
630 //reset stream position
631 p_file_stream.setPosition(0);
632 m_audio_processor.readPatch(ValueTree::readFromStream(p_file_stream).createCopy());
633
634 //setPatchBrowser to be shown
635 m_value_tree.state.getChildWithName("misc").setProperty("arp_mod_selected", MATRIX_SECTION_INDEX_PRESETS, nullptr);
636
637 //note: 99% percent of patch-loading time is spent here:
638 juce::ScopedValueSetter<bool> setter(m_is_selected_from_internal, true);
639 forceValueTreeLambda();
640
641 //set the correct Version number again
642 m_value_tree.state.getChildWithName("misc").setProperty("version_minor", ODIN_MINOR_VERSION, nullptr);
643 m_value_tree.state.getChildWithName("misc").setProperty("version_patch", ODIN_PATCH_VERSION, nullptr);
644 m_value_tree.state.getChildWithName("misc").setProperty("patch_migration_version", ODIN_PATCH_MIGRATION_VERSION, nullptr);
645}
646
647bool PatchBrowser::checkForBiggerVersion(FileInputStream &p_file_stream, std::string &p_version_string) {
648 p_file_stream.setPosition(0);

Callers

nothing calls this directly

Calls 2

readPatchMethod · 0.80
setPositionMethod · 0.45

Tested by

no test coverage detected