/[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 2185 - (hide annotations) (download) (as text)
Sun Jun 19 09:09:38 2011 UTC (12 years, 10 months ago) by persson
File MIME type: text/x-c++hdr
File size: 4059 byte(s)
* fixed compilation with gcc 4.6.1
* another "make dist" fix, for LV2 plugin
* made --enable-pthread-testcancel default on Mac OS X
* Mac OS X: fixed hanging threads

1 schoenebeck 947 /***************************************************************************
2     * *
3     * Copyright (C) 2005, 2006 Christian Schoenebeck *
4     * *
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 947
34     namespace LinuxSampler {
35    
36     /** @brief Used by InstrumentManager for background tasks.
37     *
38     * This class is just an encapsulation of tasks that should be done by
39     * the InstrumentManager in the background, that is in a separate thread
40     * without blocking the calling thread. This class is thus not exported
41     * to the API.
42     */
43     class InstrumentManagerThread : public Thread {
44 iliev 1761 friend class EventHandler;
45    
46 schoenebeck 947 public:
47     InstrumentManagerThread();
48     void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel);
49     void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode);
50     virtual ~InstrumentManagerThread();
51 persson 2185 int StopThread();
52 schoenebeck 947 protected:
53     struct command_t {
54     enum cmd_type_t {
55     DIRECT_LOAD, ///< command was created by a StartNewLoad() call
56     INSTR_MODE ///< command was created by a StartSettingMode() call
57     } type;
58     EngineChannel* pEngineChannel; ///< only for DIRECT_LOAD commands
59     InstrumentManager* pManager; ///< only for INSTR_MODE commands
60     InstrumentManager::instrument_id_t instrumentId; ///< only for INSTR_MODE commands
61     InstrumentManager::mode_t mode; ///< only for INSTR_MODE commands
62     };
63    
64     // Instance variables.
65 schoenebeck 989 std::list<command_t> queue; ///< queue with commands for loading new instruments.
66     Mutex mutex; ///< for making the queue thread safe
67     Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives
68 schoenebeck 947
69     int Main(); ///< Implementation of virtual method from class Thread.
70 iliev 1761 private:
71     class EventHandler : public ChannelCountAdapter {
72     public:
73     InstrumentManagerThread* pThread;
74     virtual void ChannelToBeRemoved(SamplerChannel* pChannel);
75     };
76    
77     EventHandler eventHandler;
78 schoenebeck 947 };
79    
80     } // namespace LinuxSampler
81    
82     #endif // __LS_INSTRUMENTLOADER_H__

  ViewVC Help
Powered by ViewVC