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
|
//Copyright (c) 2002-2003 Nasca Octavian Paul
//License: GNU GPL 2
#include "Spliter.h"
#include <stdio.h>
pthread_mutex_t mutex;
int Pexitprogram;
Spliter::Spliter() {
//init
Psplitpoint = 60;
Pchin = 0;
Pchout1 = 0;
Pchout2 = 1;
Poct1 = 0;
Poct2 = 0;
//ALSA init
snd_seq_open(&midi_in, "default", SND_SEQ_OPEN_INPUT, 0);
snd_seq_open(&midi_out, "default", SND_SEQ_OPEN_OUTPUT, 0);
char portname[50]; sprintf(portname, "Spliter IN");
snd_seq_create_simple_port(
midi_in,
portname,
SND_SEQ_PORT_CAP_WRITE
| SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_SYNTH);
sprintf(portname, "Spliter OUT");
snd_seq_create_simple_port(
midi_out,
portname,
SND_SEQ_PORT_CAP_READ
| SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_SYNTH);
}
Spliter::~Spliter() {
snd_seq_close(midi_in);
snd_seq_close(midi_out);
}
// This splits the Midi events from one channel to another two channels
void Spliter::midievents() {
snd_seq_event_t *midievent;
midievent = NULL;
snd_seq_event_input(midi_in, &midievent);
if(midievent == NULL)
return;
if((midievent->type == SND_SEQ_EVENT_NOTEON)
|| (midievent->type == SND_SEQ_EVENT_NOTEOFF)) {
int cmdchan = midievent->data.note.channel;
if(cmdchan == Pchin) {
snd_seq_ev_set_subs(midievent);
snd_seq_ev_set_direct(midievent);
if(midievent->data.note.note < Psplitpoint) {
midievent->data.note.channel = Pchout1;
int tmp = midievent->data.note.note;
tmp += Poct1 * 12; if(tmp > 127)
tmp = 127; if(tmp < 0)
tmp = 0;
midievent->data.note.note = tmp;
}
else {
midievent->data.note.channel = Pchout2;
int tmp = midievent->data.note.note;
tmp += Poct2 * 12; if(tmp > 127)
tmp = 127; if(tmp < 0)
tmp = 0;
midievent->data.note.note = tmp;
}
snd_seq_event_output_direct(midi_out, midievent);
}
else {
snd_seq_ev_set_subs(midievent);
snd_seq_ev_set_direct(midievent);
snd_seq_event_output_direct(midi_out, midievent);
}
}
snd_seq_free_event(midievent);
}
|