1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 /* 3 Rosegarden 4 A sequencer and musical notation editor. 5 Copyright 2000-2021 the Rosegarden development team. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. See the file 11 COPYING included with this distribution for more information. 12 */ 13 14 #include <vector> 15 #include <set> 16 17 #include <QSharedPointer> 18 19 #include "base/Instrument.h" 20 #include "MappedCommon.h" 21 22 #ifndef RG_ALSAPORT_H 23 #define RG_ALSAPORT_H 24 25 #ifdef HAVE_ALSA 26 #include <alsa/asoundlib.h> // ALSA 27 28 namespace Rosegarden 29 { 30 31 32 struct ClientPortPair 33 { ClientPortPairClientPortPair34 ClientPortPair() : 35 client(0), 36 port(0) 37 { } 38 ClientPortPairClientPortPair39 ClientPortPair(int i_client, int i_port) : 40 client(i_client), 41 port(i_port) 42 { } 43 44 int client; 45 int port; 46 47 bool operator==(const ClientPortPair &rhs) const 48 { 49 return (client == rhs.client && port == rhs.port); 50 } 51 52 bool operator!=(const ClientPortPair &rhs) const 53 { 54 return (client != rhs.client || port != rhs.port); 55 } 56 }; 57 58 /** 59 * Use this to hold all client information so that we can sort it 60 * before generating devices - we want to put non-duplex devices 61 * at the front of any device list (makes thing much easier at the 62 * GUI and we already have some backwards compatibility issues with 63 * this). 64 */ 65 class AlsaPortDescription 66 { 67 public: 68 AlsaPortDescription(Instrument::InstrumentType type, 69 const std::string &name, 70 int client, 71 int port, 72 unsigned int clientType, 73 unsigned int portType, 74 unsigned int capability, 75 PortDirection direction); 76 77 Instrument::InstrumentType m_type; 78 std::string m_name; 79 int m_client; 80 int m_port; 81 unsigned int m_clientType; 82 unsigned int m_portType; 83 unsigned int m_capability; 84 PortDirection m_direction; // or can deduce from capability 85 isReadable()86 bool isReadable() { return m_direction == ReadOnly || 87 m_direction == Duplex; } 88 isWriteable()89 bool isWriteable() { return m_direction == WriteOnly || 90 m_direction == Duplex; } 91 92 }; 93 94 /// Sort by checking direction 95 struct AlsaPortCmp 96 { 97 bool operator()(QSharedPointer<AlsaPortDescription> a1, 98 QSharedPointer<AlsaPortDescription> a2); 99 }; 100 101 102 } 103 104 #endif // HAVE_ALSA 105 106 #endif // RG_ALSAPORT_H 107 108