libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SCLang.hpp
Go to the documentation of this file.
1 #ifndef SCLANG_HPP
2 #define SCLANG_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <memory>
22 #include <set>
23 #include <type_traits>
24 
25 #include "OSC.hpp"
26 #include "Signal.hpp"
27 #include "LateReturn.hpp"
28 
29 namespace AlgAudio{
30 
31 class SCLangSubprocess;
32 class ModuleTemplate;
33 class SendReplyController;
34 
35 namespace Exceptions{
36 struct SCLang : public Exception{
37  SCLang(std::string t) : Exception(t) {}
38 };
39 } // namespace Exceptions
40 
45 class SCLang{
46  SCLang() = delete; // static class
47 public:
50  static void Start();
52  static void Restart();
54  static void Stop();
56  static bool IsRunning() { return subprocess != nullptr; }
62  static void PollSubprocess();
68  static void PollOSC();
83  static void SendInstruction(std::string instr);
85  static LateReturn<> InstallTemplate(const std::shared_ptr<ModuleTemplate> templ);
88  static bool WasInstalled(const std::string& id);
90  static void DebugQueryInstalled();
94  static void QueryAllNodes();
95 
98 
100 
101  static void SetOSCDebug(bool enabled);
102  static void SendOSC(const std::string& path);
103  static void SendOSC(const std::string& path, std::string tag, ...);
104  static void SendOSCCustom(const std::string& path, const lo::Message& m);
105  static LateReturn<lo::Message> SendOSCWithLOReply(const std::string& path);
106  static LateReturn<lo::Message> SendOSCWithLOReply(const std::string& path, std::string tag, ...);
107  static LateReturn<lo::Message> SendOSCCustomWithLOReply(const std::string& path, const lo::Message& m);
108  template <typename... Q, typename... Rest>
109  inline static LateReturn<Q...> SendOSCWithReply(const std::string& path, Rest... args);
110  template <typename... Q>
111  inline static LateReturn<Q...> SendOSCCustomWithReply(const std::string& path, const lo::Message& m);
112  // The above function cannot be partially speciallised... Thus we need to use another name for the case
113  // when Q = {}.
114  template <typename... Rest>
115  inline static LateReturn<> SendOSCWithEmptyReply(const std::string& path, Rest... args);
117 
121  static int RegisterSendReply(int synth_id, std::weak_ptr<SendReplyController>);
124  static void UnregisterSendReply(int synth_id, int reply_id);
125 
127  static void BootServer();
129  static void StopServer();
130 
132  static bool ready;
133 private:
134  static std::unique_ptr<SCLangSubprocess> subprocess;
135  static std::set<std::string> installed_templates;
136  static bool osc_debug;
137  static std::unique_ptr<OSC> osc;
138  static void SendReplyCatcher(int synth_id, int reply_id, float value);
139  static void ProcessMIDIInput(lo::Message);
140  static std::map<std::pair<int,int>, std::weak_ptr<SendReplyController>> sendreply_map;
141  static int sendreply_id;
142 };
143 
144 template <typename... T>
145 struct is_nonempty : std::true_type {};
146 template <>
147 struct is_nonempty<> : std::false_type {};
148 
149 template <typename... Q, typename... Rest>
150 inline LateReturn<Q...> SCLang::SendOSCWithReply(const std::string& path, Rest... args){
151  static_assert(is_nonempty<Q...>::value, "If you wish to use SendOSCWithReply with no return types, use SendOSCWithEmptyReply instead.");
152  Relay<Q...> r;
153  SendOSCWithLOReply(path,args...).Then([=](lo::Message msg){
154  r.Return( UnpackLOMessage<Q...>(msg,0) );
155  });
156  return r;
157 }
158 template <typename... Q>
159 inline LateReturn<Q...> SCLang::SendOSCCustomWithReply(const std::string& path, const lo::Message &m){
160  static_assert(is_nonempty<Q...>::value, "If you wish to use SendOSCWithReply with no return types, use SendOSCWithEmptyReply instead.");
161  Relay<Q...> r;
162  SendOSCCustomWithLOReply(path,m).Then([=](lo::Message msg){
163  r.Return( UnpackLOMessage<Q...>(msg,0) );
164  });
165  return r;
166 }
167 template <typename... Rest>
168 inline LateReturn<> SCLang::SendOSCWithEmptyReply(const std::string& path, Rest... args){
169  Relay<> r;
170  SendOSCWithLOReply(path,args...).Then([=](lo::Message){
171  r.Return();
172  });
173  return r;
174 }
175 
176 } // namespace AlgAudio
177 
178 #endif // SCLANG_HPP
static LateReturn InstallTemplate(const std::shared_ptr< ModuleTemplate > templ)
static Signal< bool, std::string > on_start_completed
Definition: SCLang.hpp:73
static void SetOSCDebug(bool enabled)
static Signal< std::string > on_line_received
Definition: SCLang.hpp:70
static void BootServer()
static void Restart()
static Signal< bool > on_server_started
Definition: SCLang.hpp:76
static void DebugQueryInstalled()
static void QueryAllNodes()
static void SendOSCCustom(const std::string &path, const lo::Message &m)
static LateReturn< Q...> SendOSCWithReply(const std::string &path, Rest...args)
Definition: SCLang.hpp:150
const Relay & Return(Types...args) const
Definition: LateReturn.hpp:437
static bool ready
Definition: SCLang.hpp:132
static LateReturn< lo::Message > SendOSCWithLOReply(const std::string &path)
static void PollOSC()
static void StopServer()
static LateReturn< lo::Message > SendOSCCustomWithLOReply(const std::string &path, const lo::Message &m)
static void Stop()
Definition: LateReturn.hpp:37
static void Start()
static void SendOSC(const std::string &path)
static bool WasInstalled(const std::string &id)
static LateReturn SendOSCWithEmptyReply(const std::string &path, Rest...args)
Definition: SCLang.hpp:168
static void PollSubprocess()
Definition: SCLang.hpp:45
static Signal< MidiMessage > on_midi_message_received
Definition: SCLang.hpp:97
static Signal< int, std::string > on_start_progress
Definition: SCLang.hpp:80
Definition: SCLang.hpp:145
Definition: SCLang.hpp:36
static int RegisterSendReply(int synth_id, std::weak_ptr< SendReplyController >)
SCLang(std::string t)
Definition: SCLang.hpp:37
Definition: Alertable.hpp:26
static bool IsRunning()
Definition: SCLang.hpp:56
Definition: LateReturn.hpp:35
static void UnregisterSendReply(int synth_id, int reply_id)
static void SendInstruction(std::string instr)
Definition: Exception.hpp:29
static LateReturn< Q...> SendOSCCustomWithReply(const std::string &path, const lo::Message &m)
Definition: SCLang.hpp:159