Misc/Stereo Added Stereo(const T &val) constructor
[zynaddsubfx-code.git] / ExternalPrograms / Spliter / Spliter.C
blob823fd3264ad041aad7f17e69c0aaa20c99402066
1 //Copyright (c) 2002-2003 Nasca Octavian Paul 
2 //License: GNU GPL 2
4 #include "Spliter.h"
5 #include <stdio.h>
7 pthread_mutex_t mutex;
8 int Pexitprogram;
10 Spliter::Spliter(){
11     //init
12     Psplitpoint=60;
13     Pchin=0;
14     Pchout1=0;
15     Pchout2=1;
16     Poct1=0;
17     Poct2=0;
18     //ALSA init
19     snd_seq_open(&midi_in,"default",SND_SEQ_OPEN_INPUT,0);
20     snd_seq_open(&midi_out,"default",SND_SEQ_OPEN_OUTPUT,0);
22     char portname[50];sprintf(portname,"Spliter IN");
23     int alsaport = snd_seq_create_simple_port(midi_in,portname
24                     ,SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE 
25                     ,SND_SEQ_PORT_TYPE_SYNTH);
26     sprintf(portname,"Spliter OUT");
27     alsaport = snd_seq_create_simple_port(midi_out,portname
28                     ,SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ 
29                     ,SND_SEQ_PORT_TYPE_SYNTH);
31     
34 Spliter::~Spliter(){
35     snd_seq_close(midi_in);
36     snd_seq_close(midi_out);
39 // This splits the Midi events from one channel to another two channels
40 void Spliter::midievents(){
41     snd_seq_event_t *midievent;
42     midievent=NULL;
43     snd_seq_event_input(midi_in,&midievent);
44     
45     if (midievent==NULL) return;
46     if  ((midievent->type==SND_SEQ_EVENT_NOTEON)||(midievent->type==SND_SEQ_EVENT_NOTEOFF)){
47         int cmdchan=midievent->data.note.channel;
48         if (cmdchan==Pchin){
49         snd_seq_ev_set_subs(midievent);  
50         snd_seq_ev_set_direct(midievent);
51         if (midievent->data.note.note<Psplitpoint) {
52             midievent->data.note.channel=Pchout1;
53             int tmp=midievent->data.note.note;
54             tmp+=Poct1*12;if (tmp>127) tmp=127;if (tmp<0) tmp=0;
55             midievent->data.note.note=tmp;
56             } else {
57             midievent->data.note.channel=Pchout2;
58             int tmp=midievent->data.note.note;
59             tmp+=Poct2*12;if (tmp>127) tmp=127;if (tmp<0) tmp=0;
60             midievent->data.note.note=tmp;
61             };
62         snd_seq_event_output_direct(midi_out,midievent);
63         } else {
64         snd_seq_ev_set_subs(midievent);  
65         snd_seq_ev_set_direct(midievent);
66         snd_seq_event_output_direct(midi_out,midievent);
67         };
68                                     
69     };
70     snd_seq_free_event(midievent);