Cleanup
[carla.git] / source / utils / CarlaExternalUI.hpp
blobc066cf4c9410cef21506de8852adbf94555d08f8
1 /*
2 * Carla External UI
3 * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_EXTERNAL_UI_HPP_INCLUDED
19 #define CARLA_EXTERNAL_UI_HPP_INCLUDED
21 #include "CarlaPipeUtils.hpp"
22 #include "CarlaString.hpp"
24 // -----------------------------------------------------------------------
26 class CarlaExternalUI : public CarlaPipeServer
28 public:
29 enum UiState {
30 UiNone = 0,
31 UiHide,
32 UiShow,
33 UiCrashed
36 CarlaExternalUI() noexcept
37 : fFilename(),
38 fArg1(),
39 fArg2(),
40 fUiState(UiNone) {}
42 ~CarlaExternalUI() /*noexcept*/ override
44 CARLA_SAFE_ASSERT_INT(fUiState == UiNone, fUiState);
47 UiState getAndResetUiState() noexcept
49 const UiState uiState(fUiState);
50 fUiState = UiNone;
51 return uiState;
54 void setData(const char* const filename, const char* const arg1, const char* const arg2) noexcept
56 fFilename = filename;
57 fArg1 = arg1;
58 fArg2 = arg2;
61 void setData(const char* const filename, const double sampleRate, const char* const uiTitle) noexcept
63 fFilename = filename;
64 fArg1 = CarlaString(sampleRate);
65 fArg2 = uiTitle;
68 bool startPipeServer(const bool show = true) noexcept
70 if (CarlaPipeServer::startPipeServer(fFilename, fArg1, fArg2))
72 if (show)
73 writeShowMessage();
74 return true;
77 return false;
80 protected:
81 // returns true if msg was handled
82 bool msgReceived(const char* const msg) noexcept override
84 if (std::strcmp(msg, "exiting") == 0)
86 closePipeServer();
87 fUiState = UiHide;
88 return true;
91 return false;
94 private:
95 CarlaString fFilename;
96 CarlaString fArg1;
97 CarlaString fArg2;
98 UiState fUiState;
100 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI)
103 // -----------------------------------------------------------------------
105 #endif // CARLA_EXTERNAL_UI_HPP_INCLUDED