/[svn]/linuxsampler/trunk/src/engines/InstrumentManagerThread.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/InstrumentManagerThread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4019 - (hide annotations) (download) (as text)
Mon Jan 3 17:45:26 2022 UTC (2 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4865 byte(s)
* SFZ engine: Automatically reload .sfz files on file changes
  (e.g. by some external text editor).

* Bumped version (2.2.0.svn14).

1 schoenebeck 947 /***************************************************************************
2     * *
3 schoenebeck 4019 * Copyright (C) 2005 - 2022 Christian Schoenebeck *
4 schoenebeck 947 * *
5     * This library is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This library 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. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this library; if not, write to the Free Software *
17     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18     * MA 02111-1307 USA *
19     ***************************************************************************/
20    
21     #ifndef __LS_INSTRUMENTLOADER_H__
22     #define __LS_INSTRUMENTLOADER_H__
23    
24     #include "../common/global.h"
25     #include "../common/Thread.h"
26     #include "../common/Condition.h"
27 schoenebeck 989 #include "../common/Mutex.h"
28 schoenebeck 947 #include "../Sampler.h"
29 iliev 1761 #include "../EventListeners.h"
30 schoenebeck 947 #include "InstrumentManager.h"
31    
32 schoenebeck 989 #include <list>
33 schoenebeck 4019 #include <functional>
34 schoenebeck 947
35     namespace LinuxSampler {
36    
37     /** @brief Used by InstrumentManager for background tasks.
38     *
39     * This class is just an encapsulation of tasks that should be done by
40     * the InstrumentManager in the background, that is in a separate thread
41     * without blocking the calling thread. This class is thus not exported
42     * to the API.
43     */
44     class InstrumentManagerThread : public Thread {
45 iliev 1761 friend class EventHandler;
46    
47 schoenebeck 947 public:
48     InstrumentManagerThread();
49     void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel);
50     void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode);
51 schoenebeck 4019 void AddPeriodicJob(String name, std::function<void()> fn);
52     void RemovePeriodicJob(String name);
53 schoenebeck 947 virtual ~InstrumentManagerThread();
54 persson 2351 #if (defined(__APPLE__) && !defined(__x86_64__)) || defined(WIN32)
55 persson 2185 int StopThread();
56 persson 2187 #endif
57 schoenebeck 947 protected:
58     struct command_t {
59     enum cmd_type_t {
60     DIRECT_LOAD, ///< command was created by a StartNewLoad() call
61     INSTR_MODE ///< command was created by a StartSettingMode() call
62     } type;
63     EngineChannel* pEngineChannel; ///< only for DIRECT_LOAD commands
64     InstrumentManager* pManager; ///< only for INSTR_MODE commands
65 persson 2277 InstrumentManager::instrument_id_t instrumentId; ///< for both DIRECT_LOAD and INSTR_MODE
66 schoenebeck 947 InstrumentManager::mode_t mode; ///< only for INSTR_MODE commands
67     };
68    
69 schoenebeck 4019 /// Custom job to be executed on behalf of external components.
70     struct ext_job_t {
71     String name; ///< unique name of the job
72     std::function<void()> fn; ///< The actual callback for the job to be executed.
73     };
74    
75 schoenebeck 947 // Instance variables.
76 schoenebeck 989 std::list<command_t> queue; ///< queue with commands for loading new instruments.
77     Mutex mutex; ///< for making the queue thread safe
78     Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives
79 schoenebeck 947
80 schoenebeck 4019 std::vector<ext_job_t> periodicJobs; ///< list of external tasks to be executed periodically
81     Mutex periodicJobsMutex; ///< for making access to periodicJobs thread safe
82    
83 schoenebeck 947 int Main(); ///< Implementation of virtual method from class Thread.
84 schoenebeck 4019 void RemovePeriodicJobWithoutLock(String name);
85     bool AnyPeriodicJobs();
86 iliev 1761 private:
87     class EventHandler : public ChannelCountAdapter {
88     public:
89     InstrumentManagerThread* pThread;
90     virtual void ChannelToBeRemoved(SamplerChannel* pChannel);
91     };
92    
93     EventHandler eventHandler;
94 schoenebeck 947 };
95    
96     } // namespace LinuxSampler
97    
98     #endif // __LS_INSTRUMENTLOADER_H__

  ViewVC Help
Powered by ViewVC