import_soundtrack.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* import_soundtrack.cpp - import soundtrack action
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <core/node_info/node_info.h>
  18. #include <core/node/make.h>
  19. #include <core/action_stack.h>
  20. #include <core/actions/change_link.h>
  21. #include <generic/process_node.h>
  22. #include "import.h"
  23. namespace rainynite::studio {
  24. struct ImportSoundTag {};
  25. using ImportSoundProcessor = ProcessNode<string, ImportSoundTag>;
  26. class SetSoundtrack : public ImportSoundProcessor {
  27. public:
  28. bool accept(core::NodeTreeIndex node) const override {
  29. auto tree = get_context()->tree();
  30. return node_name(*tree->get_node(node)) == "AudioFromFile";
  31. }
  32. void feed(string const& s) override {
  33. auto string_node = core::make_value<string>(std::move(s));
  34. auto ctx = get_context();
  35. ctx->action_stack()->emplace<core::actions::SetProperty>(ctx->tree(), get_node_index(), "file_path", string_node);
  36. }
  37. };
  38. REGISTER_PROCESS_NODE(SetSoundtrack, ImportSoundProcessor)
  39. namespace actions {
  40. /**
  41. * Import file paths as Image layers
  42. */
  43. class ImportSoundtrack :
  44. public ImportFiles<ImportSoundProcessor>,
  45. REGISTERED_ACTION(ImportSoundtrack)
  46. {
  47. ACTION_NAME("Import soundtrack")
  48. };
  49. } // namespace actions
  50. } // namespace rainynite::studio