summaryrefslogtreecommitdiff
path: root/common/JackPort.h
blob: f7a601ed37abc407877cf83c12e631d30e5852cd (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#ifndef __JackPort__
#define __JackPort__

#include "types.h"
#include "JackConstants.h"
#include "JackCompilerDeps.h"

namespace Jack
{

#define ALL_PORTS	0xFFFF
#define NO_PORT		0xFFFE

/*!
\brief Base class for port.
*/

PRE_PACKED_STRUCTURE
class SERVER_EXPORT JackPort
{

        friend class JackGraphManager;

    private:

        int fTypeId;
        enum JackPortFlags fFlags;
        char fName[REAL_JACK_PORT_NAME_SIZE];
        char fAlias1[REAL_JACK_PORT_NAME_SIZE];
        char fAlias2[REAL_JACK_PORT_NAME_SIZE];
        int fRefNum;

        jack_nframes_t fLatency;
        jack_nframes_t fTotalLatency;
        jack_latency_range_t  fPlaybackLatency;
        jack_latency_range_t  fCaptureLatency;
        uint8_t fMonitorRequests;

        bool fInUse;
        jack_port_id_t fTied;   // Locally tied source port
        jack_default_audio_sample_t fBuffer[BUFFER_SIZE_MAX + 8];

        bool IsUsed() const
        {
            return fInUse;
        }

        // RT
        void ClearBuffer(jack_nframes_t frames);
        void MixBuffers(void** src_buffers, int src_count, jack_nframes_t frames);

    public:

        JackPort();

        bool Allocate(int refnum, const char* port_name, const char* port_type, JackPortFlags flags);
        void Release();
        const char* GetName() const;
        const char* GetShortName() const;
        void SetName(const char* name);

        int GetAliases(char* const aliases[2]);
        int SetAlias(const char* alias);
        int UnsetAlias(const char* alias);
        bool NameEquals(const char* target);

        int	GetFlags() const;
        const char* GetType() const;

        int Tie(jack_port_id_t port_index);
        int UnTie();

        jack_nframes_t GetLatency() const;
        void SetLatency(jack_nframes_t latency);

        void SetLatencyRange(jack_latency_callback_mode_t mode, jack_latency_range_t* range);
        void GetLatencyRange(jack_latency_callback_mode_t mode, jack_latency_range_t* range) const;

        jack_nframes_t GetTotalLatency() const;

        int RequestMonitor(bool onoff);
        int EnsureMonitor(bool onoff);
        bool MonitoringInput()
        {
            return (fMonitorRequests > 0);
        }

        // Since we are in shared memory, the resulting pointer cannot be cached, so align it here...
        jack_default_audio_sample_t* GetBuffer()
        {
            return (jack_default_audio_sample_t*)((uintptr_t)fBuffer & ~31L) + 8;
        }

        int GetRefNum() const;

} POST_PACKED_STRUCTURE;

} // end of namespace


#endif