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