From: Brix <brix82@libero.it>
To: alsa-devel@lists.sourceforge.net
Subject: troubles programming with the sequencer
Date: Fri, 23 Jan 2004 19:05:32 +0100 [thread overview]
Message-ID: <20040123190532.1f335a80.brix82@libero.it> (raw)
Hi, i'm developing an ear-trainer (an application to improve musical ears) and i must use the MIDI synth to play out chords, but i can't let the alsa sequencer work.
My code doesn't return any error, i just can't hear anything. If i do it via the RawMIDI API, it works fine (but it's, bleahh, horrible to use).
I thought it was because i didn't assign any path/instrument to the midi channels, so i tried to set them via RawMIDI, but it still doesn't work.
Here is the code:
#include <alsa/asoundlib.h>
snd_rawmidi_t *handle_out;
void set_chan_instr( int chan, int instrument ) { // sets patch/instrument number on a channel
int ch = 0xC0 + chan;
snd_rawmidi_write(handle_out, &ch, 1);
ch = instrument;
snd_rawmidi_write(handle_out, &ch, 1);
}
snd_seq_t *open_client() { // creates a client
snd_seq_t *handle;
int err;
err = snd_seq_open(&handle, "default", SND_SEQ_OPEN_DUPLEX, 0);
if (err < 0)
return NULL;
snd_seq_set_client_name(handle, "My Client");
return handle;
}
int main() {
snd_seq_t *seq;
snd_seq_queue_tempo_t *tempo;
snd_seq_event_t ev;
snd_seq_port_info_t *port_info, *wavetable;
int port;
int queue;
// now we try to set up channel 0 via RawMIDI
if ( snd_rawmidi_open( NULL, &handle_out, "hw:0,1", 0) ) {
printf( "snd_rawmidi_open() failed\n" );
return -1;
}
// ok, let's assign instrument #4
set_chan_instr( 0, 4 );
// we create a client...
if ( ( seq = open_client() ) == NULL ) {
printf( "Error in: snd_seq_open" );
return -1;
}
// and a port
port = snd_seq_create_simple_port(seq, "my port", SND_SEQ_PORT_CAP_DUPLEX, SND_SEQ_PORT_TYPE_APPLICATION);
queue = snd_seq_alloc_queue(seq); // do allocate a queue
snd_seq_queue_tempo_alloca(&tempo);
snd_seq_queue_tempo_set_ppq(tempo, 96); // 96 pulses per quarter
snd_seq_queue_tempo_set_tempo(tempo, 1000000); // 60 BPM
snd_seq_set_queue_tempo(seq, queue, tempo);
snd_seq_ev_clear(&ev);
snd_seq_ev_set_dest(&ev, 65, 0); // 65:0 works fine with pmidi!
snd_seq_ev_set_source(&ev, port);
snd_seq_ev_schedule_tick(&ev, queue, 0, 4); // starts at 4 ticks
snd_seq_ev_set_note(&ev, 0, 60, 127, 8); // length 8 ticks
snd_seq_event_output(seq, &ev);
snd_seq_ev_schedule_tick(&ev, queue, 0, 12);
snd_seq_ev_set_note(&ev, 0, 67, 127, 8);
// let's play! (we hope..)
snd_seq_event_output(seq, &ev);
snd_seq_drain_output(seq);
snd_seq_start_queue(seq, queue, NULL);
snd_seq_drain_output(seq);
return 0;
}
Note that i can play midi files using pmidi on port 65:0.
Hope you can help me,
Marco
--
Hardware is never old.
People just choose the wrong OS.
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
next reply other threads:[~2004-01-23 18:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-23 18:05 Brix [this message]
2004-01-26 13:52 ` troubles programming with the sequencer Clemens Ladisch
2004-01-29 20:21 ` Brix
2004-01-30 13:51 ` Brix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040123190532.1f335a80.brix82@libero.it \
--to=brix82@libero.it \
--cc=alsa-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.