2000-12-21 20:44:10 +00:00
|
|
|
/*
|
|
|
|
|
* Interval inlines
|
|
|
|
|
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
#ifdef SND_INTERVAL_C
|
2000-12-21 20:44:10 +00:00
|
|
|
#define INLINE inline
|
|
|
|
|
#else
|
2000-12-29 15:00:53 +00:00
|
|
|
#define INLINE extern inline
|
2000-12-21 20:44:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE void snd_interval_any(snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-15 11:06:53 +00:00
|
|
|
i->min = 0;
|
|
|
|
|
i->openmin = 0;
|
2000-12-21 20:44:10 +00:00
|
|
|
i->max = UINT_MAX;
|
2001-01-15 11:06:53 +00:00
|
|
|
i->openmax = 0;
|
|
|
|
|
i->integer = 0;
|
|
|
|
|
i->empty = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE void snd_interval_none(snd_interval_t *i)
|
2001-01-15 11:06:53 +00:00
|
|
|
{
|
|
|
|
|
i->empty = 1;
|
2000-12-21 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_checkempty(const snd_interval_t *i)
|
2000-12-23 10:14:15 +00:00
|
|
|
{
|
|
|
|
|
return (i->min > i->max ||
|
|
|
|
|
(i->min == i->max && (i->openmin || i->openmax)));
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_empty(const snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
|
|
|
|
return i->empty;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_single(const snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
assert(!snd_interval_empty(i));
|
2000-12-21 20:44:10 +00:00
|
|
|
return (i->min == i->max ||
|
|
|
|
|
(i->min + 1 == i->max && i->openmax));
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_value(const snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
assert(snd_interval_single(i));
|
2000-12-21 20:44:10 +00:00
|
|
|
return i->min;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_min(const snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
assert(!snd_interval_empty(i));
|
2000-12-21 20:44:10 +00:00
|
|
|
return i->min;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_max(const snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
assert(!snd_interval_empty(i));
|
2001-01-15 11:06:53 +00:00
|
|
|
return i->max;
|
2000-12-21 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_test(const snd_interval_t *i, unsigned int val)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
|
|
|
|
return !((i->min > val || (i->min == val && i->openmin) ||
|
|
|
|
|
i->max < val || (i->max == val && i->openmax)));
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE void snd_interval_copy(snd_interval_t *d, const snd_interval_t *s)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
|
|
|
|
*d = *s;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_setinteger(snd_interval_t *i)
|
2001-01-15 11:06:53 +00:00
|
|
|
{
|
|
|
|
|
if (i->integer)
|
|
|
|
|
return 0;
|
|
|
|
|
if (i->openmin && i->openmax && i->min == i->max)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
i->integer = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE void snd_interval_floor(snd_interval_t *i)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
if (i->integer || snd_interval_empty(i))
|
2001-01-15 11:06:53 +00:00
|
|
|
return;
|
|
|
|
|
i->openmin = 0;
|
2001-01-19 18:28:50 +00:00
|
|
|
if (i->openmax) {
|
|
|
|
|
i->max--;
|
|
|
|
|
i->openmax = 0;
|
|
|
|
|
}
|
2001-01-15 11:06:53 +00:00
|
|
|
i->integer = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE void snd_interval_unfloor(snd_interval_t *i)
|
2001-01-19 18:28:50 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
if (snd_interval_empty(i))
|
2001-01-19 18:28:50 +00:00
|
|
|
return;
|
|
|
|
|
if (i->max == UINT_MAX)
|
|
|
|
|
return;
|
|
|
|
|
if (i->openmax)
|
|
|
|
|
return;
|
|
|
|
|
i->max++;
|
|
|
|
|
i->openmax = 1;
|
|
|
|
|
i->integer = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_always_eq(const snd_interval_t *i1, const snd_interval_t *i2)
|
2001-01-15 11:06:53 +00:00
|
|
|
{
|
2001-01-30 16:51:26 +00:00
|
|
|
return snd_interval_single(i1) && snd_interval_single(i2) &&
|
|
|
|
|
snd_interval_value(i1) == snd_interval_value(i2);
|
2000-12-21 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-30 16:51:26 +00:00
|
|
|
INLINE int snd_interval_never_eq(const snd_interval_t *i1, const snd_interval_t *i2)
|
2000-12-21 20:44:10 +00:00
|
|
|
{
|
2001-01-15 11:06:53 +00:00
|
|
|
|
|
|
|
|
return (i1->max < i2->min ||
|
|
|
|
|
(i1->max == i2->min &&
|
|
|
|
|
(i1->openmax || i1->openmin)) ||
|
|
|
|
|
i1->min > i2->max ||
|
|
|
|
|
(i1->min == i2->max &&
|
|
|
|
|
(i1->openmin || i2->openmax)));
|
2000-12-21 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
|
|
|
|
|
|