]> git.alsa-project.org Git - alsa-lib.git/commitdiff
rawmidi: rename enum snd_rawmidi_framing to snd_rawmidi_read_mode
authorJaroslav Kysela <perex@perex.cz>
Wed, 22 Sep 2021 09:05:23 +0000 (11:05 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 28 Oct 2021 06:40:20 +0000 (08:40 +0200)
We hide the internal data transfers using the data frames. Rename
the snd_rawmidi_framing enum to snd_rawmidi_read_mode to make
API more straight and understandable.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/rawmidi.h
src/rawmidi/rawmidi.c
test/rawmidi.c

index 5f44d3d9c2165ceea53e4d7875cb2e2417dd5aea..716810536a2ea2161be1314d0144cefb14b54297 100644 (file)
@@ -79,7 +79,7 @@ typedef enum _snd_rawmidi_type {
        SND_RAWMIDI_TYPE_VIRTUAL
 } snd_rawmidi_type_t;
 
-/** Type of clock used with rawmidi tstamp framing */
+/** Type of clock used with rawmidi timestamp */
 typedef enum _snd_rawmidi_clock {
        SND_RAWMIDI_CLOCK_NONE = 0,
        SND_RAWMIDI_CLOCK_REALTIME = 1,
@@ -87,11 +87,11 @@ typedef enum _snd_rawmidi_clock {
        SND_RAWMIDI_CLOCK_MONOTONIC_RAW = 3,
 } snd_rawmidi_clock_t;
 
-/** Enable or disable rawmidi framing */
-typedef enum _snd_rawmidi_framing {
-       SND_RAWMIDI_FRAMING_NONE = 0,
-       SND_RAWMIDI_FRAMING_TSTAMP = 1,
-} snd_rawmidi_framing_t;
+/** Select the read mode (standard or with timestamps) */
+typedef enum _snd_rawmidi_read_mode {
+       SND_RAWMIDI_READ_STANDARD = 0,
+       SND_RAWMIDI_READ_TSTAMP = 1,
+} snd_rawmidi_read_mode_t;
 
 int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi,
                     const char *name, int mode);
@@ -140,8 +140,8 @@ int snd_rawmidi_params_set_avail_min(snd_rawmidi_t *rmidi, snd_rawmidi_params_t
 size_t snd_rawmidi_params_get_avail_min(const snd_rawmidi_params_t *params);
 int snd_rawmidi_params_set_no_active_sensing(snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params, int val);
 int snd_rawmidi_params_get_no_active_sensing(const snd_rawmidi_params_t *params);
-int snd_rawmidi_params_set_framing_type(const snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params, snd_rawmidi_framing_t val);
-snd_rawmidi_framing_t snd_rawmidi_params_get_framing_type(const snd_rawmidi_params_t *params);
+int snd_rawmidi_params_set_read_mode(const snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params, snd_rawmidi_read_mode_t val);
+snd_rawmidi_read_mode_t snd_rawmidi_params_get_read_mode(const snd_rawmidi_params_t *params);
 int snd_rawmidi_params_set_clock_type(const snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params, snd_rawmidi_clock_t val);
 snd_rawmidi_clock_t snd_rawmidi_params_get_clock_type(const snd_rawmidi_params_t *params);
 
index bbb025e37812cc6db03b37f914608dca388c4c38..31845e6f1ddd8f5b06a1d4923cd080d8c0e930d8 100644 (file)
@@ -823,38 +823,54 @@ int snd_rawmidi_params_get_no_active_sensing(const snd_rawmidi_params_t *params)
 }
 
 /**
- * \brief enable or disable rawmidi framing
+ * \brief set read mode
  * \param rawmidi RawMidi handle
  * \param params pointer to snd_rawmidi_params_t structure
- * \param val type of rawmidi framing
+ * \param val type of read_mode
  * \return 0 on success, otherwise a negative error code.
  *
  * Notable error codes:
  * -EINVAL - "val" is invalid
- * -ENOTSUP - Kernel is too old to support framing.
+ * -ENOTSUP - mode is not supported
  *
  */
-int snd_rawmidi_params_set_framing_type(const snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params, snd_rawmidi_framing_t val)
+int snd_rawmidi_params_set_read_mode(const snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params, snd_rawmidi_read_mode_t val)
 {
+       unsigned int framing;
        assert(rawmidi && params);
-       if (val > SNDRV_RAWMIDI_MODE_FRAMING_MASK >> SNDRV_RAWMIDI_MODE_FRAMING_SHIFT)
+
+       switch (val) {
+       case SND_RAWMIDI_READ_STANDARD:
+               framing = SNDRV_RAWMIDI_MODE_FRAMING_NONE;
+               break;
+       case SND_RAWMIDI_READ_TSTAMP:
+               framing = SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP;
+               break;
+       default:
                return -EINVAL;
-       if (val != SNDRV_RAWMIDI_MODE_FRAMING_NONE &&
+       }
+
+       if (framing != SNDRV_RAWMIDI_MODE_FRAMING_NONE &&
                (rawmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 2) || rawmidi->stream != SND_RAWMIDI_STREAM_INPUT))
                return -ENOTSUP;
-       params->mode = (params->mode & ~SNDRV_RAWMIDI_MODE_FRAMING_MASK) + (val << SNDRV_RAWMIDI_MODE_FRAMING_SHIFT);
+       params->mode = (params->mode & ~SNDRV_RAWMIDI_MODE_FRAMING_MASK) | framing;
        return 0;
 }
 
 /**
- * \brief get current framing type
+ * \brief get current read mode
  * \param params pointer to snd_rawmidi_params_t structure
- * \return the current type (0 = no framing, 1 = tstamp type framing)
+ * \return the current read mode (see enum)
  */
-snd_rawmidi_framing_t snd_rawmidi_params_get_framing_type(const snd_rawmidi_params_t *params)
+snd_rawmidi_read_mode_t snd_rawmidi_params_get_read_mode(const snd_rawmidi_params_t *params)
 {
+       unsigned int framing;
+
        assert(params);
-       return (params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK) >> SNDRV_RAWMIDI_MODE_FRAMING_SHIFT;
+       framing = params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK;
+       if (framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP)
+               return SND_RAWMIDI_READ_TSTAMP;
+       return SND_RAWMIDI_READ_STANDARD;
 }
 
 /**
index 357abbe4f95b3e716846dd85dbcb435bf5e7669c..666acf63f41677b376e908a63b6ffc280b1b917d 100644 (file)
@@ -151,9 +151,9 @@ int main(int argc,char** argv)
                                if (clock_type != -1) {
                                        fprintf(stderr, "Enable kernel clock type %d\n", clock_type);
                                        snd_rawmidi_params_current(handle_in, params);
-                                       err = snd_rawmidi_params_set_framing_type(handle_in, params, 1);
+                                       err = snd_rawmidi_params_set_read_mode(handle_in, params, SND_RAWMIDI_READ_TSTAMP);
                                        if (err) {
-                                               fprintf(stderr,"snd_rawmidi_params_set_framing_type failed: %d\n", err);
+                                               fprintf(stderr,"snd_rawmidi_params_set_read_mode failed: %d\n", err);
                                                clock_type = -1;
                                        }
                                }