Ticket #486: DeleteMachine_and_RestoreConnections.patch

File DeleteMachine_and_RestoreConnections.patch, 6.4 kB (added by user, 3 months ago)

Patch :)

  • buzelib/buze.rc

     
    983983BEGIN 
    984984    VK_F1,          ID_HELP,                VIRTKEY, NOINVERT 
    985985 
     986        // TODO: don't know wether this one should be here or in `IDR_MAINFRAME ACCELERATORS` 
     987        VK_DELETE,              ID_MACHINE_DELETE_AND_RESTORE,   VIRTKEY, SHIFT, NOINVERT 
     988 
    986989        VK_UP,                  ID_MACHINE_MOVE_UP,                              VIRTKEY, CONTROL, NOINVERT 
    987990        VK_DOWN,                ID_MACHINE_MOVE_DOWN,                    VIRTKEY, CONTROL, NOINVERT 
    988991        VK_LEFT,                ID_MACHINE_MOVE_LEFT,                    VIRTKEY, CONTROL, NOINVERT 
  • buzelib/Document.cpp

     
    383383        } 
    384384 
    385385} 
     386void CDocument::deleteSelectedMachinesAndRestoreConnections() { 
     387        // TODO: this patch handles only audio connection. `Midi` and `event` connection can be  
     388        //       easily added here by analogy 
    386389 
     390        // It is be too difficult for now to perform and test delete->restore for more that one machine 
     391        if(getSelectedMachines() == 1) { 
     392                int plugin = getSelectedMachine(0); 
     393 
     394                // checking if machine has both input and output connections 
     395                // otherwise there is no sense to store and recall volumes  
     396                if(zzub_plugin_get_input_connection_count(player, plugin) > 0 && zzub_plugin_get_output_connection_count(player, plugin) > 0) { 
     397                        int inputVolume = 0, outputVolume = 0; 
     398                         
     399                        // looping through input connections 
     400                        for (int i = 0; i < zzub_plugin_get_input_connection_count(player, plugin); i++) { 
     401                                int in_plugin = zzub_plugin_get_input_connection_plugin(player, plugin, i); 
     402                                int audioconn_in = zzub_plugin_get_input_connection_by_type(player, plugin, in_plugin, zzub_connection_type_audio); 
     403                                assert(audioconn_in != -1); 
     404                                // geting input volume 
     405                                int inputVolume = zzub_plugin_get_parameter_value(player, plugin, 0, audioconn_in, 0); 
     406 
     407                                // looping through output connections 
     408                                for (int i = 0; i < zzub_plugin_get_output_connection_count(player, plugin); i++) { 
     409                                        int out_plugin = zzub_plugin_get_output_connection_plugin(player, plugin, i); 
     410                                        int audioconn_out = zzub_plugin_get_output_connection_by_type(player, plugin, out_plugin, zzub_connection_type_audio); 
     411                                        assert(audioconn_out != -1); 
     412                                        // geting input volume 
     413                                        int outputVolume = zzub_plugin_get_parameter_value(player, plugin, 0, audioconn_out, 0); 
     414                                         
     415                                        // connecting "in_plugin" to "out_plugin" and setting in+out volume taken from plugin been deleted 
     416                                        // Formula could be (inputVolume + outputVolume)/2 but in real situations it is better 
     417                                        // to have just `inputVolume` 
     418                                        connectMachinesAudio(in_plugin, out_plugin, inputVolume, 0x4000); 
     419                                } 
     420                        } 
     421                } 
     422        } 
     423        // Let's delete that machine at last 
     424        deleteSelectedMachines(); 
     425} 
     426 
     427 
    387428void CDocument::doublePatternRows(int machine, int pattern) { 
    388429 
    389430        int pattern_length = zzub_plugin_get_pattern_length(player, machine, pattern); 
  • buzelib/Document.h

     
    187187        bool connectMachinesMidi(int output, int input, string midiOutDevice); 
    188188        bool disconnectMachines(int output, int input, zzub_connection_type type); 
    189189    void deleteSelectedMachines(); 
     190        void deleteSelectedMachinesAndRestoreConnections(); 
    190191        bool importSong(std::vector<char>& bytes, int allowundo, std::string* error_messages); 
    191192        bool importSong(std::string filename, int allowundo, std::string* error_messages); 
    192193 
  • buzelib/MachineView.cpp

     
    22292229        return 0; 
    22302230} 
    22312231 
     2232LRESULT CMachineView::OnDeleteAndRestoreConnections(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled) { 
     2233//      MessageBox("Yooo"); 
     2234 
     2235        document->deleteSelectedMachinesAndRestoreConnections(); 
     2236        zzub_player_history_commit(player, "Delete Plugin(s)"); 
     2237 
     2238        //document->updateAllViews(this, UpdateMachineSelection); 
     2239        return 0; 
     2240} 
     2241 
    22322242LRESULT CMachineView::OnSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled) { 
    22332243        for (size_t i = 0; i < zzub_player_get_plugin_count(mainFrame->player); i++) { 
    22342244                int plugin_id = zzub_plugin_get_id(player, i); 
  • buzelib/MachineView.h

     
    139139                COMMAND_ID_HANDLER(ID_EDIT_COPY, OnCopy) 
    140140                COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnPaste) 
    141141                COMMAND_ID_HANDLER(ID_EDIT_DELETE, OnDelete) 
     142                COMMAND_ID_HANDLER(ID_MACHINE_DELETE_AND_RESTORE, OnDeleteAndRestoreConnections) 
    142143                COMMAND_ID_HANDLER(ID_EDIT_SELECTALL, OnSelectAll) 
    143144                COMMAND_ID_HANDLER(ID_EDIT_CLEARSELECTION, OnClearSelection) 
    144145                COMMAND_ID_HANDLER(ID_VIEW_PROPERTIES, OnViewProperties) 
     
    196197        LRESULT OnCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    197198        LRESULT OnPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    198199        LRESULT OnDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
     200        LRESULT OnDeleteAndRestoreConnections(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    199201        LRESULT OnSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    200202        LRESULT OnClearSelection(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
    201203        LRESULT OnViewProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 
  • buzelib/resource.h

     
    436436#define ID_MACHINE_MOVE_DOWN_RIGHT_STEP 53584 
    437437#define ID_MACHINE_MOVE_UP_RIGHT_STEP  53585 
    438438 
     439 
     440#define ID_MACHINE_DELETE_AND_RESTORE 53600 
     441 
    439442// Next default values for new objects 
    440443//  
    441444#ifdef APSTUDIO_INVOKED 
    442445#ifndef APSTUDIO_READONLY_SYMBOLS 
    443446#define _APS_NEXT_RESOURCE_VALUE        238 
    444 #define _APS_NEXT_COMMAND_VALUE         53586 
     447#define _APS_NEXT_COMMAND_VALUE         53601 
    445448#define _APS_NEXT_CONTROL_VALUE         1084 
    446449#define _APS_NEXT_SYMED_VALUE           101 
    447450#endif