summaryrefslogtreecommitdiff
path: root/windows/JackRouter/JackRouter.h
blob: c48d8d6932e54a587cd24b60e60b5a345976cb75 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 Copyright (C) 2006-2011 Grame

 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files
 (the "Software"), to deal in the Software without restriction,
 including without limitation the rights to use, copy, modify, merge,
 publish, distribute, sublicense, and/or sell copies of the Software,
 and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#ifndef _asiosmpl_
#define _asiosmpl_

#include "asiosys.h"

// Globals
static int	kBlockFrames = 256;
static int	kNumInputs = 4;
static int	kNumOutputs = 4;

#if WINDOWS

#include "jack.h"
#include "rpc.h"
#include "rpcndr.h"

#ifndef COM_NO_WINDOWS_H
#ifdef __MINGW32__
#include <winsock2.h>
#endif
#include <windows.h>
#include "ole2.h"
#endif

#include "combase.h"
#include "iasiodrv.h"

#define PATH_SEP "\\"

#include <list>
#include <string>

class JackRouter : public IASIO, public CUnknown
{
public:
	JackRouter(LPUNKNOWN pUnk, HRESULT *phr);
	~JackRouter();

	DECLARE_IUNKNOWN
    //STDMETHODIMP QueryInterface(REFIID riid, void **ppv) {      \
    //    return GetOwner()->QueryInterface(riid,ppv);            \
    //};                                                          \
    //STDMETHODIMP_(ULONG) AddRef() {                             \
    //    return GetOwner()->AddRef();                            \
    //};                                                          \
    //STDMETHODIMP_(ULONG) Release() {                            \
    //    return GetOwner()->Release();                           \
    //};

	// Factory method
	static CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr);
	// IUnknown
	virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid,void **ppvObject);
#else

#include "asiodrvr.h"

//---------------------------------------------------------------------------------------------
class JackRouter : public AsioDriver
{
public:
	JackRouter();
	~JackRouter();
#endif

	static int processCallback(jack_nframes_t nframes, void* arg);
    static void connectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
	static void shutdownCallback(void* arg);

	ASIOBool init(void* sysRef);
	void getDriverName(char *name);		// max 32 bytes incl. terminating zero
	long getDriverVersion();
	void getErrorMessage(char *string);	// max 128 bytes incl.

	ASIOError start();
	ASIOError stop();

	ASIOError getChannels(long *numInputChannels, long *numOutputChannels);
	ASIOError getLatencies(long *inputLatency, long *outputLatency);
	ASIOError getBufferSize(long *minSize, long *maxSize,
		long *preferredSize, long *granularity);

	ASIOError canSampleRate(ASIOSampleRate sampleRate);
	ASIOError getSampleRate(ASIOSampleRate *sampleRate);
	ASIOError setSampleRate(ASIOSampleRate sampleRate);
	ASIOError getClockSources(ASIOClockSource *clocks, long *numSources);
	ASIOError setClockSource(long index);

	ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp);
	ASIOError getChannelInfo(ASIOChannelInfo *info);

	ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
		long bufferSize, ASIOCallbacks *callbacks);
	ASIOError disposeBuffers();

	ASIOError controlPanel();
	ASIOError future(long selector, void *opt);
	ASIOError outputReady();

	void bufferSwitch();
	long getMilliSeconds() {return fMilliSeconds;}

	static std::list<std::pair<std::string, std::string> > fConnections;  // Connections list

private:

	void bufferSwitchX();

	double fSamplePosition;
	ASIOCallbacks* fCallbacks;
	ASIOTime fAsioTime;
	ASIOTimeStamp fTheSystemTime;

	void** fInputBuffers;
	void** fOutputBuffers;

	long* fInMap;
	long* fOutMap;

	long fInputLatency;
	long fOutputLatency;
	long fActiveInputs;
	long fActiveOutputs;
	long fToggle;
	long fMilliSeconds;
	bool fRunning;
	bool fFirstActivate;
    bool fFloatSample;
    bool fAliasSystem;
	bool fTimeInfoMode, fTcRead;
	char fErrorMessage[128];

	bool fAutoConnectIn;
	bool fAutoConnectOut;

	// Jack part
	jack_client_t* fClient;
	jack_port_t** fInputPorts;
	jack_port_t** fOutputPorts;
	long fBufferSize;
	ASIOSampleRate fSampleRate;

	void autoConnect();
	void saveConnections();
    void restoreConnections();
    
    void processInputs();
    void processOutputs();

};

#endif