-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChannel.hpp
144 lines (119 loc) · 4.03 KB
/
Channel.hpp
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
/***********************************************************************
Copyright(C) 2014 Eiichi Takebuchi
TinyASIO is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
TinyASIO 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 TinyASIO.If not, see <http://www.gnu.org/licenses/>
***********************************************************************/
#pragma once
#include <string>
#include "Option.hpp"
#include "Exception.hpp"
#include "SDK.hpp"
#include "Driver.hpp"
namespace asio
{
/**
* チャンネル情報
*/
class Channel
{
public:
const bool isActive; //!< チャンネルが有効かどうか
const std::string name; //!< チャンネル名
const long channelNumber; //!< チャンネル番号
const ASIOSampleType sampleType; //!< サンプリングの種類
const long channelGroup; //!< チャンネルのグループ
const bool isInput;
public:
Channel(const ASIOChannelInfo& i)
:
isActive(i.isActive > 0),
name(i.name),
channelNumber(i.channel),
sampleType(ASIO_CURRENT_SAMPLE_TYPE), //sampleType(i.type),
channelGroup(i.channelGroup),
isInput(i.isInput > 0) { }
Channel operator=(const Channel& channel)
{
return channel;
}
};
/**
* 入力チャンネル
*/
class InputChannel : public Channel
{
public:
InputChannel(const ASIOChannelInfo& info)
: Channel(info) {}
};
/**
* 出力チャンネル
*/
class OutputChannel : public Channel
{
public:
OutputChannel(const ASIOChannelInfo& info)
: Channel(info) {}
};
/**
* 各種チャンネルの管理クラス
*/
class ChannelManager
{
std::vector<InputChannel> inputs;
std::vector<OutputChannel> outputs;
IASIO* iasio;
long numberOfChannels;
long numberOfInput; //!< 入力チャンネル数
long numberOfOutput; //!< 出力チャンネル数
std::shared_ptr<ASIOChannelInfo> inPtr; //!< 入力チャンネル情報
std::shared_ptr<ASIOChannelInfo> outPtr; //!< 出力チャンネル情報
private:
//!< あるチャンネルの初期化
void InitOneChannel(ASIOChannelInfo& info, const long i, const ASIOBool isInput)
{
// infoに与えられた初期値で取得するチャンネルを判断してる
info.isInput = isInput;
info.channel = i;
ErrorCheck(iasio->getChannelInfo(&info));
info.type = 18;
if (isInput == 1)
inputs.emplace_back(info);
else
outputs.emplace_back(info);
}
public:
ChannelManager(IASIO* iasio)
: iasio(iasio)
{
ErrorCheck(iasio->getChannels(&numberOfInput, &numberOfOutput));
if (numberOfInput <= 0)
throw DontFoundChannels("入力チャンネルが見つかりません");
if (numberOfOutput <= 0)
throw DontFoundChannels("出力チャンネルが見つかりません");
numberOfChannels = numberOfInput + numberOfOutput;
inPtr = std::shared_ptr<ASIOChannelInfo>(new ASIOChannelInfo[numberOfInput]);
outPtr = std::shared_ptr<ASIOChannelInfo>(new ASIOChannelInfo[numberOfOutput]);
for (long i = 0; i < numberOfInput; ++i)
InitOneChannel(inPtr.get()[i], i, 1);
for (long i = 0; i < numberOfOutput; ++i)
InitOneChannel(outPtr.get()[i], i, 0);
}
~ChannelManager() { }
const std::vector<InputChannel>& Inputs() const { return inputs; } //!< 入力チャンネルを返す
const std::vector<OutputChannel>& Outputs() const { return outputs; } //!< 出力チャンネルを返す
const InputChannel& Inputs(const long i) const { return inputs[i]; } //!< 添字iに対応した入力チャンネルを返す
const OutputChannel& Outputs(const long i) const { return outputs[i]; } //!< 添字iに対応して出力チャンネルを返す
const long NumberOfInputs() const { return numberOfInput; } //!< 入力チャンネル数
const long NumberOfOutputs() const { return numberOfOutput; } //!< 出力チャンネル数
const long NumberOfChannels() const { return numberOfChannels; } //!< チャンネル数
};
}