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

Annotation of /linuxsampler/trunk/src/drivers/midi/VirtualMidiDevice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1663 - (hide annotations) (download) (as text)
Mon Feb 4 00:38:08 2008 UTC (16 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4561 byte(s)
* provide velocity information to instrument
  editors now as well

1 schoenebeck 1659 /*
2     Copyright (C) 2008 Christian Schoenebeck
3     */
4    
5     #ifndef LS_VIRTUALMIDIDEVICE_H
6     #define LS_VIRTUALMIDIDEVICE_H
7    
8     #include "../../common/global.h"
9    
10     namespace LinuxSampler {
11    
12     /**
13     * Light-weight MIDI interface (for MIDI in & out) intended to be used by
14     * pure software MIDI "devices", that is e.g. a graphical virtual MIDI
15     * keyboard in an instrument editor or in a sampler frontend. This class
16     * should not be used for regular MIDI input device drivers for the sampler.
17     * This primitive interface by design doesn't care about jitter, fast event
18     * delivery or masses and masses of events in a short time!
19     */
20     class VirtualMidiDevice {
21     public:
22     enum event_type_t {
23     EVENT_TYPE_NOTEON = 1,
24     EVENT_TYPE_NOTEOFF = 2
25     };
26    
27     struct event_t {
28     event_type_t Type;
29     uint8_t Key;
30     uint8_t Velocity;
31     };
32    
33     /////////////////////////////////////////////////////////////////
34     // Device methods
35     // (called by the VirtualMidiDevice implementation)
36    
37     /**
38     * Sends a MIDI @e note @e on event to the sampler.
39     *
40     * @returns true on success, false if internal FIFO full
41     * (or provided values invalid)
42     */
43     bool SendNoteOnToSampler(uint8_t Key, uint8_t Velocity);
44    
45     /**
46     * Sends a MIDI @e note @e off event to the sampler.
47     *
48     * @returns true on success, false if internal FIFO full
49     * (or provided values invalid)
50     */
51     bool SendNoteOffToSampler(uint8_t Key, uint8_t Velocity);
52    
53     /**
54     * Can be called by the virtual MIDI device to check whether a new note
55     * on or note off MIDI event arrived to the sampler during the last
56     * call to this method. So this is a asynchronously, "polling" based
57     * communication mechanism, which works in conjunction with the
58     * NoteIsActive() method call.
59     */
60     bool NotesChanged();
61    
62     /**
63     * Can be called by the virtual MIDI device to check whether a new note
64     * on or note off MIDI event arrived to the sampler for @a Key during
65     * the last call to this method. So this is a asynchronously,
66     * "polling" based communication mechanism, which works in
67     * conjunction with the NoteIsActive() method call.
68     */
69     bool NoteChanged(uint8_t Key);
70    
71     /**
72     * Can be called by the virtual MIDI device to check which key / note
73     * is currently active by the sampler, e.g. to highlight the
74     * respective keys on a graphical virtual keyboard.
75     *
76     * @see NotesChanged(), NoteChanged()
77     */
78     bool NoteIsActive(uint8_t Key);
79    
80 schoenebeck 1663 /**
81     * Returns the velocity of the @e last note on event. No FIFO is used!
82     */
83     uint8_t NoteOnVelocity(uint8_t Key);
84    
85     /**
86     * Returns the velocity of the @e last note off event. No FIFO is used!
87     */
88     uint8_t NoteOffVelocity(uint8_t Key);
89    
90 schoenebeck 1659 /////////////////////////////////////////////////////////////////
91     // Sampler methods
92     // (usually only called by the Sampler)
93    
94     /**
95     * Informs the virtual MIDI device that a @e note @e on event occured
96     * (e.g. caused by a MIDI keyboard connected to the sampler).
97     * Communication acts asynchronously, that is this method call doesn't
98     * lock in any way and returns immediately. It is thus realtime safe.
99     *
100     * @e Note: this method is usually only called by the sampler.
101     *
102     * @see ActiveNotesChanged(), NoteIsActive()
103     */
104     void SendNoteOnToDevice(uint8_t Key, uint8_t Velocity);
105    
106     /**
107     * Informs the virtual MIDI device that a @e note @e off event occured
108     * (e.g. caused by a MIDI keyboard connected to the sampler).
109     * Communication acts asynchronously, that is this method call doesn't
110     * lock in any way and returns immediately. It is thus realtime safe.
111     *
112     * @e Note: this method is usually only called by the sampler.
113     *
114     * @see ActiveNotesChanged(), NoteIsActive()
115     */
116     void SendNoteOffToDevice(uint8_t Key, uint8_t Velocity);
117    
118     /**
119     * Gets the next pending MIDI event from the virtual MIDI device by
120     * using a lockfree FIFO.
121     *
122     * @e Note: this method is usually only called by the sampler.
123     *
124     * @param Event - destination for writing the next event to
125     * @returns true on success, false if no event pending
126     */
127     bool GetMidiEventFromDevice(event_t& Event);
128    
129     /**
130     * Constructor
131     */
132     VirtualMidiDevice();
133    
134     /**
135     * Destructor
136     */
137     virtual ~VirtualMidiDevice();
138    
139     private:
140     void* pPrivateData;
141     };
142    
143     } // namespace LinuxSampler
144    
145     #endif // LS_VIRTUALMIDIDEVICE_H

  ViewVC Help
Powered by ViewVC