-
Notifications
You must be signed in to change notification settings - Fork 101
Feature/graph undo redo #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sudip-mondal-2002
merged 17 commits into
sudip-mondal-2002:main
from
MohitBareja16:feature/graph-undo-redo
May 28, 2026
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
94ba04f
test(audio): achieve 100% portaudio coverage and bypass gcc 13 dwarf …
MohitBareja16 e625ffb
build: add portaudio tests to CMake configuration
MohitBareja16 211978d
Merge branch 'main' into test-portaudio-coverage
MohitBareja16 0ec038f
test coverage for required files
MohitBareja16 f9a1b42
test coverage for required files
MohitBareja16 02ca35d
test coverage for required files
MohitBareja16 40d06ce
feat: implement comprehensive 2D audio graph undo/redo system
MohitBareja16 4675868
Merge branch 'main' into feature/graph-undo-redo
sudip-mondal-2002 217205e
Merge branch 'main' into feature/graph-undo-redo
MohitBareja16 4cf55e3
coderabbitai cases + test setup properly done
MohitBareja16 634725f
Merge branch 'main' into feature/graph-undo-redo
MohitBareja16 d0b5ff9
moved test code to test/fixtures/ and conflict issues resolved
MohitBareja16 8f9b835
Merge upstream/main into feature/graph-undo-redo and resolve UI refac…
MohitBareja16 36c2023
Merge upstream/main into feature/graph-undo-redo and resolve UI refac…
MohitBareja16 7322119
Merge upstream/main into feature/graph-undo-redo and resolve UI refac…
MohitBareja16 e3d89c0
Fix graph command edge cases, clean up singleton leaks, and achieve 1…
MohitBareja16 4513660
Merge branch 'main' into feature/graph-undo-redo
MohitBareja16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,5 +12,4 @@ struct AudioBackendState { | |
| PaStream* stream = nullptr; | ||
| }; | ||
|
|
||
|
|
||
| } // namespace Amplitron | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| #pragma once | ||
|
|
||
| #include "gui/command_base.h" | ||
| #include "audio/audio_engine.h" | ||
| #include "audio/audio_graph.h" | ||
| #include "gui/gui_graph_state.h" | ||
|
|
||
| namespace Amplitron { | ||
|
|
||
| using NodeId = int; | ||
| using EffectType = NodeRoutingType; | ||
|
|
||
| struct AddGraphNodeCommand : public Command { | ||
| AudioEngine& engine_; | ||
| NodeId node_id = -1; // Assigned on first execute | ||
| std::string name; | ||
| EffectType type; | ||
| std::shared_ptr<Effect> pedal; | ||
| ImVec2 position; | ||
| DSPNode cached_node; // To remember exactly what was added for redo | ||
|
|
||
| AddGraphNodeCommand(AudioEngine& engine, const std::string& name, EffectType type, std::shared_ptr<Effect> pedal, ImVec2 pos) | ||
| : engine_(engine), name(name), type(type), pedal(pedal), position(pos) {} | ||
|
|
||
| bool execute() override { | ||
| if (node_id == -1) { | ||
| node_id = engine_.graph().add_node(name, type, pedal); | ||
| auto* added_node = engine_.graph().find_node(node_id); | ||
| if (added_node) cached_node = *added_node; | ||
| } else { | ||
| // Re-adding the previously deleted/undone node | ||
| engine_.graph().restore_node(cached_node); | ||
| } | ||
| // Only write a fixed position when one was explicitly requested; | ||
| // if position is (0,0) the auto-placement logic in render_signal_chain | ||
| // will assign the correct cascading position on the next frame. | ||
| if (position.x != 0.0f || position.y != 0.0f) { | ||
| GuiGraphState::get_instance().node_positions[node_id] = { position, false, ImVec2(0, 0) }; | ||
| } | ||
| engine_.commit_graph_changes(); | ||
| return true; | ||
| } | ||
|
|
||
| void undo() override { | ||
| engine_.graph().remove_node(node_id); | ||
| GuiGraphState::get_instance().node_positions.erase(node_id); | ||
| engine_.commit_graph_changes(); | ||
| } | ||
|
|
||
| const char* description() const override { return "Add Node"; } | ||
| }; | ||
|
|
||
| struct RemoveGraphNodeCommand : public Command { | ||
| AudioEngine& engine_; | ||
| NodeId node_id; | ||
| EffectType type; | ||
| ImVec2 position; | ||
| std::vector<GraphLink> severed_links; // cache for undo | ||
| DSPNode cached_node; // full node data for exact restoration | ||
|
|
||
| RemoveGraphNodeCommand(AudioEngine& engine, NodeId id, EffectType t, ImVec2 pos) | ||
| : engine_(engine), node_id(id), type(t), position(pos) {} | ||
|
|
||
| bool execute() override { | ||
| auto* node_to_remove = engine_.graph().find_node(node_id); | ||
| if (node_to_remove) { | ||
| cached_node = *node_to_remove; | ||
| } | ||
|
|
||
| // Cache severed links before removal | ||
| severed_links.clear(); | ||
| for (const auto& link : engine_.graph().get_links()) { | ||
| if (std::find(cached_node.input_pin_ids.begin(), cached_node.input_pin_ids.end(), link.dest_pin_id) != cached_node.input_pin_ids.end() || | ||
| std::find(cached_node.output_pin_ids.begin(), cached_node.output_pin_ids.end(), link.source_pin_id) != cached_node.output_pin_ids.end()) { | ||
| severed_links.push_back(link); | ||
| } | ||
| } | ||
|
|
||
| engine_.graph().remove_node(node_id); | ||
| GuiGraphState::get_instance().node_positions.erase(node_id); | ||
| engine_.commit_graph_changes(); | ||
| return true; | ||
| } | ||
|
|
||
| void undo() override { | ||
| engine_.graph().restore_node(cached_node); | ||
| GuiGraphState::get_instance().node_positions[node_id] = { position, false, ImVec2(0, 0) }; | ||
|
|
||
| for (const auto& link : severed_links) { | ||
| engine_.graph().restore_link(link); | ||
| } | ||
| engine_.commit_graph_changes(); | ||
| } | ||
|
|
||
| const char* description() const override { return "Remove Node"; } | ||
| }; | ||
|
|
||
| struct AddGraphLinkCommand : public Command { | ||
| AudioEngine& engine_; | ||
| GraphLink link; | ||
| bool was_successful = false; | ||
|
|
||
| AddGraphLinkCommand(AudioEngine& engine, int src_pin, int dst_pin) | ||
| : engine_(engine) { | ||
| link.source_pin_id = src_pin; | ||
| link.dest_pin_id = dst_pin; | ||
| link.id = -1; // Unknown until execute | ||
| } | ||
|
|
||
| bool execute() override { | ||
| if (link.id == -1) { | ||
| link.id = engine_.graph().add_link(link.source_pin_id, link.dest_pin_id); | ||
| was_successful = (link.id != -1); | ||
| } else if (was_successful) { | ||
| engine_.graph().restore_link(link); | ||
| } | ||
| if (was_successful) { | ||
| engine_.commit_graph_changes(); | ||
| } | ||
| return was_successful; | ||
| } | ||
|
|
||
| void undo() override { | ||
| if (was_successful) { | ||
| engine_.graph().remove_link(link.id); | ||
| engine_.commit_graph_changes(); | ||
| } | ||
| } | ||
|
|
||
| const char* description() const override { return "Add Link"; } | ||
| }; | ||
|
|
||
| struct RemoveGraphLinkCommand : public Command { | ||
| AudioEngine& engine_; | ||
| GraphLink link; | ||
|
|
||
| RemoveGraphLinkCommand(AudioEngine& engine, const GraphLink& l) | ||
| : engine_(engine), link(l) {} | ||
|
|
||
| bool execute() override { | ||
| engine_.graph().remove_link(link.id); | ||
| engine_.commit_graph_changes(); | ||
| return true; | ||
| } | ||
|
|
||
| void undo() override { | ||
| engine_.graph().restore_link(link); | ||
| engine_.commit_graph_changes(); | ||
| } | ||
|
|
||
| const char* description() const override { return "Remove Link"; } | ||
| }; | ||
|
|
||
| struct MoveGraphNodeCommand : public Command { | ||
| NodeId node_id; | ||
| ImVec2 old_pos; | ||
| ImVec2 new_pos; | ||
|
|
||
| MoveGraphNodeCommand(NodeId id, ImVec2 old_pos, ImVec2 new_pos) | ||
| : node_id(id), old_pos(old_pos), new_pos(new_pos) {} | ||
|
|
||
| bool execute() override { | ||
| auto& positions = GuiGraphState::get_instance().node_positions; | ||
| if (positions.count(node_id)) { | ||
| positions[node_id].position = new_pos; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| void undo() override { | ||
| auto& positions = GuiGraphState::get_instance().node_positions; | ||
| if (positions.count(node_id)) { | ||
| positions[node_id].position = old_pos; | ||
| } | ||
| } | ||
|
|
||
| const char* description() const override { return "Move Node"; } | ||
| }; | ||
|
|
||
| } // namespace Amplitron |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.