1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 See the AUTHORS file for more details. 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. See the file 13 COPYING included with this distribution for more information. 14 */ 15 16 #ifndef RG_DEVICE_H 17 #define RG_DEVICE_H 18 19 #include "XmlExportable.h" 20 #include "Instrument.h" 21 #include <string> 22 #include <vector> 23 24 // A Device can query underlying hardware/sound APIs to 25 // generate a list of Instruments. 26 // 27 28 namespace Rosegarden 29 { 30 31 typedef unsigned int DeviceId; 32 33 class Instrument; 34 typedef std::vector<Instrument *> InstrumentList; 35 class Controllable; 36 class AllocateChannels; 37 38 class Device : public XmlExportable 39 { 40 public: 41 typedef enum 42 { 43 Midi, 44 Audio, 45 SoftSynth 46 } DeviceType; 47 48 // special device ids 49 static const DeviceId NO_DEVICE; 50 static const DeviceId ALL_DEVICES; 51 // The "external controller" ALSA port that we create. 52 static const DeviceId EXTERNAL_CONTROLLER; 53 Device(DeviceId id,const std::string & name,DeviceType type)54 Device(DeviceId id, const std::string &name, DeviceType type): 55 m_name(name), m_type(type), m_id(id) { } 56 57 ~Device() override; 58 59 /** 60 * Return a Controllable if we are a subtype that also inherits 61 * from Controllable, otherwise return nullptr 62 **/ 63 Controllable *getControllable(); 64 65 /** 66 * Return our AllocateChannels if we are a subtype that tracks 67 * free channels, otherwise return nullptr 68 **/ 69 virtual AllocateChannels *getAllocator(); 70 setType(DeviceType type)71 void setType(DeviceType type) { m_type = type; } getType()72 DeviceType getType() const { return m_type; } 73 setName(const std::string & name)74 void setName(const std::string &name) { m_name = name; renameInstruments(); } getName()75 std::string getName() const { return m_name; } 76 setId(DeviceId id)77 void setId(DeviceId id) { m_id = id; } getId()78 DeviceId getId() const { return m_id; } 79 80 virtual bool isInput() const = 0; 81 virtual bool isOutput() const = 0; 82 83 // Accessing instrument lists - Devices should only 84 // show the world what they want it to see 85 // 86 // Two functions - one to return all Instruments on a 87 // Device - one to return all Instruments that a user 88 // is allowed to select (Presentation Instruments). 89 // 90 virtual InstrumentList getAllInstruments() const = 0; 91 virtual InstrumentList getPresentationInstruments() const = 0; 92 93 /// Send channel setups to each instrument in the device. 94 /** 95 * This is mainly a MidiDevice thing. Not sure if we should push it down. 96 */ 97 void sendChannelSetups(); 98 99 protected: 100 virtual void addInstrument(Instrument *) = 0; 101 virtual void renameInstruments() = 0; 102 103 InstrumentList m_instruments; 104 std::string m_name; 105 DeviceType m_type; 106 DeviceId m_id; 107 }; 108 109 } 110 111 #endif // RG_DEVICE_H 112