hydrogen 1.2.6
NsmClient.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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 General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef NSM_CLIENT_H
24#define NSM_CLIENT_H
25
26#if defined(H2CORE_HAVE_OSC) || _DOXYGEN_
27
28#include <core/Object.h>
29#include <cassert>
30
31#include "core/Nsm.h"
32
33
57class NsmClient : public H2Core::Object<NsmClient>
58{
60 public:
69 ~NsmClient();
71 pthread_t m_NsmThread;
79 static void create_instance();
84 static NsmClient* get_instance() { assert(__instance); return __instance; }
85
96 void sendDirtyState( const bool isDirty );
119 void createInitialClient();
120
124 void shutdown();
125
130 static void loadDrumkit();
131
146 static void linkDrumkit( std::shared_ptr<H2Core::Song> pSong );
147
161 static int dereferenceDrumkit( std::shared_ptr<H2Core::Song> pSong );
162
173 static void replaceDrumkitPath( std::shared_ptr<H2Core::Song> pSong, const QString& sDrumkitPath );
174
183 static void printError( const QString& msg );
192 static void printMessage( const QString& msg );
193
195 bool getUnderSessionManagement() const;
196
197 QString getSessionFolderPath() const;
198 void setSessionFolderPath( const QString& sPath );
199
200 bool getIsNewSession() const;
201 void setIsNewSession( bool bNew );
202
203 private:
206 NsmClient();
207
212
221
229
236
280 static int OpenCallback( const char* name, const char* displayName,
281 const char* clientID, char** outMsg,
282 void* userData );
283
294 static int SaveCallback( char** outMsg, void* userData );
295
304 static void* ProcessEvent( void* data );
305
321 static void copyPreferences( const char* name );
322
328 static bool bNsmShutdown;
329};
330
334
335inline QString NsmClient::getSessionFolderPath() const {
337}
338inline void NsmClient::setSessionFolderPath( const QString& sPath ) {
339 m_sSessionFolderPath = sPath;
340}
341
342inline bool NsmClient::getIsNewSession() const {
343 return m_bIsNewSession;
344}
345inline void NsmClient::setIsNewSession( bool bNew ) {
346 m_bIsNewSession = bNew;
347}
348#endif /* H2CORE_HAVE_OSC */
349
350#endif // NSM_CLIENT_H
void * nsm_client_t
Definition Nsm.h:86
#define H2_OBJECT(name)
Definition Object.h:227
void setIsNewSession(bool bNew)
Definition NsmClient.h:345
void setSessionFolderPath(const QString &sPath)
Definition NsmClient.h:338
static int dereferenceDrumkit(std::shared_ptr< H2Core::Song > pSong)
Replaces a path in Song::m_sLastLoadedDrumkitPath pointing to the session folder with one pointing to...
~NsmClient()
Destructor.
Definition NsmClient.cpp:58
void sendDirtyState(const bool isDirty)
Informs the NSM server whether the current H2Core::Song is modified or not.
static int OpenCallback(const char *name, const char *displayName, const char *clientID, char **outMsg, void *userData)
Callback function for the NSM server to tell Hydrogen to open a H2Core::Song.
Definition NsmClient.cpp:70
static void printError(const QString &msg)
Custom function to print a colored error message.
static NsmClient * get_instance()
Definition NsmClient.h:84
static void loadDrumkit()
Checks whether there is a drumkit present in the session folder and loads it into the H2Core::SoundLi...
static NsmClient * __instance
Object holding the current NsmClient singleton.
Definition NsmClient.h:67
static void create_instance()
If __instance equals nullptr, a new NsmClient singleton will be created and stored in it.
Definition NsmClient.cpp:63
void shutdown()
Causes the NSM client to not process events anymore.
static void copyPreferences(const char *name)
Part of OpenCallback() responsible for copying and loading the preferences.
QString getSessionFolderPath() const
Definition NsmClient.h:335
nsm_client_t * m_pNsm
Stores the current instance of the NSM client.
Definition NsmClient.h:211
static void linkDrumkit(std::shared_ptr< H2Core::Song > pSong)
Responsible for linking a drumkit on user or system level into the session folder and updating all co...
bool getUnderSessionManagement() const
Definition NsmClient.h:331
bool getIsNewSession() const
Definition NsmClient.h:342
static void replaceDrumkitPath(std::shared_ptr< H2Core::Song > pSong, const QString &sDrumkitPath)
Replaces @H2Core::Song::m_sLastLoadedDrumkitPath as well as all @H2Core::Instrument::__drumkit_path b...
static bool bNsmShutdown
Indicates whether the NsmClient::NsmProcessEvent() function should continue processing events.
Definition NsmClient.h:328
void createInitialClient()
Actual setup, initialization, and registration of the NSM client.
static int SaveCallback(char **outMsg, void *userData)
Callback function for the NSM server to tell Hydrogen to save the current session.
static void printMessage(const QString &msg)
Custom function to print a colored message.
QString m_sSessionFolderPath
Folder all the content of the current session will be stored in.
Definition NsmClient.h:228
bool m_bIsNewSession
Indicates whether a song file was already found in the session folder and successfully loaded or the ...
Definition NsmClient.h:235
bool m_bUnderSessionManagement
To determine whether Hydrogen is under NON session management, it is not sufficient to check whether ...
Definition NsmClient.h:220
pthread_t m_NsmThread
Thread the NSM client will run in.
Definition NsmClient.h:71
NsmClient()
Private constructor to allow construction only via create_instance().
Definition NsmClient.cpp:49
static void * ProcessEvent(void *data)
Event handling function of the NSM client.