diff options
author | deva <deva> | 2008-07-21 12:11:02 +0000 |
---|---|---|
committer | deva <deva> | 2008-07-21 12:11:02 +0000 |
commit | 981cd50a83e67f5471ee1e1ad0c0575506f14da0 (patch) | |
tree | c206e93a6def02fec109190cc1c0b15c26f639c8 | |
parent | 9f07c02a19ee79906ad3f3ab8c9eed725def8b96 (diff) |
Wee multivoices and multiple wavs... all triggered by the midi test framework.
-rw-r--r-- | src/cymbal.wav | bin | 0 -> 147512 bytes | |||
-rw-r--r-- | src/drumgizmo.cc | 13 | ||||
-rw-r--r-- | src/event.cc | 10 | ||||
-rw-r--r-- | src/event.h | 7 | ||||
-rw-r--r-- | src/jackclient.cc | 52 | ||||
-rw-r--r-- | src/jackclient.h | 2 | ||||
-rw-r--r-- | src/snare.wav | bin | 0 -> 49220 bytes |
7 files changed, 53 insertions, 31 deletions
diff --git a/src/cymbal.wav b/src/cymbal.wav Binary files differnew file mode 100644 index 0000000..0ce8b13 --- /dev/null +++ b/src/cymbal.wav diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 737a197..f423bb0 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -31,20 +31,23 @@ static jack_port_t *test_midi_port = NULL; static size_t timer = 0; +static size_t next = 44100; int process(jack_nframes_t nframes, void *arg) { // if(jack_port_connected_to(test_midi_port, "DrumGizmo:midi_in")) { void* port_buf = jack_port_get_buffer(test_midi_port, nframes); - if(timer > 44100) { // activate every second (44100 samples) - printf("ding\n"); + if(timer > next) { // activate every second (44100 samples) + // printf("ding\n"); - jack_nframes_t time = 1; - size_t size = 3; - jack_midi_data_t all_notes_off[] = { 0xB0, 123, 0 }; + jack_nframes_t time = (jack_nframes_t)(((float)rand() / (float)RAND_MAX) * nframes); + size_t size = 1; + jack_midi_data_t all_notes_off[] = { rand() % 2 }; jack_midi_event_write(port_buf, time, all_notes_off, size); + timer = 0; + next = (size_t)(((float)rand() / (float)RAND_MAX) * 0.3 * 44100); } timer += nframes; diff --git a/src/event.cc b/src/event.cc index 804d42f..c589807 100644 --- a/src/event.cc +++ b/src/event.cc @@ -26,11 +26,12 @@ */ #include "event.h" -Event::Event(Sample *sample, size_t onset) +Event::Event(jack_port_t *port, Sample *sample, size_t time, size_t duration) { + this->port = port; this->sample = sample; - this->onset = onset; - duration = 0; + this->time = time; + this->duration = duration; } Event::~Event() @@ -39,5 +40,6 @@ Event::~Event() bool Event::operator<(const Event& event) const { - return onset + duration < event.onset + event.duration; + if(time == event.time) return this < &event; + return time < event.time; } diff --git a/src/event.h b/src/event.h index 4f277a7..c32297e 100644 --- a/src/event.h +++ b/src/event.h @@ -27,19 +27,22 @@ #ifndef __DRUMGIZMO_EVENT_H__ #define __DRUMGIZMO_EVENT_H__ +#include <jack/jack.h> + #include <set> #include "sample.h" class Event { public: - Event(Sample *sample, size_t onset); + Event(jack_port_t *port, Sample *sample, size_t time, size_t duration = 0); ~Event(); bool operator<(const Event& event) const; + jack_port_t *port; Sample *sample; size_t duration; - size_t onset; + size_t time; }; typedef std::set< Event > Events; diff --git a/src/jackclient.cc b/src/jackclient.cc index 42a85c2..0f3e254 100644 --- a/src/jackclient.cc +++ b/src/jackclient.cc @@ -96,7 +96,8 @@ JackClient::JackClient(size_t num_inputs, size_t num_outputs) //jack_set_xrun_callback(jack_client, _wrap_jack_xrun, this); - sample = new Sample("/home/deva/snare.wav"); + sample[0] = new Sample("cymbal.wav"); + sample[1] = new Sample("snare.wav"); } JackClient::~JackClient() @@ -130,10 +131,15 @@ int JackClient::process(jack_nframes_t nframes) printf("]\n"); */ - // Create trigger event - Event event(sample, midi_event.time); - events.insert(event); + 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); + events.insert(event); + pi++; + } } jack_midi_clear_buffer(midibuffer); @@ -152,30 +158,38 @@ int JackClient::process(jack_nframes_t nframes) pi++; } + Events nextevents; + + // printf("Events %d\n", events.size()); + // Handle events Events::iterator ei = events.begin(); while(ei != events.end()) { - printf("Event\n"); - - Ports::iterator pi = output_ports.begin(); - while(pi != output_ports.end()) { - - jack_default_audio_sample_t *buffer; - buffer = (jack_default_audio_sample_t *)jack_port_get_buffer(*pi, nframes); + Event event = *ei; - for(size_t j = 0; j < nframes; j++) { - buffer[j] = sample->data[j];//(float)rand() / (float)RAND_MAX; // Set output - } - - pi++; + jack_default_audio_sample_t *buffer; + buffer = (jack_default_audio_sample_t *)jack_port_get_buffer(event.port, nframes); + + size_t size = (event.sample->size - event.duration) < nframes ? + (event.sample->size - event.duration) - event.time : nframes - event.time; + + for(size_t j = event.time; j < event.time + size; j++) { + //memcpy(buffer + event.time, event.sample->data + event.duration, size); + buffer[j] += event.sample->data[event.duration + j]; } - + + if(event.duration + size < event.sample->size) { + Event e(event.port, event.sample, 0, event.duration + size); + nextevents.insert(e); + } + ei++; } - // Remove all events - events.clear(); + // Remove all dead events + events = nextevents; + /* for(size_t i = 0; i < output_ports.size(); i++) { jack_default_audio_sample_t *buffer; diff --git a/src/jackclient.h b/src/jackclient.h index cf32eb0..f1b6b72 100644 --- a/src/jackclient.h +++ b/src/jackclient.h @@ -63,7 +63,7 @@ private: Ports output_ports; jack_port_t *midi_port; - Sample *sample; + Sample *sample[2]; Events events; }; diff --git a/src/snare.wav b/src/snare.wav Binary files differnew file mode 100644 index 0000000..77a6123 --- /dev/null +++ b/src/snare.wav |