[PD-cvs] pd/src s_midi_alsa.c,1.1.2.1,1.1.2.2

Tim Blechmann timblech at users.sourceforge.net
Mon May 2 11:29:49 CEST 2005


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3400

Modified Files:
      Tag: devel_0_38
	s_midi_alsa.c 
Log Message:
hopefully fixed memory leak ...

Index: s_midi_alsa.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/s_midi_alsa.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** s_midi_alsa.c	5 Nov 2004 13:33:19 -0000	1.1.2.1
--- s_midi_alsa.c	2 May 2005 09:29:47 -0000	1.1.2.2
***************
*** 26,42 ****
  static snd_seq_t *midi_handle;
  
! static int alsa_port;
! static int alsa_initialized;
! static void alsa_midiout(int fd, int n)
! {
!     /*snd_midi_event_encode_byte();
!     char b = n;
!     if ((write(fd, (char *) &b, 1)) != 1)
!         perror("midi write");*/
! }
  
- #define O_MIDIFLAG O_NDELAY
  
! unsigned short CombineBytes(unsigned char First, unsigned char Second)
  {
      unsigned short _14bit;
--- 26,34 ----
  static snd_seq_t *midi_handle;
  
! static snd_midi_event_t *midiev;
  
  
! 
! static unsigned short CombineBytes(unsigned char First, unsigned char Second)
  {
      unsigned short _14bit;
***************
*** 52,58 ****
  
      char portname[50];
!     int err;
      int client;
      int i;
      if (nmidiin>0 && nmidiout>0)
  	err = snd_seq_open(&midi_handle,"default",SND_SEQ_OPEN_DUPLEX,0);
--- 44,53 ----
  
      char portname[50];
!     int err = 0;
      int client;
      int i;
+     alsa_nmidiin = 0;
+     alsa_nmidiout = 0;
+ 
      if (nmidiin>0 && nmidiout>0)
  	err = snd_seq_open(&midi_handle,"default",SND_SEQ_OPEN_DUPLEX,0);
***************
*** 70,92 ****
      for (i=0;i<nmidiout;i++)
      {
          sprintf(portname,"Pure Data Midi-In %d",i+1);
!         alsa_port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE , SND_SEQ_PORT_TYPE_APPLICATION);
! 	alsa_midiinfd[i] = alsa_port;	
      }
      for (i=0;i<nmidiin;i++)
      {
          sprintf(portname,"Pure Data Midi-Out %d",i+1);
!         alsa_port = snd_seq_create_simple_port(midi_handle,portname,  SND_SEQ_PORT_CAP_SUBS_READ |  SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_APPLICATION);
! 	alsa_midioutfd[i] = alsa_port;	
!     }
!     
! //    alsa_port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_DUPLEX |SND_SEQ_PORT_CAP_SUBS_WRITE |  SND_SEQ_PORT_CAP_SUBS_READ , SND_SEQ_PORT_TYPE_APPLICATION);
!     //alsa_port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_READ |  SND_SEQ_PORT_CAP_SUBS_READ , SND_SEQ_PORT_TYPE_APPLICATION);
!     if (alsa_port < 0) 
!     {
! 	    sys_setalarm(1000000);
! 	    post("couldn't open alsa MIDI output device");
! 	    return;
      }
      snd_seq_client_info_t *alsainfo;
      snd_seq_client_info_malloc(&alsainfo);
--- 65,85 ----
      for (i=0;i<nmidiout;i++)
      {
+         int port;
          sprintf(portname,"Pure Data Midi-In %d",i+1);
!         port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE , SND_SEQ_PORT_TYPE_APPLICATION);
! 	alsa_midiinfd[i] = port;	
!         if (port < 0) goto error;        
      }
+ 
      for (i=0;i<nmidiin;i++)
      {
+         int port;
          sprintf(portname,"Pure Data Midi-Out %d",i+1);
!         port = snd_seq_create_simple_port(midi_handle,portname,  SND_SEQ_PORT_CAP_SUBS_READ |  SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_APPLICATION);
! 	alsa_midioutfd[i] = port;	
!         if (port < 0) goto error;        
      }
+    
+     if (nmidiout == 0 && nmidiin == 0) return;
      snd_seq_client_info_t *alsainfo;
      snd_seq_client_info_malloc(&alsainfo);
***************
*** 95,102 ****
      client = snd_seq_client_info_get_client(alsainfo);
      snd_seq_set_client_info(midi_handle,alsainfo);
      post("Opened Alsa Client %d in:%d out:%d",client,nmidiin,nmidiout);
      sys_setalarm(0);
      alsa_nmidiout = nmidiout;
!     alsa_initialized = nmidiin;
  }
  
--- 88,102 ----
      client = snd_seq_client_info_get_client(alsainfo);
      snd_seq_set_client_info(midi_handle,alsainfo);
+     snd_seq_client_info_free(alsainfo);
      post("Opened Alsa Client %d in:%d out:%d",client,nmidiin,nmidiout);
      sys_setalarm(0);
+     snd_midi_event_new(20,&midiev);
      alsa_nmidiout = nmidiout;
!     alsa_nmidiin = nmidiin;
!     return;
!   error:
!     sys_setalarm(1000000);
!     post("couldn't open alsa MIDI output device");
!     return;
  }
  
***************
*** 106,115 ****
  void sys_putmidimess(int portno, int a, int b, int c)
  {
! 	    int aa;
! 	    int channel;
!     snd_midi_event_t *dev;
      snd_seq_event_t ev;
      snd_seq_ev_clear(&ev);
-     dev = (snd_midi_event_t*)malloc(30);
      if (portno >= 0 && portno < alsa_nmidiout)
      {
--- 106,112 ----
  void sys_putmidimess(int portno, int a, int b, int c)
  {
!     int channel;
      snd_seq_event_t ev;
      snd_seq_ev_clear(&ev);
      if (portno >= 0 && portno < alsa_nmidiout)
      {
***************
*** 157,160 ****
--- 154,159 ----
  void sys_putmidibyte(int portno, int byte)
  {
+ 
+     post("putmidibyte not implemented, please report as a bug");
  /*    snd_midi_event_t *dev;
      snd_seq_event_t ev;
***************
*** 172,214 ****
  }
  
- #if 0   /* this is the "select" version which doesn't work with OSS
-         driver for emu10k1 (it doesn't implement select.) */
- void sys_poll_midi(void)
- {
-     int i, throttle = 100;
-     struct timeval timout;
-     int did = 1, maxfd = 0;
-     while (did)
-     {
-         fd_set readset, writeset, exceptset;
-         did = 0;
-         if (throttle-- < 0)
-             break;
-         timout.tv_sec = 0;
-         timout.tv_usec = 0;
- 
-         FD_ZERO(&writeset);
-         FD_ZERO(&readset);
-         FD_ZERO(&exceptset);
-         for (i = 0; i < alsa_nmidiin; i++)
-         {
-             if (alsa_midiinfd[i] > maxfd)
-                 maxfd = alsa_midiinfd[i];
-             FD_SET(alsa_midiinfd[i], &readset);
-         }
-         select(maxfd+1, &readset, &writeset, &exceptset, &timout);
-         for (i = 0; i < alsa_nmidiin; i++)
-             if (FD_ISSET(alsa_midiinfd[i], &readset))
-         {
-             char c;
-             int ret = read(alsa_midiinfd[i], &c, 1);
-             if (ret <= 0)
-                 fprintf(stderr, "Midi read error\n");
-             else sys_midibytein(i, (c & 0xff));
-             did = 1;
-         }
-     }
- }
- #else 
  
      /* this version uses the asynchronous "read()" ... */
--- 171,174 ----
***************
*** 218,225 ****
     int count, alsa_source;
     int i;
-    snd_midi_event_t *dev;
     snd_seq_event_t *midievent = NULL;
!    snd_midi_event_new(20,&dev);
!    snd_midi_event_init(dev);
     count = snd_seq_event_input_pending(midi_handle,1);
     if (count != 0)
--- 178,188 ----
     int count, alsa_source;
     int i;
     snd_seq_event_t *midievent = NULL;
! 
!    if (alsa_nmidiout == 0 && alsa_nmidiin == 0) return;
!    
!    snd_midi_event_init(midiev);
! 
!    if (!alsa_nmidiout && !alsa_nmidiin) return;
     count = snd_seq_event_input_pending(midi_handle,1);
     if (count != 0)
***************
*** 227,231 ****
     if (midievent != NULL)
     {
!        count = snd_midi_event_decode(dev,buf,20,midievent);
         alsa_source = midievent->dest.port;
         for(i=0;i<count;i++)
--- 190,194 ----
     if (midievent != NULL)
     {
!        count = snd_midi_event_decode(midiev,buf,20,midievent);
         alsa_source = midievent->dest.port;
         for(i=0;i<count;i++)
***************
*** 233,249 ****
         //post("received %d midi bytes\n",count);
     }
-    snd_midi_event_free(dev);
  }
- #endif
  
  void sys_close_midi()
  {
-     /*int i;
-     for (i = 0; i < alsa_nmidiin; i++)
-         close(alsa_midiinfd[i]);
-     for (i = 0; i < alsa_nmidiout; i++)
-         close(alsa_midioutfd[i]);*/
      alsa_nmidiin = alsa_nmidiout = 0;
      snd_seq_close(midi_handle);
  }
  
--- 196,206 ----
         //post("received %d midi bytes\n",count);
     }
  }
  
  void sys_close_midi()
  {
      alsa_nmidiin = alsa_nmidiout = 0;
      snd_seq_close(midi_handle);
+     snd_midi_event_free(midiev);
  }
  
***************
*** 266,270 ****
          ndev = maxndev;
      for (i = 0; i < ndev; i++)
!         sprintf(indevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
      *nindevs = ndev;
  
--- 223,227 ----
          ndev = maxndev;
      for (i = 0; i < ndev; i++)
!         sprintf(indevlist + i * devdescsize, "ALSA MIDI device #%d", i+1);
      *nindevs = ndev;
  
***************
*** 272,276 ****
          ndev = maxndev;
      for (i = 0; i < ndev; i++)
!         sprintf(outdevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
      *noutdevs = ndev;
  }
--- 229,233 ----
          ndev = maxndev;
      for (i = 0; i < ndev; i++)
!         sprintf(outdevlist + i * devdescsize, "ALSA MIDI device #%d", i+1);
      *noutdevs = ndev;
  }





More information about the Pd-cvs mailing list