Skip to content

Commit

Permalink
Correct midiseq.c : better use jack_midi_reset_buffer instead of jack…
Browse files Browse the repository at this point in the history
…_midi_clear_buffer for output port.
  • Loading branch information
sletz committed Feb 10, 2016
1 parent 5e565e6 commit 123de36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
67 changes: 30 additions & 37 deletions example-clients/midiseq.c
Expand Up @@ -50,49 +50,44 @@ static void usage()

static int process(jack_nframes_t nframes, void *arg)
{
int i,j;
void* port_buf = jack_port_get_buffer(output_port, nframes);
unsigned char* buffer;
jack_midi_clear_buffer(port_buf);
/*memset(buffer, 0, nframes*sizeof(jack_default_audio_sample_t));*/
int i,j;
void* port_buf = jack_port_get_buffer(output_port, nframes);
unsigned char* buffer;
jack_midi_reset_buffer(port_buf);
/*memset(buffer, 0, nframes*sizeof(jack_default_audio_sample_t));*/

for(i=0; i<nframes; i++)
{
for(j=0; j<num_notes; j++)
{
if(note_starts[j] == loop_index)
{
buffer = jack_midi_event_reserve(port_buf, i, 3);
/* printf("wrote a note on, port buffer = 0x%x, event buffer = 0x%x\n", port_buf, buffer);*/
buffer[2] = 64; /* velocity */
buffer[1] = note_frqs[j];
buffer[0] = 0x90; /* note on */
}
else if(note_starts[j] + note_lengths[j] == loop_index)
{
buffer = jack_midi_event_reserve(port_buf, i, 3);
/* printf("wrote a note off, port buffer = 0x%x, event buffer = 0x%x\n", port_buf, buffer);*/
buffer[2] = 64; /* velocity */
buffer[1] = note_frqs[j];
buffer[0] = 0x80; /* note off */
}
}
loop_index = loop_index+1 >= loop_nsamp ? 0 : loop_index+1;
}
return 0;
for (i = 0; i < nframes; i++) {
for (j = 0; j < num_notes; j++) {
if (note_starts[j] == loop_index) {
if ((buffer = jack_midi_event_reserve(port_buf, i, 3))) {
/* printf("wrote a note on, port buffer = 0x%x, event buffer = 0x%x\n", port_buf, buffer); */
buffer[2] = 64; /* velocity */
buffer[1] = note_frqs[j];
buffer[0] = 0x90; /* note on */
}
} else if (note_starts[j] + note_lengths[j] == loop_index) {
if ((buffer = jack_midi_event_reserve(port_buf, i, 3))) {
/* printf("wrote a note off, port buffer = 0x%x, event buffer = 0x%x\n", port_buf, buffer); */
buffer[2] = 64; /* velocity */
buffer[1] = note_frqs[j];
buffer[0] = 0x80; /* note off */
}
}
}
loop_index = loop_index+1 >= loop_nsamp ? 0 : loop_index+1;
}
return 0;
}

int main(int narg, char **args)
{
int i;
jack_nframes_t nframes;
if((narg<6) || ((narg-3)%3 !=0))
{
if ((narg<6) || ((narg-3)%3 != 0)) {
usage();
exit(1);
}
if((client = jack_client_open (args[1], JackNullOption, NULL)) == 0)
{
if ((client = jack_client_open (args[1], JackNullOption, NULL)) == 0) {
fprintf (stderr, "JACK server not running?\n");
return 1;
}
Expand All @@ -105,15 +100,13 @@ int main(int narg, char **args)
note_starts = malloc(num_notes*sizeof(jack_nframes_t));
note_lengths = malloc(num_notes*sizeof(jack_nframes_t));
loop_nsamp = atoi(args[2]);
for(i=0; i<num_notes; i++)
{
for (i = 0; i < num_notes; i++) {
note_starts[i] = atoi(args[3 + 3*i]);
note_frqs[i] = atoi(args[4 + 3*i]);
note_lengths[i] = atoi(args[5 + 3*i]);
}

if (jack_activate(client))
{
if (jack_activate(client)) {
fprintf (stderr, "cannot activate client");
return 1;
}
Expand Down
2 changes: 0 additions & 2 deletions macosx/Jackdmp.xcodeproj/project.pbxproj
Expand Up @@ -1785,7 +1785,6 @@
4B49D3C214864D49003390F8 /* pa_asio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pa_asio.h; path = ../windows/portaudio/pa_asio.h; sourceTree = SOURCE_ROOT; };
4B49D3C314864D49003390F8 /* portaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = portaudio.h; path = ../windows/portaudio/portaudio.h; sourceTree = SOURCE_ROOT; };
4B49D3C914864DA7003390F8 /* JackLinuxTime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = JackLinuxTime.c; path = ../linux/JackLinuxTime.c; sourceTree = SOURCE_ROOT; };
4B49D3CB14864DB2003390F8 /* cycles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cycles.h; path = ../linux/cycles.h; sourceTree = SOURCE_ROOT; };
4B49D3D814864DEC003390F8 /* JackWinThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackWinThread.cpp; path = ../windows/JackWinThread.cpp; sourceTree = SOURCE_ROOT; };
4B49D3D914864DEC003390F8 /* JackWinServerLaunch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackWinServerLaunch.cpp; path = ../windows/JackWinServerLaunch.cpp; sourceTree = SOURCE_ROOT; };
4B49D3DA14864DEC003390F8 /* JackWinSemaphore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackWinSemaphore.cpp; path = ../windows/JackWinSemaphore.cpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -2905,7 +2904,6 @@
isa = PBXGroup;
children = (
4B05A07D0DF72BC000840F4C /* driver.h */,
4B49D3CB14864DB2003390F8 /* cycles.h */,
4B49D3C914864DA7003390F8 /* JackLinuxTime.c */,
4B349837133A6B6F00D130AB /* firewire */,
4B349825133A6AF500D130AB /* alsarawmidi */,
Expand Down

0 comments on commit 123de36

Please sign in to comment.