File: jackaudio.h

package info (click to toggle)
musescore2 2.3.2%2Bdfsg4-15
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 168,212 kB
  • sloc: cpp: 262,317; xml: 176,707; sh: 3,377; ansic: 1,384; python: 356; makefile: 227; perl: 82; pascal: 78
file content (95 lines) | stat: -rw-r--r-- 3,607 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//=============================================================================
//  MuseScore
//  Linux Music Score Editor
//  $Id: jackaudio.h 4147 2011-04-07 14:39:44Z wschweer $
//
//  Copyright (C) 2002-2009 Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#ifndef __JACKAUDIO_H__
#define __JACKAUDIO_H__

#include "config.h"
#include "driver.h"
#include <jack/jack.h>

namespace Ms {

class Synth;
class Seq;
class MidiDriver;

//---------------------------------------------------------
//   JackAudio
//---------------------------------------------------------

class JackAudio : public Driver {
      unsigned _segmentSize;
                              // We use fakeState if preferences.useJackTransport = false to emulate JACK Transport.
                              // ALSA, PortAudio do the same thing because of they don't have any transport.
                              // Also this implements fake transport when we have to temporarily disconnect from JACK Transport.
                              // It may be useful when playing count in to let JACK Transport wait before playing score.
      Transport fakeState;

      jack_client_t* client;
      char _jackName[8];

      bool timeSigTempoChanged;
      QList<jack_port_t*> ports;
      QList<jack_port_t*> midiOutputPorts;
      QList<jack_port_t*> midiInputPorts;

      static int processAudio(jack_nframes_t, void*);
      static void timebase (jack_transport_state_t, jack_nframes_t, jack_position_t*, int, void *);
      void hotPlug();
      void setTimebaseCallback();
      void releaseTimebaseCallback();
      void rememberAudioConnections();
      void restoreAudioConnections();
      void rememberMidiConnections();
      void restoreMidiConnections();
      QList<QString> inputPorts();
   public:
      JackAudio(Seq*);
      virtual ~JackAudio();
      virtual bool init(bool hot = false);
      virtual bool start(bool hotPlug = false);
      virtual bool stop();
      int framePos() const;
      void connect(void*, void*);
      void connect(const char* src, const char* dst);
      void disconnect(void* src, void* dst);
      virtual bool isRealtime() const   { return jack_is_realtime(client); }
      virtual void startTransport();
      virtual void stopTransport();
      virtual Transport getState() override;
      virtual void seekTransport(int);
      virtual int sampleRate() const    { return jack_get_sample_rate(client); }
      virtual void putEvent(const NPlayEvent&, unsigned framePos);
      virtual void midiRead();

      virtual void registerPort(const QString& name, bool input, bool midi);
      virtual void unregisterPort(jack_port_t*);
      virtual void handleTimeSigTempoChanged();
      virtual void checkTransportSeek(int, int, bool);
      virtual int bufferSize() {return _segmentSize;}
      void setBufferSize(int nframes) { _segmentSize = nframes;}
      void updateOutPortCount(int);
      };


} // namespace Ms
#endif