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

Method savePatchInOpenedFileStream

Source/gui/PatchBrowser.cpp:672–730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

670}
671
672void PatchBrowser::savePatchInOpenedFileStream(FileOutputStream &p_file_stream) {
673 // use this to overwrite old content
674 p_file_stream.setPosition(0);
675 p_file_stream.truncate();
676
677 //write patch name onto valuetree
678 m_value_tree.state.getChildWithName("misc").setProperty("patch_name", p_file_stream.getFile().getFileNameWithoutExtension(), nullptr);
679 DBG(m_value_tree.state.getChildWithName("misc")["patch_name"].toString());
680
681 //make a deep copy and remove the midi_learn part and file name
682 ValueTree copy_with_removed_params = m_value_tree.state.createCopy();
683 copy_with_removed_params.removeChild(copy_with_removed_params.getChildWithName("midi_learn"), nullptr);
684 copy_with_removed_params.getChildWithName("misc").removeProperty("current_patch_filename", nullptr);
685 copy_with_removed_params.getChildWithName("misc").removeProperty("current_patch_directory", nullptr);
686 copy_with_removed_params.getChildWithName("misc").removeProperty("arp_mod_selected", nullptr);
687
688 //remove draw osc params if they aren't needed
689 for (int osc = 1; osc < 4; ++osc) {
690 std::string osc_string = std::to_string(osc);
691
692 if (!usesWavedraw(osc)) {
693 //DBG("uses wavedraw " + String(osc));
694 for (int step = 0; step < WAVEDRAW_STEPS_X; ++step) {
695 copy_with_removed_params.getChildWithName("draw").removeProperty(String("osc" + osc_string + "_wavedraw_values_" + std::to_string(step)), nullptr);
696 }
697 }
698 if (!usesChipdraw(osc)) {
699 //DBG("uses chipdraw " + String(osc));
700 for (int step = 0; step < CHIPDRAW_STEPS_X; ++step) {
701 copy_with_removed_params.getChildWithName("draw").removeProperty(String("osc" + osc_string + "_chipdraw_values_" + std::to_string(step)), nullptr);
702 }
703 }
704 if (!usesSpecdraw(osc)) {
705 //DBG("uses specdraw " + String(osc));
706 for (int step = 0; step < SPECDRAW_STEPS_X; ++step) {
707 copy_with_removed_params.getChildWithName("draw").removeProperty(String("osc" + osc_string + "_specdraw_values_" + std::to_string(step)), nullptr);
708 }
709 }
710 }
711
712 //write valuetree into file
713 copy_with_removed_params.writeToStream(p_file_stream);
714
715 //set label
716 //m_patch.setText(m_value_tree.state.getChildWithName("misc")["patch_name"].toString().toStdString());
717
718 //save load directory
719 //m_last_directory = file_to_write.getParentDirectory().getFullPathName();
720
721 DBG(copy_with_removed_params.toXmlString());
722
723 m_value_tree.state.getChildWithName("misc").setProperty("current_patch_filename", p_file_stream.getFile().getFileName(),
724 nullptr); //needed for up/down buttons in patch loading
725 m_value_tree.state.getChildWithName("misc").setProperty("current_patch_directory",
726 p_file_stream.getFile().getParentDirectory().getFullPathName(),
727 nullptr); //needed for up/down buttons in patch loading
728 DBG("set filename in valuetree: " + m_value_tree.state.getChildWithName("misc")["current_patch_filename"].toString());
729 DBG("set filepath in valuetree: " + m_value_tree.state.getChildWithName("misc")["current_patch_directory"].toString());

Callers

nothing calls this directly

Calls 1

setPositionMethod · 0.45

Tested by

no test coverage detected