forked from rncbc/us428control
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cus428Midi.h
136 lines (122 loc) · 4.5 KB
/
Cus428Midi.h
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
/* -*- mode:C++; indent-tabs-mode:t; tab-width:8; c-basic-offset: 8 -*- */
/*
*
* Copyright (c) 2003 by Karsten Wiese <[email protected]>
* Copyright (c) 2004-2013 by Rui Nuno Capela <[email protected]>
*
* This program 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 2 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Cus428State.h"
// MMC Command Codes.
#define MMC_CMD_STOP 0x01
#define MMC_CMD_PLAY 0x02
#define MMC_CMD_DEFERRED_PLAY 0x03
#define MMC_CMD_FAST_FORWARD 0x04
#define MMC_CMD_REWIND 0x05
#define MMC_CMD_RECORD_STROBE 0x06
#define MMC_CMD_RECORD_EXIT 0x07
#define MMC_CMD_RECORD_PAUSE 0x08
#define MMC_CMD_PAUSE 0x09
#define MMC_CMD_EJECT 0x0a
#define MMC_CMD_CHASE 0x0b
#define MMC_CMD_COMMAND_ERROR_RESET 0x0c
#define MMC_CMD_MMC_RESET 0x0d
#define MMC_CMD_JOG_START 0x20
#define MMC_CMD_JOG_STOP 0x21
#define MMC_CMD_WRITE 0x40
#define MMC_CMD_MASKED_WRITE 0x41
#define MMC_CMD_READ 0x42
#define MMC_CMD_UPDATE 0x43
#define MMC_CMD_LOCATE 0x44
#define MMC_CMD_VARIABLE_PLAY 0x45
#define MMC_CMD_SEARCH 0x46
#define MMC_CMD_SHUTTLE 0x47
#define MMC_CMD_STEP 0x48
#define MMC_CMD_ASSIGN_SYSTEM_MASTER 0x49
#define MMC_CMD_GENERATOR_COMMAND 0x4a
#define MMC_CMD_MTC_COMMAND 0x4b
#define MMC_CMD_MOVE 0x4c
#define MMC_CMD_ADD 0x4d
#define MMC_CMD_SUBTRACT 0x4e
#define MMC_CMD_DROP_FRAME_ADJUST 0x4f
#define MMC_CMD_PROCEDURE 0x50
#define MMC_CMD_EVENT 0x51
#define MMC_CMD_GROUP 0x52
#define MMC_CMD_COMMAND_SEGMENT 0x53
#define MMC_CMD_DEFERRED_VARIABLE_PLAY 0x54
#define MMC_CMD_RECORD_STROBE_VARIABLE 0x55
#define MMC_CMD_WAIT 0x7c
#define MMC_CMD_RESUME 0x7f
// Available MMC Masked Write sub-commands (information fields).
#define MMC_CIF_TRACK_RECORD 0x4f
#define MMC_CIF_TRACK_MUTE 0x62
#define MMC_CIF_TRACK_SOLO 0x66 // Custom-implementation ;)
class Cus428Midi {
public:
Cus428Midi():
Seq(0){}
int CreatePorts(){
int Err;
if (0 <= (Err = snd_seq_open(&Seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK))) {
snd_seq_set_client_name(Seq, "US-428");
Err = snd_seq_create_simple_port(Seq, "Controls",
SND_SEQ_PORT_CAP_READ
|SND_SEQ_PORT_CAP_WRITE
|SND_SEQ_PORT_CAP_SUBS_READ
|SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_MIDI_GENERIC);
if (Err >= 0) {
Port = Err;
snd_seq_ev_clear(&Ev);
snd_seq_ev_set_direct(&Ev);
snd_seq_ev_set_source(&Ev, Port);
snd_seq_ev_set_subs(&Ev);
}
}
return Err;
}
int SendMidiControl(char Channel, char Param, char Val){
snd_seq_ev_set_controller(&Ev, Channel, Param, Val & 0x7F);
SubMitEvent();
return 0;
}
int SendMidiNote(char Channel, char Note, char Val){
if (!Val)
snd_seq_ev_set_noteoff(&Ev, Channel, Note, Val & 0x7F);
else
snd_seq_ev_set_noteon(&Ev, Channel, Note, Val & 0x7F);
SubMitEvent();
return 0;
}
int SendMidiControl(char Channel, Cus428State::eKnobs K, bool Down){
return SendMidiControl(Channel, KnobParam[K - Cus428State::eK_RECORD], Down ? 0x7F : 0);
}
// To parse and dispatch input MIDI events.
void ProcessMidiEvents();
// Send MMC command.
void SendMmcCommand(unsigned char MmcCmd, unsigned char *MmcData = 0, unsigned char MmcLen = 0);
// Made public for friendliness.
snd_seq_t *Seq;
private:
int Port;
snd_seq_event_t Ev;
int SubMitEvent(){
snd_seq_event_output(Seq, &Ev);
snd_seq_drain_output(Seq);
return 0;
}
static char KnobParam[];
};
extern Cus428Midi Midi;