Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
driver.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#ifndef __ASE_DRIVER_HH__
3#define __ASE_DRIVER_HH__
4
5#include <ase/api.hh>
6#include <ase/midievent.hh>
7#include <functional>
8
9namespace Ase {
10
11ASE_CLASS_DECLS (Driver);
12ASE_CLASS_DECLS (MidiDriver);
13ASE_CLASS_DECLS (PcmDriver);
14
17 String devid;
18 String device_name;
19 String capabilities;
20 String device_info;
21 String notice;
22 String hints;
23 int32 priority = 0;
24 bool readonly = false;
25 bool writeonly = false;
26};
27
29class Driver : public std::enable_shared_from_this<Driver> {
30protected:
31 struct Flags { enum { OPENED = 1, READABLE = 2, WRITABLE = 4, }; };
32 const String driver_, devid_;
33 size_t flags_ = 0;
34 explicit Driver (const String &driver, const String &devid);
35 virtual ~Driver ();
36 template<class Derived> std::shared_ptr<Derived>
37 shared_from_base () { return std::static_pointer_cast<Derived> (shared_from_this()); }
38public:
39 enum {
40 // bonus bits
41 SURROUND = 0x08 << 24,
42 HEADSET = 0x04 << 24,
43 RECORDER = 0x02 << 24,
44 MIDI_THRU = 0x01 << 24,
45 // penalty bits
46 JACK = 0x1f << 24,
47 ALSA_USB = 0x2f << 24,
48 ALSA_KERN = 0x3f << 24,
49 OSS = 0x4f << 24,
50 PULSE = 0x5f << 24,
51 ALSA_USER = 0x6f << 24,
52 PSEUDO = 0x76 << 24,
53 PAUTO = 0x79 << 24,
54 PNULL = 0x7c << 24,
55 WCARD = 0x01 << 16,
56 WDEV = 0x01 << 8,
57 WSUB = 0x01 << 0,
58 };
59 enum IODir { READONLY = 1, WRITEONLY = 2, READWRITE = 3 };
60 typedef std::shared_ptr<Driver> DriverP;
61 bool opened () const { return flags_ & Flags::OPENED; }
62 bool readable () const { return flags_ & Flags::READABLE; }
63 bool writable () const { return flags_ & Flags::WRITABLE; }
64 String devid () const;
65 virtual void close () = 0;
66 static String priority_string (uint priority);
67 // registry
68 using Entry = DriverEntry;
69 using EntryVec = DriverEntryS;
70};
71using DriverP = Driver::DriverP;
72
74class MidiDriver : public Driver {
75protected:
76 explicit MidiDriver (const String &driver, const String &devid);
77 virtual Ase::Error open (IODir iodir) = 0;
78public:
80 static MidiDriverP open (const String &devid, IODir iodir, Ase::Error *ep);
81 virtual bool has_events () = 0;
82 virtual uint fetch_events (MidiEventOutput &estream, double samplerate) = 0;
83 static EntryVec list_drivers ();
84 static String register_driver (const String &driverid,
85 const std::function<MidiDriverP (const String&)> &create,
86 const std::function<void (EntryVec&)> &list);
87};
89
92 uint n_channels = 0;
93 uint mix_freq = 0;
94 uint block_length = 0;
95 uint latency_ms = 0;
96};
97
99class PcmDriver : public Driver {
100protected:
101 explicit PcmDriver (const String &driver, const String &devid);
102 virtual Ase::Error open (IODir iodir, const PcmDriverConfig &config) = 0;
103public:
105 static PcmDriverP open (const String &devid, IODir desired, IODir required, const PcmDriverConfig &config, Ase::Error *ep);
106 virtual uint pcm_n_channels () const = 0;
107 virtual uint pcm_mix_freq () const = 0;
108 virtual uint pcm_block_length () const = 0;
109 virtual void pcm_latency (uint *rlatency, uint *wlatency) const = 0;
110 virtual bool pcm_check_io (int64 *timeoutp) = 0;
111 virtual size_t pcm_read (size_t n, float *values) = 0;
112 virtual void pcm_write (size_t n, const float *values) = 0;
113 static EntryVec list_drivers ();
114 static String register_driver (const String &driverid,
115 const std::function<PcmDriverP (const String&)> &create,
116 const std::function<void (EntryVec&)> &list);
117};
119
120bool* register_driver_loader (const char *staticwhat, Error (*loader) ());
122
123} // Ase
124
125#endif // __ASE_DRIVER_HH__
Base class for a PCM and MIDI devices.
Definition driver.hh:29
static String priority_string(uint priority)
Return string which represents the given priority mask.
Definition driver.cc:31
String devid() const
Return a string which uniquely identifies this driver and device.
Definition driver.cc:24
Base class for a MIDI devices.
Definition driver.hh:74
A stream of writable MidiEvent structures.
Definition midievent.hh:96
Base class for a PCM devices.
Definition driver.hh:99
The Anklang C++ API namespace.
Definition api.hh:9
int32_t int32
A 32-bit signed integer.
Definition cxxaux.hh:28
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:29
Error
Enum representing Error states.
Definition api.hh:22
bool * register_driver_loader(const char *staticwhat, Error(*loader)())
Register loader callbacks at static constructor time.
Definition driver.cc:65
std::string String
Convenience alias for std::string.
Definition cxxaux.hh:35
uint32_t uint
Provide 'uint' as convenience type.
Definition cxxaux.hh:18
void load_registered_drivers()
Load all registered drivers.
Definition driver.cc:76
Driver information for PCM and MIDI handling.
Definition driver.hh:16
PCM device configuration.
Definition driver.hh:91