diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/drumgizmo.cc | 4 | ||||
-rw-r--r-- | src/jackclient.cc | 14 | ||||
-rw-r--r-- | src/jackclient.h | 5 | ||||
-rw-r--r-- | src/midimapper.cc | 56 | ||||
-rw-r--r-- | src/midimapper.h | 44 |
6 files changed, 111 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7e7ebbe..472f5fe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,9 +8,11 @@ drumgizmo_SOURCES = \ drumgizmo.cc \ event.cc \ jackclient.cc \ + midimapper.cc \ sample.cc EXTRA_DIST = \ jackclient.h \ event.h \ + midimapper.h \ sample.h diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index f423bb0..936c231 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -47,7 +47,7 @@ int process(jack_nframes_t nframes, void *arg) jack_midi_event_write(port_buf, time, all_notes_off, size); timer = 0; - next = (size_t)(((float)rand() / (float)RAND_MAX) * 0.3 * 44100); + next = (size_t)(((float)rand() / (float)RAND_MAX) * 0.2 * 44100); } timer += nframes; @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) client.activate(); - sendMidi(); + // sendMidi(); while(1) sleep(1); diff --git a/src/jackclient.cc b/src/jackclient.cc index 0f3e254..ed2838e 100644 --- a/src/jackclient.cc +++ b/src/jackclient.cc @@ -121,21 +121,15 @@ int JackClient::process(jack_nframes_t nframes) for(jack_nframes_t i = 0; i < midievents; i++) { jack_midi_event_t midi_event; jack_midi_event_get(&midi_event, midibuffer, i); - /* - // Parse midi event - printf("[ Time: %d Size: %d ", midi_event.time, midi_event.size); - for(size_t j = 0; j < midi_event.size; j++) { - jack_midi_data_t m = midi_event.buffer[j]; - printf(" Data: %d ", m); - } - printf("]\n"); - */ + int s = midimapper.map(midi_event); + if(s == -1) continue; // -1 is illigal node. + Ports::iterator pi = output_ports.begin(); while(pi != output_ports.end()) { // Create trigger event - Event event(*pi, sample[midi_event.buffer[0]], midi_event.time); + Event event(*pi, sample[s], midi_event.time); events.insert(event); pi++; diff --git a/src/jackclient.h b/src/jackclient.h index f1b6b72..b910323 100644 --- a/src/jackclient.h +++ b/src/jackclient.h @@ -34,8 +34,7 @@ #include "event.h" #include "sample.h" - -#define TEST_MIDI +#include "midimapper.h" typedef std::vector< jack_port_t *> Ports; @@ -65,6 +64,8 @@ private: Sample *sample[2]; Events events; + + MidiMapper midimapper; }; #endif/*__DRUMGIZMO_JACKCLIENT_H__*/ diff --git a/src/midimapper.cc b/src/midimapper.cc new file mode 100644 index 0000000..ed8c252 --- /dev/null +++ b/src/midimapper.cc @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * midimapper.cc + * + * Mon Jul 21 15:24:08 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "midimapper.h" + +#define NOTE_ON 0x90 + +MidiMapper::MidiMapper() +{ + for(int i = 0; i < 16; i++) _map[i] = i % 2; +} + +//http://ccrma-www.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html +int MidiMapper::map(jack_midi_event_t event) +{ + // Parse midi event + printf("[ Time: %d Size: %d ", event.time, event.size); + for(size_t j = 0; j < event.size; j++) { + jack_midi_data_t m = event.buffer[j]; + printf(" Data: %d ", m); + } + printf("]\n"); + + if(event.size == 3) return -1; + if(event.buffer[0] != NOTE_ON) return -1; + + int key = event.buffer[1]; + // int velocity = event.buffer[2]; + + if(_map.find(key) == _map.end()) return -1; // key is not in map. + + return _map[key]; +} diff --git a/src/midimapper.h b/src/midimapper.h new file mode 100644 index 0000000..d0b6a72 --- /dev/null +++ b/src/midimapper.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * midimapper.h + * + * Mon Jul 21 15:24:07 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __DRUMGIZMO_MIDIMAPPER_H__ +#define __DRUMGIZMO_MIDIMAPPER_H__ + +#include <jack/midiport.h> + +#include <map> + +class MidiMapper { +public: + MidiMapper(); + + int map(jack_midi_event_t event); + +private: + std::map< int, int > _map; +}; + +#endif/*__DRUMGIZMO_MIDIMAPPER_H__*/ |