1 /*
2     MusicClient.h
3 
4     Copyright 2009-2011, Alan Calvert
5     Copyright 2009, James Morris
6     Copyright 2016-2019, Will Godfrey & others
7 
8     This file is part of yoshimi, which is free software: you can
9     redistribute it and/or modify it under the terms of the GNU General
10     Public License as published by the Free Software Foundation, either
11     version 2 of the License, or (at your option) any later version.
12 
13     yoshimi is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with yoshimi.  If not, see <http://www.gnu.org/licenses/>.
20 
21     Modified May 2019
22 */
23 
24 #ifndef MUSIC_CLIENT_H
25 #define MUSIC_CLIENT_H
26 
27 #include <string>
28 #include <pthread.h>
29 
30 #include "globals.h"
31 
32 enum audio_drivers { no_audio = 0, jack_audio, alsa_audio};
33 enum midi_drivers { no_midi = 0, jack_midi, alsa_midi};
34 
35 class SynthEngine;
36 class MusicIO;
37 class BeatTracker;
38 
39 struct music_clients
40 {
41     int order;
42     audio_drivers audioDrv;
43     midi_drivers midiDrv;
44     bool operator ==(const music_clients& other) const { return audioDrv == other.audioDrv && midiDrv == other.midiDrv; }
45     bool operator >(const music_clients& other) const { return (order > other.order) && (other != *this); }
46     bool operator <(const music_clients& other) const { return (order < other.order)  && (other != *this); }
47     bool operator !=(const music_clients& other) const { return audioDrv != other.audioDrv || midiDrv != other.midiDrv; }
48 };
49 
50 #define NMC_SRATE 44100
51 
52 class MusicClient
53 {
54 private:
55     SynthEngine *synth;
56     pthread_t timerThreadId;
57     static void *timerThread_fn(void*);
58     bool timerWorking;
59     float *buffersL [NUM_MIDI_PARTS + 1];
60     float *buffersR [NUM_MIDI_PARTS + 1];
61     audio_drivers audioDrv;
62     midi_drivers midiDrv;
63     MusicIO *audioIO;
64     MusicIO *midiIO;
65     BeatTracker *beatTracker;
66 public:
67     MusicClient(SynthEngine *_synth, audio_drivers _audioDrv, midi_drivers _midiDrv);
68     ~MusicClient();
69     bool Open(void);
70     bool Start(void);
71     void Close(void);
72     unsigned int getSamplerate(void);
73     int getBuffersize(void);
74     std::string audioClientName(void);
75     std::string midiClientName(void);
76     int audioClientId(void);
77     int midiClientId(void);
78     void registerAudioPort(int /*portnum*/);
79 
80     static MusicClient *newMusicClient(SynthEngine *_synth);
81 };
82 
83 #endif
84