/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputDeviceAlsa.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInputDeviceAlsa.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3766 - (show annotations) (download) (as text)
Mon Apr 6 12:41:49 2020 UTC (4 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7013 byte(s)
Fixed deadlocks (e.g. when restarting engines).

* Individual thread implementations (e.g. disk thread, etc.):
  Disable thread cancellation on critical sections, e.g. when holding
  mutex locks, to prevent deadlocks if thread is stopped and/or
  restarted.

* Added TestCancel() calls to thread implementations if missing.

* No need to wrap Thread::TestCancel() calls into
  CONFIG_PTHREAD_TESTCANCEL macro conditions (since TestCancel() is
  already a stub on systems which don't have pthread_testcancel()
  available).

* If compiled for debugging: give each thread a human readable name
  to simplify debugging of multi-threading issues.

* DiskThreadBase: TestCancel() and pthread_testcancel() calls are
  per-se redundant, so only call TestCancel().

* Added missing override keywords to silent compiler warnings.

* Bumped version (2.1.1.svn54).

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2020 Christian Schoenebeck *
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, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __LS_MIDIINPUTDEVICEALSA_H__
25 #define __LS_MIDIINPUTDEVICEALSA_H__
26
27 #include <alsa/asoundlib.h>
28
29 #include "../../common/global_private.h"
30 #include "../../common/Thread.h"
31 #include "MidiInputDevice.h"
32
33 namespace LinuxSampler {
34
35 /** ALSA MIDI input driver
36 *
37 * Implements MIDI input for the Advanced Linux Sound Architecture
38 * (ALSA).
39 */
40 class MidiInputDeviceAlsa : public MidiInputDevice, public Thread {
41 public:
42
43 /**
44 * MIDI Port implementation for the ALSA MIDI input driver.
45 */
46 class MidiInputPortAlsa : public MidiInputPort {
47 public:
48 /** MIDI Port Parameter 'NAME'
49 *
50 * Used to assign an arbitrary name to the MIDI port.
51 */
52 class ParameterName : public MidiInputPort::ParameterName {
53 public:
54 ParameterName(MidiInputPort* pPort) throw (Exception);
55 virtual void OnSetValue(String s) throw (Exception) OVERRIDE;
56 };
57
58 /** MIDI Port Parameter 'ALSA_SEQ_BINDINGS'
59 *
60 * Used to connect to other Alsa sequencer clients.
61 */
62 class ParameterAlsaSeqBindings : public DeviceRuntimeParameterStrings {
63 public:
64 ParameterAlsaSeqBindings(MidiInputPortAlsa* pPort);
65 virtual String Description() OVERRIDE;
66 virtual bool Fix() OVERRIDE;
67 virtual std::vector<String> PossibilitiesAsString() OVERRIDE;
68 virtual void OnSetValue(std::vector<String> vS) throw (Exception) OVERRIDE;
69 protected:
70 MidiInputPortAlsa* pPort;
71 };
72
73 /** MIDI Port Parameter 'ALSA_SEQ_ID'
74 *
75 * Reflects the ALSA sequencer ID of this MIDI port,
76 * e.g. "128:0".
77 */
78 class ParameterAlsaSeqId : public DeviceRuntimeParameterString {
79 public:
80 ParameterAlsaSeqId(MidiInputPortAlsa* pPort);
81 virtual String Description() OVERRIDE;
82 virtual bool Fix() OVERRIDE;
83 virtual std::vector<String> PossibilitiesAsString() OVERRIDE;
84 virtual void OnSetValue(String s) OVERRIDE;
85 };
86
87 void ConnectToAlsaMidiSource(const char* MidiSource);
88 protected:
89 std::vector<snd_seq_port_subscribe_t*> subscriptions;
90
91 MidiInputPortAlsa(MidiInputDeviceAlsa* pDevice) throw (MidiInputException);
92 ~MidiInputPortAlsa();
93 friend class MidiInputDeviceAlsa;
94 private:
95 MidiInputDeviceAlsa* pDevice;
96
97 friend class ParameterName;
98 friend class ParameterAlsaSeqBindings;
99 void UnsubscribeAll();
100 };
101
102 /** MIDI Device Parameter 'NAME'
103 *
104 * Used to assign an arbitrary name to the ALSA client of this
105 * MIDI device.
106 */
107 class ParameterName : public DeviceCreationParameterString {
108 public:
109 ParameterName();
110 ParameterName(String s);
111 virtual String Description() OVERRIDE;
112 virtual bool Fix() OVERRIDE;
113 virtual bool Mandatory() OVERRIDE;
114 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() OVERRIDE;
115 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) OVERRIDE;
116 virtual optional<String> DefaultAsString(std::map<String,String> Parameters) OVERRIDE;
117 virtual void OnSetValue(String s) throw (Exception) OVERRIDE;
118 static String Name();
119 };
120
121 MidiInputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler);
122 ~MidiInputDeviceAlsa();
123
124 // derived abstract methods from class 'MidiInputDevice'
125 void Listen() OVERRIDE;
126 void StopListen() OVERRIDE;
127 virtual String Driver() OVERRIDE;
128 static String Name();
129 static String Description();
130 static String Version();
131
132 MidiInputPortAlsa* CreateMidiPort() OVERRIDE;
133 protected:
134 int Main() OVERRIDE; ///< Implementation of virtual method from class Thread
135 private:
136 snd_seq_t* hAlsaSeq;
137 int hAlsaSeqClient; ///< Alsa Sequencer client ID
138
139 friend class MidiInputPortAlsa;
140 friend class MidiInputPortAlsa::ParameterName;
141 friend class MidiInputPortAlsa::ParameterAlsaSeqBindings;
142 };
143 }
144
145 #endif // __LS_MIDIINPUTDEVICEALSA_H__

  ViewVC Help
Powered by ViewVC