All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Development Question
@ 2007-03-21  1:02 M. Gagnon
  0 siblings, 0 replies; 10+ messages in thread
From: M. Gagnon @ 2007-03-21  1:02 UTC (permalink / raw)
  To: alsa-devel


> > >What is the output of the program?
> >
> > pending events size: 28
> > pending events size: 56
> > pending events size: 84
> > ...
> > BEFORE DRAIN: pending events size: 476
> > AFTER DRAIN: pending events size: 0
>
>Looks OK.  In theory, all events should be sent somewhere.
>
>Please run aseqdump and send the events to its port.  What does it
>output?
>

% aseqdump
Waiting for data at port 128:0. Press Ctrl+C to end.
Source_ Event_________________ Ch _Data__
  0:1   Port subscribed           129:0 -> 128:0
129:0   Note on                 2  60 127
  0:1   Port unsubscribed         129:0 -> 128:0

Seems like only one event gets sent - just like what i hear.

>Run "cat /proc/asound/seq/queues" and
>"cat /proc/asound/seq/timer".
>

% cat /proc/asound/seq/queues
queue 0: [Queue-0]
owned by client    : 128
lock status        : Locked
queued time events : 0
queued tick events : 0
timer state        : Running
timer PPQ          : 96
current tempo      : 500000
current BPM        : 120
current time       : 1.536000000 s
current tick       : 294

queue 1: [Queue-1]
owned by client    : 129
lock status        : Locked
queued time events : 0
queued tick events : 0
timer state        : Running
timer PPQ          : 48
current tempo      : 1000000
current BPM        : 60
current time       : 1.488000000 s
current tick       : 71

% cat /proc/asound/seq/timer
Timer for queue 0 : system timer
  Period time : 0.004000000
  Skew : 65536 / 65536
Timer for queue 1 : system timer
  Period time : 0.004000000
  Skew : 65536 / 65536

thanks for your help

just as reminder (so the output can be interpreted) this is my latest code
/*
all:
	g++ midi_receiver.cpp -o AlsaNoteTest -lasound
*/

#include <stdio.h>
#include <alsa/asoundlib.h>
#include "midi_receiver.h"
#include <vector>
#include <iostream>
#include <unistd.h>
#include <pthread.h>

pthread_t thread1;
char *message1 = "Thread 1";
int  iret1;

void *play_func( void *ptr )
{
     AlsaNotePlayer::play();
}

int main()
{
AlsaNotePlayer::findDevices();
AlsaNotePlayer::openDevice(128, 0);

AlsaNotePlayer::setTempo(60, 48);

int time=0;
int duration = 50;

AlsaNotePlayer::noteOn_seq(1, 60, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 60, 0, time);

AlsaNotePlayer::noteOn_seq(1, 62, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 62, 0, time);

AlsaNotePlayer::noteOn_seq(1, 60, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 60, 0, time);

AlsaNotePlayer::noteOn_seq(1, 59, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 59, 0, time);

// ----------
AlsaNotePlayer::noteOn_seq(1, 63, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 63, 0, time);

AlsaNotePlayer::noteOn_seq(1, 65, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 65, 0, time);

AlsaNotePlayer::noteOn_seq(1, 63, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 63, 0, time);

AlsaNotePlayer::noteOn_seq(1, 61, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 61, 0, time);


iret1 = pthread_create( &thread1, NULL, play_func, (void*) message1);
pthread_join( thread1, NULL);

while(1)
{
usleep(10000);
}

}

namespace AlsaNotePlayer
{

class MidiDevice
{

public:

int client, port;
char* name;

MidiDevice(int client_arg, int port_arg, const char* name_arg)
{
  client = client_arg;
  port = port_arg;
  name = (char*)name_arg;
}

};

std::vector<MidiDevice> devices;

struct MidiContext
{
		snd_seq_t* sequencer;
		int queue;
		snd_seq_addr_t address;
		int port;
		snd_seq_port_subscribe_t *subs;
};

struct MidiContext MidiContext;
snd_seq_addr_t address;

void findDevices()
{
	snd_seq_client_info_t* clientInfo;

	if (snd_seq_open(&MidiContext.sequencer, "default", SND_SEQ_OPEN_OUTPUT, 0) 
< 0)
	{
		return;
	}

	snd_seq_client_info_alloca(&clientInfo);
	snd_seq_client_info_set_client(clientInfo, -1);

	// iterate through clients
	while (snd_seq_query_next_client(MidiContext.sequencer, clientInfo) >= 0)
	{
		snd_seq_port_info_t* pinfo;

		snd_seq_port_info_alloca(&pinfo);
		snd_seq_port_info_set_client(pinfo, 
snd_seq_client_info_get_client(clientInfo));
		snd_seq_port_info_set_port(pinfo, -1);

		// and now through ports
		while (snd_seq_query_next_port(MidiContext.sequencer, pinfo) >= 0)
		{
			unsigned int capability = snd_seq_port_info_get_capability(pinfo);

			if ((capability & SND_SEQ_PORT_CAP_SUBS_WRITE) == 0)
			{
				continue;
			}

			int client  = (snd_seq_port_info_get_addr(pinfo))->client;
			int port    = (snd_seq_port_info_get_addr(pinfo))->port;

			std::cout << client << ":" << port << " --> " << 
snd_seq_port_info_get_name(pinfo) << std::endl;
			devices.push_back( MidiDevice(client, port, 
snd_seq_port_info_get_name(pinfo)) );

		}

	}

	if (snd_seq_set_client_name(MidiContext.sequencer, "Aria") < 0)
	{
		return;
	}

	//MidiContext.address.port = 
snd_seq_create_simple_port(MidiContext.sequencer, "Aria Port 0", 
SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION);
MidiContext.address.port =  
snd_seq_create_simple_port(MidiContext.sequencer, "Aria Port 0",
					 SND_SEQ_PORT_CAP_WRITE |
					 SND_SEQ_PORT_CAP_SUBS_WRITE |
					 SND_SEQ_PORT_CAP_READ,
					 SND_SEQ_PORT_TYPE_APPLICATION);
					 //SND_SEQ_PORT_TYPE_MIDI_GENERIC);

	MidiContext.address.client = snd_seq_client_id (MidiContext.sequencer);
	MidiContext.queue = snd_seq_alloc_queue (MidiContext.sequencer);

	snd_seq_set_client_pool_output (MidiContext.sequencer, 1024);
}

void setTempo(int tempo_arg, int resolution)
{
// argument is not yet considered
        snd_seq_queue_tempo_t *tempo;
        snd_seq_queue_tempo_alloca(&tempo);
       // snd_seq_queue_tempo_set_tempo(tempo, 1000000); // 60 BPM
       // snd_seq_queue_tempo_set_ppq(tempo, 48); // 48 PPQ
	snd_seq_queue_tempo_set_ppq(tempo, resolution);
	snd_seq_queue_tempo_set_tempo(tempo, 60*1000000/tempo_arg);
        snd_seq_set_queue_tempo(MidiContext.sequencer, MidiContext.queue, 
tempo);
}

void openDevice(int client, int port)
{
	address.client = client;
	address.port = port;

	snd_seq_port_subscribe_alloca(&MidiContext.subs);

	snd_seq_port_subscribe_set_sender(MidiContext.subs, &MidiContext.address);
	snd_seq_port_subscribe_set_dest(MidiContext.subs, &address);

	snd_seq_subscribe_port(MidiContext.sequencer, MidiContext.subs);
}

void closeDevice()
{
	snd_seq_port_subscribe_alloca(&MidiContext.subs);
	snd_seq_port_subscribe_set_sender(MidiContext.subs, &MidiContext.address);
	snd_seq_port_subscribe_set_dest(MidiContext.subs, &address);

	if (snd_seq_unsubscribe_port(MidiContext.sequencer, MidiContext.subs) < 0)
	{
		return;
	}
	//snd_seq_port_subscribe_free(MidiContext.subs);
}




//************************************************************************************//
//************************************MIDI 
EVENTS*************************************//
//************************************************************************************//

void noteOn_seq(int channel, int note, int velocity, int tick)
{
	snd_seq_event_t event;

	snd_seq_ev_clear(&event);

	event.queue  = MidiContext.queue;
	event.source = MidiContext.address;

	snd_seq_ev_set_subs(&event);
	snd_seq_ev_set_source(&event, MidiContext.port);
	snd_seq_ev_set_noteon(&event, channel, note, velocity);
	snd_seq_ev_schedule_tick(&event, MidiContext.queue, 0, tick );

	snd_seq_event_output(MidiContext.sequencer, &event);

       std::cout << "pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;
}

void noteOff_seq(int channel, int note, int velocity, int tick)
{
	snd_seq_event_t event;
	snd_seq_ev_clear(&event);

	event.queue  = MidiContext.queue;
	event.source = MidiContext.address;

	snd_seq_ev_set_subs(&event);
	snd_seq_ev_set_noteoff(&event, channel, note, velocity);
        snd_seq_ev_schedule_tick(&event, MidiContext.queue, 0 /*absolute*/, 
tick );

	snd_seq_event_output(MidiContext.sequencer, &event);

       std::cout << "pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;
}


void play()
{
        snd_seq_start_queue(MidiContext.sequencer, MidiContext.queue, 0);

       std::cout << "BEFORE DRAIN: pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;
        int output = snd_seq_drain_output(MidiContext.sequencer);
       std::cout << "AFTER DRAIN: pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;

	if(output == 0) std::cout << "all events drained" << std::endl;
	if(output > 0) std::cout << output << "bytes remaining" << std::endl;
	if(output < 0)
	{
		 fprintf (stderr, "Error: (%s)\n", snd_strerror (output));
		 //std::cout << "error" << std::endl;
	}
}


}

_________________________________________________________________
Ne perdez pas de temps dans les files d’attente… magasinez en ligne.  
http://magasiner.sympatico.msn.ca

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-20  0:27             ` M. Gagnon
  2007-03-20  1:58               ` raghvendra misra
@ 2007-03-20  8:12               ` Clemens Ladisch
  1 sibling, 0 replies; 10+ messages in thread
From: Clemens Ladisch @ 2007-03-20  8:12 UTC (permalink / raw)
  To: M. Gagnon, alsa-devel

M. Gagnon wrote:
> >What is the output of the program?
> 
> pending events size: 28
> pending events size: 56
> pending events size: 84
> ...
> BEFORE DRAIN: pending events size: 476
> AFTER DRAIN: pending events size: 0

Looks OK.  In theory, all events should be sent somewhere.

Please run aseqdump and send the events to its port.  What does it
output?

> >What are the contents of /proc/asound/seq/queues and .../timers while it's
> >trying to play?
> 
> i'm sorry, but despite some googling this still sounds esoteric to me.

These are just file names.  Run "cat /proc/asound/seq/queues" and
"cat /proc/asound/seq/timer".


Regards,
Clemens

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-20  0:27             ` M. Gagnon
@ 2007-03-20  1:58               ` raghvendra misra
  2007-03-20  8:12               ` Clemens Ladisch
  1 sibling, 0 replies; 10+ messages in thread
From: raghvendra misra @ 2007-03-20  1:58 UTC (permalink / raw)
  To: M. Gagnon; +Cc: alsa-devel

unsubscribe

On 3/20/07, M. Gagnon <fire_void@hotmail.com> wrote:
>
> >What is the output of the program?
>
> 14:0 --> Midi Through Port-0
> 128:0 --> TiMidity port 0
> 128:1 --> TiMidity port 1
> 128:2 --> TiMidity port 2
> 128:3 --> TiMidity port 3
> pending events size: 28
> pending events size: 56
> pending events size: 84
> pending events size: 112
> pending events size: 140
> pending events size: 168
> pending events size: 196
> pending events size: 224
> pending events size: 252
> pending events size: 280
> pending events size: 308
> pending events size: 336
> pending events size: 364
> pending events size: 392
> pending events size: 420
> pending events size: 448
> BEFORE DRAIN: pending events size: 476
> AFTER DRAIN: pending events size: 0
> all events drained
>
> everything seems okay to me (i may not be adding the same number of notes as
> in the sample i posted, and i have more console prints now, so small
> differences could appear from the code i posted)
>
> >What are the contents of /proc/asound/seq/queues and .../timers while it's
> >trying to play?
>
> i'm sorry, but despite some googling this still sounds esoteric to me. Any
> reference i could look at to know how to do this?
>
> thanks
>
> _________________________________________________________________
> Participez au concours Tournée Live Mobile dès maintenant!
> http://www.concertmobilelive.ca
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-19  8:33           ` Clemens Ladisch
@ 2007-03-20  0:27             ` M. Gagnon
  2007-03-20  1:58               ` raghvendra misra
  2007-03-20  8:12               ` Clemens Ladisch
  0 siblings, 2 replies; 10+ messages in thread
From: M. Gagnon @ 2007-03-20  0:27 UTC (permalink / raw)
  To: alsa-devel


>What is the output of the program?

14:0 --> Midi Through Port-0
128:0 --> TiMidity port 0
128:1 --> TiMidity port 1
128:2 --> TiMidity port 2
128:3 --> TiMidity port 3
pending events size: 28
pending events size: 56
pending events size: 84
pending events size: 112
pending events size: 140
pending events size: 168
pending events size: 196
pending events size: 224
pending events size: 252
pending events size: 280
pending events size: 308
pending events size: 336
pending events size: 364
pending events size: 392
pending events size: 420
pending events size: 448
BEFORE DRAIN: pending events size: 476
AFTER DRAIN: pending events size: 0
all events drained

everything seems okay to me (i may not be adding the same number of notes as 
in the sample i posted, and i have more console prints now, so small 
differences could appear from the code i posted)

>What are the contents of /proc/asound/seq/queues and .../timers while it's
>trying to play?

i'm sorry, but despite some googling this still sounds esoteric to me. Any 
reference i could look at to know how to do this?

thanks

_________________________________________________________________
Participez au concours Tournée Live Mobile dès maintenant! 
http://www.concertmobilelive.ca


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-18 18:08         ` M. Gagnon
@ 2007-03-19  8:33           ` Clemens Ladisch
  2007-03-20  0:27             ` M. Gagnon
  0 siblings, 1 reply; 10+ messages in thread
From: Clemens Ladisch @ 2007-03-19  8:33 UTC (permalink / raw)
  To: M. Gagnon, alsa-devel

M. Gagnon wrote:
> Okay, i tried with the docs. This is what i came up with, however i can't 
> seem to be able to play anything more than the first event, like time was 
> not moving, Perhaps i've missed something simple to make the time start?

What is the output of the program?
What are the contents of /proc/asound/seq/queues and .../timers while it's
trying to play?


Regards,
Clemens

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-18 10:29       ` Pieter Palmers
@ 2007-03-18 18:08         ` M. Gagnon
  2007-03-19  8:33           ` Clemens Ladisch
  0 siblings, 1 reply; 10+ messages in thread
From: M. Gagnon @ 2007-03-18 18:08 UTC (permalink / raw)
  To: alsa-devel

Okay, i tried with the docs. This is what i came up with, however i can't 
seem to be able to play anything more than the first event, like time was 
not moving, Perhaps i've missed something simple to make the time start?

I have pretty much followed everything that's there 
http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html
but no luck

What i am missing here? I guess it's something simple but i can't find

Thanks a lot for the support!

/*
all:
	g++ midi_receiver.cpp -o AlsaNoteTest -lasound
*/

#include <stdio.h>
#include <alsa/asoundlib.h>
#include <vector>
#include <iostream>
#include <unistd.h>

// --------- declaration -------------
namespace AlsaNotePlayer
{
void  findDevices ();
void  openDevice (int client, int port);
void  closeDevice ();
void noteOn_seq(int channel, int note, int velocity, int tick);
void noteOff_seq(int channel, int note, int velocity, int tick);
void play();
void setTempo(int tempo);
}

// -------- definition ----------------

int main()
{
AlsaNotePlayer::findDevices();
AlsaNotePlayer::openDevice(128, 0); // replace by your ports as needed

AlsaNotePlayer::setTempo(60);

int time=0;
int duration = 200;

AlsaNotePlayer::noteOn_seq(1, 60, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 60, 0, time);

AlsaNotePlayer::noteOn_seq(1, 62, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 62, 0, time);

AlsaNotePlayer::noteOn_seq(1, 60, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 60, 0, time);

AlsaNotePlayer::noteOn_seq(1, 59, 127, time);
time += duration;
AlsaNotePlayer::noteOff_seq(1, 59, 0, time);

AlsaNotePlayer::play();
usleep(999999999);

}

namespace AlsaNotePlayer
{

class MidiDevice
{

public:

int client, port;
char* name;

MidiDevice(int client_arg, int port_arg, const char* name_arg)
{
  client = client_arg;
  port = port_arg;
  name = (char*)name_arg;
}

};

std::vector<MidiDevice> devices;

struct MidiContext
{
		snd_seq_t* sequencer;
		int queue;
		snd_seq_addr_t address;
		int port;
		snd_seq_port_subscribe_t *subs;
};

struct MidiContext MidiContext;
snd_seq_addr_t address;

void noteOn_seq(int channel, int note, int velocity, int tick)
{
	snd_seq_event_t event;

	snd_seq_ev_clear(&event);

	event.queue  = MidiContext.queue;
	event.source = MidiContext.address;

	snd_seq_ev_set_subs(&event);
	snd_seq_ev_set_source(&event, MidiContext.port);
	//snd_seq_ev_set_direct(&event);
	snd_seq_ev_set_noteon(&event, channel, note, velocity);
	snd_seq_ev_schedule_tick(&event, MidiContext.queue, 0, tick );

	snd_seq_event_output(MidiContext.sequencer, &event);

       std::cout << "pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;
}

void noteOff_seq(int channel, int note, int velocity, int tick)
{
	snd_seq_event_t event;
	snd_seq_ev_clear(&event);

	event.queue  = MidiContext.queue;
	event.source = MidiContext.address;

	snd_seq_ev_set_subs(&event);
	//snd_seq_ev_set_direct(&event);
	snd_seq_ev_set_noteoff(&event, channel, note, velocity);
        snd_seq_ev_schedule_tick(&event, channel, 0 /*absolute*/, tick );

	snd_seq_event_output(MidiContext.sequencer, &event);

       std::cout << "pending events size: " << 
snd_seq_event_output_pending(MidiContext.sequencer) << std::endl;
}


void play()
{
        snd_seq_start_queue(MidiContext.sequencer, MidiContext.queue, 0);

        int output = snd_seq_drain_output(MidiContext.sequencer);

	if(output == 0) std::cout << "all events drained" << std::endl;
	else if(output > 0) std::cout << output << "bytes remaining" << std::endl;
	else if(output < 0)
	{
		 fprintf (stderr, "Error: (%s)\n", snd_strerror (output));
	}
}

void findDevices()
{
	snd_seq_client_info_t* clientInfo;

	if (snd_seq_open(&MidiContext.sequencer, "default", SND_SEQ_OPEN_OUTPUT, 0) 
< 0)
	{
		return;
	}

	snd_seq_client_info_alloca(&clientInfo);
	snd_seq_client_info_set_client(clientInfo, -1);

	// iterate through clients
	while (snd_seq_query_next_client(MidiContext.sequencer, clientInfo) >= 0)
	{
		snd_seq_port_info_t* pinfo;

		snd_seq_port_info_alloca(&pinfo);
		snd_seq_port_info_set_client(pinfo, 
snd_seq_client_info_get_client(clientInfo));
		snd_seq_port_info_set_port(pinfo, -1);

		// and now through ports
		while (snd_seq_query_next_port(MidiContext.sequencer, pinfo) >= 0)
		{
			unsigned int capability = snd_seq_port_info_get_capability(pinfo);

			if ((capability & SND_SEQ_PORT_CAP_SUBS_WRITE) == 0)
			{
				continue;
			}

			int client  = (snd_seq_port_info_get_addr(pinfo))->client;
			int port    = (snd_seq_port_info_get_addr(pinfo))->port;

			std::cout << client << ":" << port << " --> " << 
snd_seq_port_info_get_name(pinfo) << std::endl;
			devices.push_back( MidiDevice(client, port, 
snd_seq_port_info_get_name(pinfo)) );

		}

	}

	if (snd_seq_set_client_name(MidiContext.sequencer, "Aria") < 0)
	{
		return;
	}

	MidiContext.address.port = 
snd_seq_create_simple_port(MidiContext.sequencer, "Aria Port 0", 
SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION);
	MidiContext.address.client = snd_seq_client_id (MidiContext.sequencer);
	MidiContext.queue = snd_seq_alloc_queue (MidiContext.sequencer);

	snd_seq_set_client_pool_output (MidiContext.sequencer, 1024);
}

void setTempo(int tempo_arg)
{
// argument is not yet considered
        snd_seq_queue_tempo_t *tempo;
        snd_seq_queue_tempo_alloca(&tempo);
        snd_seq_queue_tempo_set_tempo(tempo, 1000000); // 60 BPM
        snd_seq_queue_tempo_set_ppq(tempo, 48); // 48 PPQ
        snd_seq_set_queue_tempo(MidiContext.sequencer, MidiContext.queue, 
tempo);
}

void openDevice(int client, int port)
{
	address.client = client;
	address.port = port;

	snd_seq_port_subscribe_alloca(&MidiContext.subs);

	snd_seq_port_subscribe_set_sender(MidiContext.subs, &MidiContext.address);
	snd_seq_port_subscribe_set_dest(MidiContext.subs, &address);

	snd_seq_subscribe_port(MidiContext.sequencer, MidiContext.subs);
}

void closeDevice()
{
	snd_seq_port_subscribe_alloca(&MidiContext.subs);
	snd_seq_port_subscribe_set_sender(MidiContext.subs, &MidiContext.address);
	snd_seq_port_subscribe_set_dest(MidiContext.subs, &address);

	if (snd_seq_unsubscribe_port(MidiContext.sequencer, MidiContext.subs) < 0)
	{
		return;
	}
	//snd_seq_port_subscribe_free(MidiContext.subs);
}


}



>From: Pieter Palmers <pieterp@joow.be>
>To: "M. Gagnon" <fire_void@hotmail.com>
>CC: alsa-devel@lists.sourceforge.net
>Subject: Re: [Alsa-devel] Development Question
>Date: Sun, 18 Mar 2007 11:29:32 +0100
>
>M. Gagnon wrote:
>>This is interesting, Pieter, however my app already has the knowledge of 
>>notes and events, the only reason i had midi bytes was because i converted 
>>the events into bytes because then i could make them play using a single 
>>function on mac.
>>
>>Apparently on Linux/Alsa it's not this way, so i should probably learn how 
>>to put a serie of events in a sequence and then play it. The most recent 
>>sample of this i found was dated '2002' and didn't work, and my own 
>>attempts with the documentation didn't either.
>>
>>I am already able to send events directly. Where can i find recent 
>>infomation on how to schedule them in a queue and play them after?
>I found the doxygen docs that come with alsa-devel sufficient.
>
>What you have to do is convert your own 'events' into ALSA seq events, and 
>then use the snd_seq_event_output function. Things as timestamps etc... are 
>properties of ALSA seq events, and can be set using snd_seq_event_* 
>functions.
>
>
>Pieter
>
>PS: One tricky thing if you use multiple ports is that the port an event 
>should be sent to is also a property of the event.
>

_________________________________________________________________
Windows Live Spaces: partagez vos photos avec vos amis! 
http://spaces.live.com/?mkt=fr-ca


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-18  1:19     ` M. Gagnon
@ 2007-03-18 10:29       ` Pieter Palmers
  2007-03-18 18:08         ` M. Gagnon
  0 siblings, 1 reply; 10+ messages in thread
From: Pieter Palmers @ 2007-03-18 10:29 UTC (permalink / raw)
  To: M. Gagnon; +Cc: alsa-devel

M. Gagnon wrote:
> This is interesting, Pieter, however my app already has the knowledge of 
> notes and events, the only reason i had midi bytes was because i converted 
> the events into bytes because then i could make them play using a single 
> function on mac.
> 
> Apparently on Linux/Alsa it's not this way, so i should probably learn how 
> to put a serie of events in a sequence and then play it. The most recent 
> sample of this i found was dated '2002' and didn't work, and my own attempts 
> with the documentation didn't either.
> 
> I am already able to send events directly. Where can i find recent 
> infomation on how to schedule them in a queue and play them after?
I found the doxygen docs that come with alsa-devel sufficient.

What you have to do is convert your own 'events' into ALSA seq events, 
and then use the snd_seq_event_output function. Things as timestamps 
etc... are properties of ALSA seq events, and can be set using 
snd_seq_event_* functions.


Pieter

PS: One tricky thing if you use multiple ports is that the port an event 
should be sent to is also a property of the event.


> 
> thanks
> 
> 
>> From: Pieter Palmers <pieterp@joow.be>
>> To: "M. Gagnon" <fire_void@hotmail.com>
>> CC: alsa-devel@lists.sourceforge.net
>> Subject: Re: [Alsa-devel] Development Question
>> Date: Sat, 17 Mar 2007 22:36:31 +0100
>>
>> M. Gagnon wrote:
>>> Hi, i am now trying to port an application to linux using Alsa. At some 
>>> point, i have midi bytes as char* and i have to play them. This is exactly 
>>> the same data you'd find in a file, expect that it's in memory instead. 
>>> How is that possible?
>>>
>>> If this is not possible, i could always take any help on playing midi 
>>> using sequencers I looked at the docs, i found a few samples, but they 
>>> seemed to be outdated and the one that could interest me segfaulted. After 
>>> i debugged it and fixed the segfault, it played nothing... (and i'm sure 
>>> my midi is configured correctly BTW, pmidi works and i also succeeded in 
>>> getting single notes to play)
>> This is how I do playback in the freebob backend for jack:
>>
>> for (s=0;s<samples_read;s++) {
>>   signed int *byte=(buff+s);
>>   snd_seq_event_t ev;
>>   if ((snd_midi_event_encode_byte(
>>          port->parser,(*byte) & 0xFF, &ev)
>>        ) > 0) {
>>       // a midi message is complete, send it out to ALSA
>>       snd_seq_ev_set_subs(&ev);
>>       snd_seq_ev_set_direct(&ev);
>>       snd_seq_ev_set_source(&ev, port->seq_port_nr);
>>       snd_seq_event_output_direct(port->seq_handle, &ev);			   }
>> }
>>
>> you can check the freebob_driver_midi_* functions in the freebob jack 
>> backend for more detail.
>>
>> Pieter
>>
> 
> _________________________________________________________________
> Windows Live Spaces: partagez vos photos avec vos amis! 
> http://spaces.live.com/?mkt=fr-ca
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
> 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-17 21:36   ` Pieter Palmers
@ 2007-03-18  1:19     ` M. Gagnon
  2007-03-18 10:29       ` Pieter Palmers
  0 siblings, 1 reply; 10+ messages in thread
From: M. Gagnon @ 2007-03-18  1:19 UTC (permalink / raw)
  To: alsa-devel

This is interesting, Pieter, however my app already has the knowledge of 
notes and events, the only reason i had midi bytes was because i converted 
the events into bytes because then i could make them play using a single 
function on mac.

Apparently on Linux/Alsa it's not this way, so i should probably learn how 
to put a serie of events in a sequence and then play it. The most recent 
sample of this i found was dated '2002' and didn't work, and my own attempts 
with the documentation didn't either.

I am already able to send events directly. Where can i find recent 
infomation on how to schedule them in a queue and play them after?

thanks


>From: Pieter Palmers <pieterp@joow.be>
>To: "M. Gagnon" <fire_void@hotmail.com>
>CC: alsa-devel@lists.sourceforge.net
>Subject: Re: [Alsa-devel] Development Question
>Date: Sat, 17 Mar 2007 22:36:31 +0100
>
>M. Gagnon wrote:
>>Hi, i am now trying to port an application to linux using Alsa. At some 
>>point, i have midi bytes as char* and i have to play them. This is exactly 
>>the same data you'd find in a file, expect that it's in memory instead. 
>>How is that possible?
>>
>>If this is not possible, i could always take any help on playing midi 
>>using sequencers I looked at the docs, i found a few samples, but they 
>>seemed to be outdated and the one that could interest me segfaulted. After 
>>i debugged it and fixed the segfault, it played nothing... (and i'm sure 
>>my midi is configured correctly BTW, pmidi works and i also succeeded in 
>>getting single notes to play)
>This is how I do playback in the freebob backend for jack:
>
>for (s=0;s<samples_read;s++) {
>   signed int *byte=(buff+s);
>   snd_seq_event_t ev;
>   if ((snd_midi_event_encode_byte(
>          port->parser,(*byte) & 0xFF, &ev)
>        ) > 0) {
>       // a midi message is complete, send it out to ALSA
>       snd_seq_ev_set_subs(&ev);
>       snd_seq_ev_set_direct(&ev);
>       snd_seq_ev_set_source(&ev, port->seq_port_nr);
>       snd_seq_event_output_direct(port->seq_handle, &ev);			   }
>}
>
>you can check the freebob_driver_midi_* functions in the freebob jack 
>backend for more detail.
>
>Pieter
>

_________________________________________________________________
Windows Live Spaces: partagez vos photos avec vos amis! 
http://spaces.live.com/?mkt=fr-ca


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Development Question
  2007-03-17 19:27 ` M. Gagnon
@ 2007-03-17 21:36   ` Pieter Palmers
  2007-03-18  1:19     ` M. Gagnon
  0 siblings, 1 reply; 10+ messages in thread
From: Pieter Palmers @ 2007-03-17 21:36 UTC (permalink / raw)
  To: M. Gagnon; +Cc: alsa-devel

M. Gagnon wrote:
> Hi, i am now trying to port an application to linux using Alsa. At some 
> point, i have midi bytes as char* and i have to play them. This is exactly 
> the same data you'd find in a file, expect that it's in memory instead. How 
> is that possible?
> 
> If this is not possible, i could always take any help on playing midi using 
> sequencers I looked at the docs, i found a few samples, but they seemed to 
> be outdated and the one that could interest me segfaulted. After i debugged 
> it and fixed the segfault, it played nothing... (and i'm sure my midi is 
> configured correctly BTW, pmidi works and i also succeeded in getting single 
> notes to play)
This is how I do playback in the freebob backend for jack:

for (s=0;s<samples_read;s++) {
   signed int *byte=(buff+s);
   snd_seq_event_t ev;
   if ((snd_midi_event_encode_byte(
          port->parser,(*byte) & 0xFF, &ev)
        ) > 0) {
       // a midi message is complete, send it out to ALSA
       snd_seq_ev_set_subs(&ev);
       snd_seq_ev_set_direct(&ev);
       snd_seq_ev_set_source(&ev, port->seq_port_nr);
       snd_seq_event_output_direct(port->seq_handle, &ev);			   }
}

you can check the freebob_driver_midi_* functions in the freebob jack 
backend for more detail.

Pieter


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Development Question
       [not found] <mailman.0.1174159191.971.alsa-devel@lists.sourceforge.net>
@ 2007-03-17 19:27 ` M. Gagnon
  2007-03-17 21:36   ` Pieter Palmers
  0 siblings, 1 reply; 10+ messages in thread
From: M. Gagnon @ 2007-03-17 19:27 UTC (permalink / raw)
  To: alsa-devel

Hi, i am now trying to port an application to linux using Alsa. At some 
point, i have midi bytes as char* and i have to play them. This is exactly 
the same data you'd find in a file, expect that it's in memory instead. How 
is that possible?

If this is not possible, i could always take any help on playing midi using 
sequencers I looked at the docs, i found a few samples, but they seemed to 
be outdated and the one that could interest me segfaulted. After i debugged 
it and fixed the segfault, it played nothing... (and i'm sure my midi is 
configured correctly BTW, pmidi works and i also succeeded in getting single 
notes to play)

Thanks

_________________________________________________________________
Ne perdez pas de temps dans les files d’attente… magasinez en ligne.  
http://magasiner.sympatico.msn.ca


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-03-21  1:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-21  1:02 Development Question M. Gagnon
     [not found] <mailman.0.1174159191.971.alsa-devel@lists.sourceforge.net>
2007-03-17 19:27 ` M. Gagnon
2007-03-17 21:36   ` Pieter Palmers
2007-03-18  1:19     ` M. Gagnon
2007-03-18 10:29       ` Pieter Palmers
2007-03-18 18:08         ` M. Gagnon
2007-03-19  8:33           ` Clemens Ladisch
2007-03-20  0:27             ` M. Gagnon
2007-03-20  1:58               ` raghvendra misra
2007-03-20  8:12               ` Clemens Ladisch

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.