aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/machina/LearnRequest.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/machina/LearnRequest.hpp')
-rw-r--r--src/engine/machina/LearnRequest.hpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/engine/machina/LearnRequest.hpp b/src/engine/machina/LearnRequest.hpp
new file mode 100644
index 0000000..60f1b27
--- /dev/null
+++ b/src/engine/machina/LearnRequest.hpp
@@ -0,0 +1,81 @@
+/* This file is part of Machina.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Machina is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_LEARNREQUEST_HPP
+#define MACHINA_LEARNREQUEST_HPP
+
+#include <raul/Maid.h>
+#include <raul/SharedPtr.h>
+#include "types.hpp"
+#include "Node.hpp"
+#include "MidiAction.hpp"
+
+namespace Machina {
+
+class Node;
+class MidiAction;
+
+
+/** A request to MIDI learn a certain node.
+ */
+class LearnRequest : public Raul::Deletable {
+public:
+
+ static SharedPtr<LearnRequest>
+ create(SharedPtr<Raul::Maid> maid, SharedPtr<Node> node)
+ {
+ SharedPtr<LearnRequest> ret(new LearnRequest(maid, node));
+ maid->manage(ret);
+ return ret;
+ }
+
+ // Add the learned actions to the node
+ void finish(Timestamp time)
+ {
+ _node->add_enter_action(_enter_action);
+ _node->add_exit_action(_exit_action);
+ _node->set_duration(time - _start_time);
+ std::cerr << "LEARN DURATION: " << _node->duration() << std::endl;
+ }
+
+ void start(Timestamp time) { _started = true; _start_time = time; }
+ bool started() { return _started; }
+
+ const SharedPtr<Node>& node() { return _node; }
+ const SharedPtr<MidiAction>& enter_action() { return _enter_action; }
+ const SharedPtr<MidiAction>& exit_action() { return _exit_action; }
+
+private:
+ LearnRequest(SharedPtr<Raul::Maid> maid, SharedPtr<Node> node)
+ : _started(false)
+ , _node(node)
+ , _enter_action(MidiAction::create(maid, 4, NULL))
+ , _exit_action(MidiAction::create(maid, 4, NULL))
+ {
+ }
+
+ bool _started;
+ Timestamp _start_time;
+ SharedPtr<Node> _node;
+ SharedPtr<MidiAction> _enter_action;
+ SharedPtr<MidiAction> _exit_action;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_LEARNREQUEST_HPP