|
Packit Service |
b98cfc |
/* -*- mode:C++; indent-tabs-mode:t; tab-width:8; c-basic-offset: 8 -*- */
|
|
Packit Service |
b98cfc |
/*
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* Copyright (c) 2003 by Karsten Wiese <annabellesgarden@yahoo.de>
|
|
Packit Service |
b98cfc |
* Copyright (c) 2004-2007 by Rui Nuno Capela <rncbc@rncbc.org>
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
b98cfc |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
b98cfc |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
b98cfc |
* (at your option) any later version.
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b98cfc |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b98cfc |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b98cfc |
* GNU General Public License for more details.
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b98cfc |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b98cfc |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
b98cfc |
*/
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
#include "Cus428State.h"
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
// MMC Command Codes.
|
|
Packit Service |
b98cfc |
#define MMC_CMD_STOP 0x01
|
|
Packit Service |
b98cfc |
#define MMC_CMD_PLAY 0x02
|
|
Packit Service |
b98cfc |
#define MMC_CMD_DEFERRED_PLAY 0x03
|
|
Packit Service |
b98cfc |
#define MMC_CMD_FAST_FORWARD 0x04
|
|
Packit Service |
b98cfc |
#define MMC_CMD_REWIND 0x05
|
|
Packit Service |
b98cfc |
#define MMC_CMD_RECORD_STROBE 0x06
|
|
Packit Service |
b98cfc |
#define MMC_CMD_RECORD_EXIT 0x07
|
|
Packit Service |
b98cfc |
#define MMC_CMD_RECORD_PAUSE 0x08
|
|
Packit Service |
b98cfc |
#define MMC_CMD_PAUSE 0x09
|
|
Packit Service |
b98cfc |
#define MMC_CMD_EJECT 0x0a
|
|
Packit Service |
b98cfc |
#define MMC_CMD_CHASE 0x0b
|
|
Packit Service |
b98cfc |
#define MMC_CMD_COMMAND_ERROR_RESET 0x0c
|
|
Packit Service |
b98cfc |
#define MMC_CMD_MMC_RESET 0x0d
|
|
Packit Service |
b98cfc |
#define MMC_CMD_JOG_START 0x20
|
|
Packit Service |
b98cfc |
#define MMC_CMD_JOG_STOP 0x21
|
|
Packit Service |
b98cfc |
#define MMC_CMD_WRITE 0x40
|
|
Packit Service |
b98cfc |
#define MMC_CMD_MASKED_WRITE 0x41
|
|
Packit Service |
b98cfc |
#define MMC_CMD_READ 0x42
|
|
Packit Service |
b98cfc |
#define MMC_CMD_UPDATE 0x43
|
|
Packit Service |
b98cfc |
#define MMC_CMD_LOCATE 0x44
|
|
Packit Service |
b98cfc |
#define MMC_CMD_VARIABLE_PLAY 0x45
|
|
Packit Service |
b98cfc |
#define MMC_CMD_SEARCH 0x46
|
|
Packit Service |
b98cfc |
#define MMC_CMD_SHUTTLE 0x47
|
|
Packit Service |
b98cfc |
#define MMC_CMD_STEP 0x48
|
|
Packit Service |
b98cfc |
#define MMC_CMD_ASSIGN_SYSTEM_MASTER 0x49
|
|
Packit Service |
b98cfc |
#define MMC_CMD_GENERATOR_COMMAND 0x4a
|
|
Packit Service |
b98cfc |
#define MMC_CMD_MTC_COMMAND 0x4b
|
|
Packit Service |
b98cfc |
#define MMC_CMD_MOVE 0x4c
|
|
Packit Service |
b98cfc |
#define MMC_CMD_ADD 0x4d
|
|
Packit Service |
b98cfc |
#define MMC_CMD_SUBTRACT 0x4e
|
|
Packit Service |
b98cfc |
#define MMC_CMD_DROP_FRAME_ADJUST 0x4f
|
|
Packit Service |
b98cfc |
#define MMC_CMD_PROCEDURE 0x50
|
|
Packit Service |
b98cfc |
#define MMC_CMD_EVENT 0x51
|
|
Packit Service |
b98cfc |
#define MMC_CMD_GROUP 0x52
|
|
Packit Service |
b98cfc |
#define MMC_CMD_COMMAND_SEGMENT 0x53
|
|
Packit Service |
b98cfc |
#define MMC_CMD_DEFERRED_VARIABLE_PLAY 0x54
|
|
Packit Service |
b98cfc |
#define MMC_CMD_RECORD_STROBE_VARIABLE 0x55
|
|
Packit Service |
b98cfc |
#define MMC_CMD_WAIT 0x7c
|
|
Packit Service |
b98cfc |
#define MMC_CMD_RESUME 0x7f
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
// Available MMC Masked Write sub-commands (information fields).
|
|
Packit Service |
b98cfc |
#define MMC_CIF_TRACK_RECORD 0x4f
|
|
Packit Service |
b98cfc |
#define MMC_CIF_TRACK_MUTE 0x62
|
|
Packit Service |
b98cfc |
#define MMC_CIF_TRACK_SOLO 0x66 // Custom-implementation ;)
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
class Cus428Midi {
|
|
Packit Service |
b98cfc |
public:
|
|
Packit Service |
b98cfc |
Cus428Midi():
|
|
Packit Service |
b98cfc |
Seq(0){}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int CreatePorts(){
|
|
Packit Service |
b98cfc |
int Err;
|
|
Packit Service |
b98cfc |
if (0 <= (Err = snd_seq_open(&Seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK))) {
|
|
Packit Service |
b98cfc |
snd_seq_set_client_name(Seq, "US-428");
|
|
Packit Service |
b98cfc |
Err = snd_seq_create_simple_port(Seq, "Controls",
|
|
Packit Service |
b98cfc |
SND_SEQ_PORT_CAP_READ
|
|
Packit Service |
b98cfc |
|SND_SEQ_PORT_CAP_WRITE
|
|
Packit Service |
b98cfc |
|SND_SEQ_PORT_CAP_SUBS_READ
|
|
Packit Service |
b98cfc |
|SND_SEQ_PORT_CAP_SUBS_WRITE,
|
|
Packit Service |
b98cfc |
SND_SEQ_PORT_TYPE_MIDI_GENERIC);
|
|
Packit Service |
b98cfc |
if (Err >= 0) {
|
|
Packit Service |
b98cfc |
Port = Err;
|
|
Packit Service |
b98cfc |
snd_seq_ev_clear(&Ev;;
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_direct(&Ev;;
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_source(&Ev, Port);
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_subs(&Ev;;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
return Err;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int SendMidiControl(char Channel, char Param, char Val){
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_controller(&Ev, Channel, Param, Val & 0x7F);
|
|
Packit Service |
b98cfc |
SubMitEvent();
|
|
Packit Service |
b98cfc |
return 0;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int SendMidiNote(char Channel, char Note, char Val){
|
|
Packit Service |
b98cfc |
if (!Val)
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_noteoff(&Ev, Channel, Note, Val & 0x7F);
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
snd_seq_ev_set_noteon(&Ev, Channel, Note, Val & 0x7F);
|
|
Packit Service |
b98cfc |
SubMitEvent();
|
|
Packit Service |
b98cfc |
return 0;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int SendMidiControl(char Channel, Cus428State::eKnobs K, bool Down){
|
|
Packit Service |
b98cfc |
return SendMidiControl(Channel, KnobParam[K - Cus428State::eK_RECORD], Down ? 0x7F : 0);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
// To parse and dispatch input MIDI events.
|
|
Packit Service |
b98cfc |
void ProcessMidiEvents();
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
// Send MMC command.
|
|
Packit Service |
b98cfc |
void SendMmcCommand(unsigned char MmcCmd, unsigned char *MmcData = 0, unsigned char MmcLen = 0);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
// Made public for friendliness.
|
|
Packit Service |
b98cfc |
snd_seq_t *Seq;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
private:
|
|
Packit Service |
b98cfc |
int Port;
|
|
Packit Service |
b98cfc |
snd_seq_event_t Ev;
|
|
Packit Service |
b98cfc |
int SubMitEvent(){
|
|
Packit Service |
b98cfc |
snd_seq_event_output(Seq, &Ev;;
|
|
Packit Service |
b98cfc |
snd_seq_drain_output(Seq);
|
|
Packit Service |
b98cfc |
return 0;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
static char KnobParam[];
|
|
Packit Service |
b98cfc |
};
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
extern Cus428Midi Midi;
|