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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 970 - (hide annotations) (download)
Wed Dec 6 22:28:17 2006 UTC (17 years, 4 months ago) by schoenebeck
File size: 5227 byte(s)
* fixed crash occuring in conjunction with the new 'MAP MIDI_INSTRUMENT'
  LSCP command (cause: RingBuffer was not able to do deep copies)

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     #include "InstrumentManagerThread.h"
22    
23     namespace LinuxSampler {
24    
25     InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {
26 schoenebeck 970 pQueue = new RingBuffer<command_t,true>(INSTRUMENT_LOADER_QUEUE_SIZE);
27 schoenebeck 947 }
28    
29     InstrumentManagerThread::~InstrumentManagerThread() {
30     if (pQueue) delete pQueue;
31     }
32    
33     /**
34     * @brief Order loading of a new instrument.
35     *
36     * The request will go into a queue waiting to be processed by the
37     * class internal task thread. This method will immediately return and
38     * the instrument will be loaded in the background.
39     *
40     * @param Filename - file name of the instrument
41     * @param uiInstrumentIndex - index of the instrument within the file
42     * @param pEngineChannel - engine channel on which the instrument should be loaded
43     */
44     void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {
45     dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).",Filename.c_str(),uiInstrumentIndex));
46     // already tell the engine which instrument to load
47     pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex);
48    
49     command_t cmd;
50     cmd.type = command_t::DIRECT_LOAD;
51     cmd.pEngineChannel = pEngineChannel;
52     pQueue->push(&cmd);
53     StartThread(); // ensure thread is running
54     conditionJobsLeft.Set(true); // wake up thread
55     }
56    
57     /**
58     * @brief Order changing the life-time strategy of an instrument.
59     *
60     * The request will go into a queue waiting to be processed by the
61     * class internal task thread. This method will immediately return and
62     * in case the instrument has to be loaded due to a mode change to
63     * PERSISTENT, it will be loaded in the background.
64     *
65     * @param pManager - InstrumentManager which manages the instrument
66     * @param ID - unique ID of the instrument
67     * @param Mode - life-time strategy to set for this instrument
68     */
69     void InstrumentManagerThread::StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode) {
70     command_t cmd;
71     cmd.type = command_t::INSTR_MODE;
72     cmd.pManager = pManager;
73     cmd.instrumentId = ID;
74     cmd.mode = Mode;
75     pQueue->push(&cmd);
76     StartThread(); // ensure thread is running
77     conditionJobsLeft.Set(true); // wake up thread
78     }
79    
80     // Entry point for the task thread.
81     int InstrumentManagerThread::Main() {
82     while (true) {
83     while (pQueue->read_space()) {
84     command_t cmd;
85     pQueue->pop(&cmd);
86     try {
87     switch (cmd.type) {
88     case command_t::DIRECT_LOAD:
89     cmd.pEngineChannel->LoadInstrument();
90     break;
91     case command_t::INSTR_MODE:
92     cmd.pManager->SetMode(cmd.instrumentId, cmd.mode);
93     break;
94     default:
95     std::cerr << "InstrumentManagerThread: unknown command - BUG!\n" << std::flush;
96     }
97     }
98     catch (Exception e) {
99     e.PrintMessage();
100     }
101     }
102    
103     // nothing left to do, sleep until new jobs arrive
104     conditionJobsLeft.WaitIf(false);
105     // reset flag
106     conditionJobsLeft.Set(false);
107     // unlock condition object so it can be turned again by other thread
108     conditionJobsLeft.Unlock();
109     }
110     }
111    
112     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC