add a raw CoreMidi data debug mode
[ardour.git] / libs / backends / alsa / zita-alsa-pcmi.cc
index 8947e1a12ee70b5f329bfe371ee0e0ba4728f620..3c271b69073806f997e5dc4176ef28199dcf0ef3 100644 (file)
@@ -170,7 +170,11 @@ snd_pcm_sframes_t Alsa_pcmi::pcm_wait (void)
                }
                for (i = 0; i < n2; i++) _poll_fd [i].events |= POLLERR;
 
-               r = poll (_poll_fd, n2, 1000);
+               timespec timeout;
+               timeout.tv_sec = 1;
+               timeout.tv_nsec = 0;
+               r = ppoll (_poll_fd, n2, &timeout, NULL);
+
                if (r < 0)
                {
                        if (errno == EINTR) return 0;
@@ -266,6 +270,9 @@ int Alsa_pcmi::play_init (snd_pcm_uframes_t len)
        const snd_pcm_channel_area_t   *a;
        int                            err;
 
+       if (!_play_handle) {
+               return 0;
+       }
        if ((err = snd_pcm_mmap_begin (_play_handle, &a, &_play_offs, &len)) < 0)
        {
                if (_debug & DEBUG_DATA) fprintf (stderr, "Alsa_pcmi: snd_pcm_mmap_begin(play): %s.\n", snd_strerror (err));
@@ -287,6 +294,10 @@ int Alsa_pcmi::capt_init (snd_pcm_uframes_t len)
        const snd_pcm_channel_area_t  *a;
        int                           err;
 
+       if (!_capt_handle) {
+               return 0;
+       }
+
        if ((err = snd_pcm_mmap_begin (_capt_handle, &a, &_capt_offs, &len)) < 0)
        {
                if (_debug & DEBUG_DATA) fprintf (stderr, "Alsa_pcmi: snd_pcm_mmap_begin(capt): %s.\n", snd_strerror (err));
@@ -322,12 +333,14 @@ void Alsa_pcmi::capt_chan  (int chan, float *dst, int len, int step)
 
 int Alsa_pcmi::play_done (int len)
 {
+       if (!_play_handle) return 0;
        return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
 }
 
 
 int Alsa_pcmi::capt_done (int len)
 {
+       if (!_capt_handle) return 0;
        return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
 }
 
@@ -410,6 +423,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                }
        }
 
+       _state = -2;
        if (_play_handle)
        {
                if (snd_pcm_hw_params_malloc (&_play_hwpar) < 0)
@@ -447,16 +461,19 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                if (snd_pcm_hw_params_get_rate (_play_hwpar, &fsamp, &dir) || (fsamp != _fsamp) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested sample rate for playback.\n");
+                       _state = -3;
                        return;
                }
                if (snd_pcm_hw_params_get_period_size (_play_hwpar, &fsize, &dir) || (fsize != _fsize) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested period size for playback.\n");
+                       _state = -4;
                        return;
                }
                if (snd_pcm_hw_params_get_periods (_play_hwpar, &nfrag, &dir) || (nfrag != _nfrag) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested number of periods for playback.\n");
+                       _state = -5;
                        return;
                }
 
@@ -503,6 +520,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle playback sample format.\n");
+                               _state = -6;
                                return;
                }
 #elif __BYTE_ORDER == __BIG_ENDIAN
@@ -540,6 +558,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle playback sample format.\n");
+                               _state = -6;
                                return;
                }
 #else
@@ -554,16 +573,19 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                if (snd_pcm_hw_params_get_rate (_capt_hwpar, &fsamp, &dir) || (fsamp != _fsamp) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested sample rate for capture.\n");
+                       _state = -3;
                        return;
                }
                if (snd_pcm_hw_params_get_period_size (_capt_hwpar, &fsize, &dir) || (fsize != _fsize) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested period size for capture.\n");
+                       _state = -4;
                        return;
                }
                if (snd_pcm_hw_params_get_periods (_capt_hwpar, &nfrag, &dir) || (nfrag != _nfrag) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested number of periods for capture.\n");
+                       _state = -5;
                        return;
                }
 
@@ -605,6 +627,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle capture sample format.\n");
+                               _state = -6;
                                return;
                }
 #elif __BYTE_ORDER == __BIG_ENDIAN
@@ -636,6 +659,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle capture sample format.\n");
+                               _state = -6;
                                return;
                }
 #else