-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.hpp
129 lines (108 loc) · 2.96 KB
/
commands.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
/* Copyright (c) 2021 Martin Profittlich. All rights reserved. */
/* The file LICENSE contains more information about licensing. */
#pragma once
#include <string>
#include <sstream>
#include <vector>
#include "helpers.h"
///@todo: Display vs. View -> better naming
typedef enum { None, Select, Display, View, Copy, Store, Name, PatchMidiChannel, PatchMidiPC, PatchMidiCC, Input, Output, Loops } CommandType;
class Command
{
public:
class Parameter
{
public:
void setStr(std::string s)
{
if (onlyDigits(s))
{
m_isNumber = true;
m_str = s;
std::stringstream conv(s);
conv >> m_num;
}
else
{
m_isNumber = false;
m_str = s;
m_num = UINT_MAX;
}
}
void setNum(unsigned n)
{
m_isNumber = true;
m_num = n;
std::stringstream conv;
conv << m_num;
m_str = conv.str();
}
std::string str() const
{
return m_str;
}
unsigned num() const
{
if (!isNumber()) throw std::logic_error ("Not a number parameter");
return m_num;
}
bool isNumber () const
{
return m_isNumber;
}
private:
bool m_isNumber;
std::string m_str;
unsigned m_num;
};
Command (CommandType t, Parameter p1, Parameter p2)
{
clear();
m_command = t;
addParameter (p1);
addParameter (p2);
}
Command (CommandType t, Parameter p1)
{
clear();
m_command = t;
addParameter (p1);
}
Command (CommandType t)
{
clear();
m_command = t;
}
Command ()
{
clear();
}
void clear()
{
m_command = None;
m_params.clear();
}
CommandType command () const
{
return m_command;
}
void setCommand (CommandType c)
{
m_command = c;
}
Parameter parameter(size_t i) const
{
return m_params.at(i);
}
Parameter & parameter(size_t i)
{
return m_params.at(i);
}
void addParameter(Parameter p)
{
m_params.push_back (p);
}
private:
CommandType m_command;
std::vector<Parameter> m_params;
};