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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1761 - (show annotations) (download) (as text)
Fri Aug 29 15:42:06 2008 UTC (15 years, 7 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 4029 byte(s)
* fixed a crash which occurs when removing a sampler channel waiting
  to start instrument loading after another channel

1 /***************************************************************************
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 #include "../common/Mutex.h"
28 #include "../Sampler.h"
29 #include "../EventListeners.h"
30 #include "InstrumentManager.h"
31
32 #include <list>
33
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 friend class EventHandler;
45
46 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 protected:
52 struct command_t {
53 enum cmd_type_t {
54 DIRECT_LOAD, ///< command was created by a StartNewLoad() call
55 INSTR_MODE ///< command was created by a StartSettingMode() call
56 } type;
57 EngineChannel* pEngineChannel; ///< only for DIRECT_LOAD commands
58 InstrumentManager* pManager; ///< only for INSTR_MODE commands
59 InstrumentManager::instrument_id_t instrumentId; ///< only for INSTR_MODE commands
60 InstrumentManager::mode_t mode; ///< only for INSTR_MODE commands
61 };
62
63 // Instance variables.
64 std::list<command_t> queue; ///< queue with commands for loading new instruments.
65 Mutex mutex; ///< for making the queue thread safe
66 Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives
67
68 int Main(); ///< Implementation of virtual method from class Thread.
69 private:
70 class EventHandler : public ChannelCountAdapter {
71 public:
72 InstrumentManagerThread* pThread;
73 virtual void ChannelToBeRemoved(SamplerChannel* pChannel);
74 };
75
76 EventHandler eventHandler;
77 };
78
79 } // namespace LinuxSampler
80
81 #endif // __LS_INSTRUMENTLOADER_H__

  ViewVC Help
Powered by ViewVC