diff options
author | deva <deva> | 2009-11-22 09:56:08 +0000 |
---|---|---|
committer | deva <deva> | 2009-11-22 09:56:08 +0000 |
commit | 366701768b4e7e31e3d96071700783a49bcbd078 (patch) | |
tree | aa8a1c9493c8f46d36ee1f3239d9b59361692139 /src | |
parent | 28630efa5e905f501f267e5e105d184ec5dd379a (diff) |
Added editor for automated chopping up of audiofiles into samples.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/audiofile.cc | 6 | ||||
-rw-r--r-- | src/drumgizmo.cc | 6 | ||||
-rw-r--r-- | src/midimapper.cc | 8 | ||||
-rw-r--r-- | src/midiplayer.cc | 58 | ||||
-rw-r--r-- | src/midiplayer.h | 5 |
6 files changed, 69 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 2108c43..5ec0802 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,8 @@ bin_PROGRAMS = drumgizmo -drumgizmo_LDADD = $(JACK_LIBS) $(SNDFILE_LIBS) +drumgizmo_LDADD = $(JACK_LIBS) $(SNDFILE_LIBS) $(SMF_LIBS) -drumgizmo_CXXFLAGS = $(JACK_CXXFLAGS) $(SNDFILE_CXXFLAGS) +drumgizmo_CXXFLAGS = $(JACK_CXXFLAGS) $(SNDFILE_CXXFLAGS) $(SMF_CFLAGS) drumgizmo_SOURCES = \ audiofile.cc \ diff --git a/src/audiofile.cc b/src/audiofile.cc index a556bca..9c00bed 100644 --- a/src/audiofile.cc +++ b/src/audiofile.cc @@ -41,12 +41,12 @@ AudioFile::AudioFile(std::string filename, bool preload, int min_velocity) int num = atoi(p); if(num < 0) num *= -1; - printf("%s", filename.c_str()); + //printf("%s", filename.c_str()); if(preload && num >= min_velocity) { - printf(" ... loading"); + //printf(" ... loading"); load(); } - printf("\n"); + printf("."); fflush(stdout); } AudioFile::~AudioFile() diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index a4d863f..3941f17 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -136,7 +136,11 @@ int main(int argc, char *argv[]) client.activate(); - if(midifile) MidiPlayer player(midifile); + if(midifile) { + MidiPlayer player(midifile); + + while(1) sleep(1); + } while(1) sleep(1); diff --git a/src/midimapper.cc b/src/midimapper.cc index 1d2c7a8..6bf38c7 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -26,7 +26,7 @@ */ #include "midimapper.h" -#define NOTE_ON 0x90 +#define NOTE_ON 0x9 MidiMapper::MidiMapper(DrumKit *drumkit) { @@ -64,8 +64,10 @@ Sample *MidiMapper::map(jack_midi_event_t event) { Sample *sample = NULL; + // printf("m"); fflush(stdout); + if(event.size != 3) return NULL; - if(event.buffer[0] != NOTE_ON) return NULL; + if(event.buffer[0] & NOTE_ON != NOTE_ON) return NULL; int key = event.buffer[1]; int velocity = event.buffer[2]; @@ -81,7 +83,7 @@ Sample *MidiMapper::map(jack_midi_event_t event) printf("]\n"); */ if(drumkit->instruments.find(key) == drumkit->instruments.end()) { - printf("Unknown intrsument %d\n", key); + printf("Unknown instrument %d\n", key); return NULL; } diff --git a/src/midiplayer.cc b/src/midiplayer.cc index f8c462b..b55b225 100644 --- a/src/midiplayer.cc +++ b/src/midiplayer.cc @@ -26,8 +26,6 @@ */ #include "midiplayer.h" -#define NOTE_ON 0x90 - int _process(jack_nframes_t nframes, void *arg) { return ((MidiPlayer*)arg)->process(nframes); @@ -35,9 +33,16 @@ int _process(jack_nframes_t nframes, void *arg) MidiPlayer::MidiPlayer(std::string filename) { + timeline = 0; + cur_event = NULL; + + printf("Loading MIDI file: %s\n", filename.c_str()); + smf = smf_load(filename.c_str()); + printf("done\n"); + jack_status_t status; - jack_client_t *jack_client = jack_client_open("MidiTest", JackNullOption, &status); + jack_client_t *jack_client = jack_client_open("MidiGizmo", JackNullOption, &status); port = jack_port_register(jack_client, "midi_out", @@ -49,8 +54,9 @@ MidiPlayer::MidiPlayer(std::string filename) jack_activate(jack_client); - jack_connect(jack_client, "MidiTest:midi_out", "DrumGizmo:midi_in"); + jack_connect(jack_client, "MidiGizmo:midi_out", "DrumGizmo:midi_in"); + jack_connect(jack_client, "DrumGizmo:Alesis", "system:playback_1"); jack_connect(jack_client, "DrumGizmo:Kick-R", "system:playback_1"); jack_connect(jack_client, "DrumGizmo:Kick-L", "system:playback_1"); jack_connect(jack_client, "DrumGizmo:SnareTop", "system:playback_1"); @@ -63,6 +69,7 @@ MidiPlayer::MidiPlayer(std::string filename) jack_connect(jack_client, "DrumGizmo:Ride", "system:playback_1"); // jack_connect(jack_client, "DrumGizmo:Hihat", "system:playback_1"); + jack_connect(jack_client, "DrumGizmo:Alesis", "system:playback_2"); jack_connect(jack_client, "DrumGizmo:Kick-R", "system:playback_2"); jack_connect(jack_client, "DrumGizmo:Kick-L", "system:playback_2"); jack_connect(jack_client, "DrumGizmo:SnareTop", "system:playback_2"); @@ -80,12 +87,15 @@ MidiPlayer::MidiPlayer(std::string filename) jack_connect(jack_client, "DrumGizmo:Amb-R", "system:playback_1"); jack_connect(jack_client, "DrumGizmo:Amb-L", "system:playback_2"); + /* timer = 0; next = 44100; + */ } MidiPlayer::~MidiPlayer() { + smf_delete(smf); } #if 0 // All @@ -93,12 +103,12 @@ MidiPlayer::~MidiPlayer() static int inst[] = { 35, 36, 38, 46, 41, 43, 45, 47, 49, 57, 51 }; #endif -#if 1 // Cymbals +#if 0 // Cymbals #define NUM_INST 3 static int inst[] = { 51, 49, 57 }; #endif -#if 0 // Toms +#if 1 // Toms #define NUM_INST 4 static int inst[] = { 41, 43, 45, 47 }; #endif @@ -109,13 +119,42 @@ static int inst[] = { 35, 36 }; #endif int MidiPlayer::process(jack_nframes_t nframes) { - return 0; - // if(jack_port_connected_to(test_midi_port, "DrumGizmo:midi_in")) { void* port_buf = jack_port_get_buffer(port, nframes); + + + double cur_max_time = (double)(timeline + nframes) / 44100.0; + double cur_min_time = (double)(timeline) / 44100.0; + + printf("["); fflush(stdout); + + if(!cur_event) cur_event = smf_get_next_event(smf); + do { + if(cur_event) { + if(!smf_event_is_metadata(cur_event)) { + + printf("p"); fflush(stdout); + + jack_nframes_t time = (jack_nframes_t)((cur_event->time_seconds - cur_min_time) * 44100.0); + jack_midi_event_write(port_buf, time, (jack_midi_data_t*)cur_event->midi_buffer, + cur_event->midi_buffer_length); + } + } else { + smf_rewind(smf); + } + cur_event = smf_get_next_event(smf); + while(!cur_event) cur_event = smf_get_next_event(smf); + } while(cur_event->time_seconds < cur_max_time && cur_event->time_seconds >= cur_min_time); + + timeline += nframes; + + printf("]\n"); fflush(stdout); + + + /* if(timer > next) { // activate every second (44100 samples) - // printf("ding\n"); + jack_nframes_t time = (jack_nframes_t)(((float)rand() / (float)RAND_MAX) * nframes); size_t size = 3; @@ -127,6 +166,7 @@ int MidiPlayer::process(jack_nframes_t nframes) } timer += nframes; + */ return 0; } diff --git a/src/midiplayer.h b/src/midiplayer.h index 3694939..e41c73a 100644 --- a/src/midiplayer.h +++ b/src/midiplayer.h @@ -30,6 +30,7 @@ #include <jack/jack.h> #include <jack/midiport.h> #include <string> +#include <smf.h> class MidiPlayer { public: @@ -44,6 +45,10 @@ private: size_t timer; size_t next; + + smf_t *smf; + smf_event_t *cur_event; + unsigned int timeline; }; #endif/*__DRUMGIZMO_MIDIPLAYER_H__*/ |