reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

action.cpp (1519B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #include "action.hpp"
     19 
     20 #include <reaper_plugin_functions.h>
     21 
     22 Action::Action(const char *name, const char *desc, const Callback &callback)
     23   : m_name(name), m_reg{}, m_callback(callback)
     24 {
     25   m_reg.accel.cmd = plugin_register("command_id", const_cast<char *>(m_name));
     26   m_reg.desc = desc;
     27 
     28   plugin_register("gaccel", &m_reg);
     29 }
     30 
     31 Action::~Action()
     32 {
     33   plugin_register("-gaccel", &m_reg);
     34   plugin_register("-command_id", const_cast<char *>(m_name));
     35 }
     36 
     37 Action *ActionList::find(const Action::CommandID id) const
     38 {
     39   const auto it = m_list.find(id);
     40   return it != m_list.end() ? it->second.get() : nullptr;
     41 }
     42 
     43 bool ActionList::run(const Action::CommandID id) const
     44 {
     45   if(Action *action = find(id)) {
     46     action->run();
     47     return true;
     48   }
     49 
     50   return false;
     51 }