2013-07-17 09:55:20 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-07-17 09:55:20 -04:00
|
|
|
|
|
|
|
#ifndef __ardour_msvc_extensions_h__
|
|
|
|
#define __ardour_msvc_extensions_h__
|
|
|
|
|
2020-03-26 06:40:36 -04:00
|
|
|
#ifdef WINVER
|
|
|
|
#undef WINVER
|
2013-07-17 09:55:20 -04:00
|
|
|
#endif
|
2020-03-26 06:40:36 -04:00
|
|
|
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) /* 1900 is an arbitrary value, corresponding to VS2019 (it might need to be lowered) */
|
|
|
|
#define WINVER 0x0500
|
|
|
|
#else
|
|
|
|
#define WINVER 0x0601
|
|
|
|
#endif
|
|
|
|
#ifdef _WIN32_WINNT
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#endif
|
|
|
|
#define _WIN32_WINNT WINVER
|
|
|
|
|
2013-07-17 09:55:20 -04:00
|
|
|
#ifndef _CPP_VECTOR
|
|
|
|
#define _CPP_VECTOR 1
|
|
|
|
#endif
|
|
|
|
|
2013-08-27 12:10:46 -04:00
|
|
|
#ifdef __cplusplus
|
2013-07-17 09:55:20 -04:00
|
|
|
#include <vector>
|
2013-08-27 12:10:46 -04:00
|
|
|
#endif
|
|
|
|
|
2013-07-17 09:55:20 -04:00
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#include <boost/regex.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <ardourext/float_cast.h>
|
|
|
|
|
|
|
|
// 'INFINITY' is not defined in MSVC. Assume 'HUGE_VAL'
|
|
|
|
#ifndef INFINITY
|
|
|
|
#define INFINITY HUGE_VAL
|
|
|
|
#endif
|
|
|
|
|
2016-05-03 12:30:58 -04:00
|
|
|
#ifndef NAN
|
|
|
|
#define NAN _NANCODE
|
|
|
|
#endif
|
|
|
|
|
2013-07-17 09:55:20 -04:00
|
|
|
// File access modes copied from unistd.h
|
|
|
|
#define F_OK 0
|
|
|
|
#define R_OK 4
|
|
|
|
#define W_OK 2
|
|
|
|
#define X_OK 1
|
|
|
|
|
|
|
|
// Miscellaneous #defines
|
2021-01-30 08:55:25 -05:00
|
|
|
// JE - (these ones believed to be no longer needed from VS2015 onward)
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
2013-07-17 09:55:20 -04:00
|
|
|
#define __attribute__(x)
|
|
|
|
#define llabs _abs64
|
|
|
|
#define atoll _atoi64
|
|
|
|
#define access _access
|
|
|
|
#define getcwd _getcwd
|
|
|
|
#define getpid _getpid
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#define link ntfs_link
|
|
|
|
#define unlink ntfs_unlink
|
2021-01-30 08:55:25 -05:00
|
|
|
#endif
|
|
|
|
#define random rand
|
2013-07-17 09:55:20 -04:00
|
|
|
#define strcasecmp stricmp
|
|
|
|
#define strncasecmp strnicmp
|
|
|
|
#define strtok_r( _s, _sep, _lasts ) \
|
|
|
|
( *(_lasts) = strtok( (_s), (_sep) ) )
|
|
|
|
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
#define PATH_MAX _MAX_PATH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Types missing from Win32 'stat.h' (hopefully Windows
|
|
|
|
// will either act sensibly or ignore most of them).
|
|
|
|
#define _S_IFBLK 0x3000
|
|
|
|
#define S_IRWXU _S_IRWXU
|
|
|
|
#define S_IXUSR _S_IXUSR
|
|
|
|
#define S_IWUSR _S_IWUSR
|
|
|
|
#define S_IRUSR _S_IRUSR
|
|
|
|
#define S_IXGRP _S_IXGRP
|
|
|
|
#define S_IWGRP _S_IWGRP
|
|
|
|
#define S_IRGRP _S_IRGRP
|
|
|
|
#define S_IXOTH _S_IXOTH
|
|
|
|
#define S_IWOTH _S_IWOTH
|
|
|
|
#define S_IROTH _S_IROTH
|
|
|
|
|
|
|
|
#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
|
|
|
|
#define _S_IXUSR _S_IEXEC
|
|
|
|
#define _S_IWUSR _S_IWRITE
|
|
|
|
#define _S_IRUSR _S_IREAD
|
|
|
|
#define _S_IXGRP _S_IEXEC
|
|
|
|
#define _S_IWGRP _S_IWRITE
|
|
|
|
#define _S_IRGRP _S_IREAD
|
|
|
|
#define _S_IXOTH _S_IEXEC
|
|
|
|
#define _S_IWOTH _S_IWRITE
|
|
|
|
#define _S_IROTH _S_IREAD
|
|
|
|
|
|
|
|
#define S_ISFIFO(m) _S_ISFIFO(m)
|
|
|
|
#define S_ISDIR(m) _S_ISDIR(m)
|
|
|
|
#define S_ISCHR(m) _S_ISCHR(m)
|
|
|
|
#define S_ISBLK(m) _S_ISBLK(m)
|
|
|
|
#define S_ISREG(m) _S_ISREG(m)
|
|
|
|
|
|
|
|
#define _S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
|
|
|
|
#define _S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
|
|
|
#define _S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR)
|
|
|
|
#define _S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK)
|
|
|
|
#define _S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__USE_BSD) || defined(_BSD_SOURCE)
|
|
|
|
/* Convenience macros for operations on timevals.
|
|
|
|
NOTE: `timercmp' does not work for >= or <=.
|
|
|
|
Note also that 'timerset', 'timerclear' and
|
|
|
|
'timercmp' are (perhaps strangely) already
|
|
|
|
defined, along with various other 'time'
|
|
|
|
functions in WinSock.h */
|
|
|
|
# define timeradd(a, b, result) \
|
|
|
|
do { \
|
|
|
|
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
|
|
|
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
|
|
|
if ((result)->tv_usec >= 1000000) \
|
|
|
|
{ \
|
|
|
|
++(result)->tv_sec; \
|
|
|
|
(result)->tv_usec -= 1000000; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
# define timersub(a, b, result) \
|
|
|
|
do { \
|
|
|
|
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
|
|
|
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
|
|
|
if ((result)->tv_usec < 0) { \
|
|
|
|
--(result)->tv_sec; \
|
|
|
|
(result)->tv_usec += 1000000; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif /* BSD */
|
|
|
|
|
|
|
|
#if !defined(__BIT_TYPES_DEFINED) || !defined(__BIT_TYPES_DEFINED__)
|
|
|
|
#define __BIT_TYPES_DEFINED__ 1
|
|
|
|
// Doesn't yet define all 'bit types'. Only those
|
|
|
|
// needed by Ardour. More can be added as needed.
|
|
|
|
#ifndef __int8_t_defined
|
|
|
|
#define __int8_t_defined
|
|
|
|
typedef unsigned char u_int8_t;
|
|
|
|
typedef unsigned short int u_int16_t;
|
|
|
|
typedef unsigned int u_int32_t;
|
|
|
|
typedef unsigned __int64 u_int64_t;
|
|
|
|
|
|
|
|
typedef signed char int8_t;
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
typedef short int16_t;
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
typedef int int32_t;
|
|
|
|
typedef unsigned uint32_t;
|
|
|
|
typedef long long int64_t;
|
|
|
|
typedef unsigned long long uint64_t;
|
|
|
|
#endif // __int8_t
|
|
|
|
|
|
|
|
#ifndef __register_t_defined
|
|
|
|
#define __register_t_defined
|
|
|
|
typedef int register_t;
|
|
|
|
#endif // __register_t
|
|
|
|
#endif // __BIT_TYPESD
|
|
|
|
|
|
|
|
// throw()
|
|
|
|
#ifndef __THROW
|
2013-08-27 12:10:46 -04:00
|
|
|
#ifdef __cplusplus
|
2013-07-17 09:55:20 -04:00
|
|
|
#define __THROW throw()
|
2013-08-27 12:10:46 -04:00
|
|
|
#else
|
|
|
|
#define __THROW
|
|
|
|
#endif
|
2013-07-17 09:55:20 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// System V compatibility
|
|
|
|
typedef unsigned short ushort;
|
|
|
|
typedef unsigned int uint;
|
|
|
|
|
|
|
|
// mode_t
|
|
|
|
#ifndef _MODE_T_
|
|
|
|
#define _MODE_T_
|
|
|
|
typedef unsigned short _mode_t;
|
|
|
|
|
|
|
|
#ifndef NO_OLDNAMES
|
|
|
|
typedef _mode_t mode_t;
|
|
|
|
#endif /* NO_OLDNAMES */
|
|
|
|
#endif /* _MODE_T_ */
|
|
|
|
|
2013-08-04 10:36:07 -04:00
|
|
|
// int64 abs()
|
2016-09-30 03:24:51 -04:00
|
|
|
#if (defined(_MSC_VER) && (_MSC_VER < 1500))
|
2013-08-27 12:10:46 -04:00
|
|
|
#ifdef __cplusplus // Normal 'C' doesn't permit over-ridden functions !!
|
2014-06-04 13:12:30 -04:00
|
|
|
inline int64_t abs(int64_t val) throw()
|
2013-08-04 10:36:07 -04:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
return val * (-1);
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
2013-08-27 12:10:46 -04:00
|
|
|
#endif
|
2016-09-30 03:24:51 -04:00
|
|
|
#endif
|
2013-08-04 10:36:07 -04:00
|
|
|
|
2021-01-30 08:55:25 -05:00
|
|
|
// fmin() and fmax() etc.
|
2020-03-26 06:40:36 -04:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
2020-06-20 04:38:00 -04:00
|
|
|
#define fmin(a, b) __min((double)a, (double)b)
|
|
|
|
#define fmax(a, b) __max((double)a, (double)b)
|
2021-01-30 08:55:25 -05:00
|
|
|
|
|
|
|
// 'std::isnan()' is not available in early versions of MSVC. Assume '_isnan(double)'
|
|
|
|
#define isnan(val) _isnan((double)val)
|
|
|
|
|
|
|
|
// 'std::isinf()' is not available in early versions of MSVC. Assume '!_finite(double)'
|
|
|
|
#define isinf(val) !_finite((double)val)
|
|
|
|
|
2020-03-26 06:40:36 -04:00
|
|
|
#endif
|
2013-07-17 09:55:20 -04:00
|
|
|
|
|
|
|
// approximate POSIX pipe()
|
|
|
|
#define pipe(handles) _pipe(handles, 4096, _O_BINARY)
|
|
|
|
|
|
|
|
// Windows mkdir() doesn't care about access privileges
|
|
|
|
#define mkdir(path, mode) _mkdir(path)
|
|
|
|
|
|
|
|
// Redefine 'ftruncate()' to use the glib-win32 version
|
|
|
|
#define ftruncate(fd, len) g_win32_ftruncate((gint)fd, (guint)len)
|
|
|
|
|
|
|
|
|
|
|
|
// #include the main headers for Ardour MSVC
|
2013-08-27 12:10:46 -04:00
|
|
|
#ifdef __cplusplus
|
2014-01-13 05:22:31 -05:00
|
|
|
#if defined(LIBPBD_DLL) || defined(PBD_IS_IN_WIN_STATIC_LIB)
|
2013-07-17 09:55:20 -04:00
|
|
|
#include <pbd/msvc_pbd.h>
|
2014-01-13 05:22:31 -05:00
|
|
|
|
|
|
|
#ifdef LIBPBD_DLL
|
|
|
|
#define DEFAULT_COMPARISONS_DEFINED
|
|
|
|
#define DECLARE_DEFAULT_COMPARISONS(Type) \
|
|
|
|
LIBPBD_API bool operator > (const Type& lhs, const Type& rhs); \
|
|
|
|
LIBPBD_API bool operator < (const Type& lhs, const Type& rhs); \
|
|
|
|
LIBPBD_API bool operator != (const Type& lhs, const Type& rhs); \
|
|
|
|
LIBPBD_API bool operator == (const Type& lhs, const Type& rhs);
|
|
|
|
#endif
|
2013-07-17 09:55:20 -04:00
|
|
|
#endif
|
|
|
|
#if defined(BUILDING_LIBARDOUR) || defined(LIBARDOUR_IS_IN_WIN_STATIC_LIB)
|
|
|
|
#include <ardour/msvc_libardour.h>
|
|
|
|
#endif
|
|
|
|
#if defined(BUILDING_RUBBERBAND) || defined(RUBBERBAND_IS_IN_WIN_STATIC_LIB)
|
|
|
|
#include <rubberband/msvc_rubberband.h>
|
|
|
|
#endif
|
2013-08-27 12:10:46 -04:00
|
|
|
#endif // __cplusplus
|
2013-07-17 09:55:20 -04:00
|
|
|
|
2014-01-13 05:22:31 -05:00
|
|
|
#ifndef DEFAULT_COMPARISONS_DEFINED
|
|
|
|
#define DEFAULT_COMPARISONS_DEFINED
|
|
|
|
#define DECLARE_DEFAULT_COMPARISONS(Type) \
|
|
|
|
extern bool operator > (const Type& lhs, const Type& rhs); \
|
|
|
|
extern bool operator < (const Type& lhs, const Type& rhs); \
|
|
|
|
extern bool operator != (const Type& lhs, const Type& rhs); \
|
|
|
|
extern bool operator == (const Type& lhs, const Type& rhs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(LIBPBD_API) || defined(PBD_IS_IN_WIN_STATIC_LIB)
|
2016-05-28 14:07:22 -04:00
|
|
|
// Emulate some C99 math functions which MSVC itself didn't
|
|
|
|
// implement until later in life.
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
|
|
|
extern double expm1(double x);
|
|
|
|
extern double log1p(double x);
|
2016-08-19 07:56:34 -04:00
|
|
|
extern double round(double x);
|
|
|
|
extern float roundf(float x);
|
2016-05-28 14:07:22 -04:00
|
|
|
#endif
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
|
|
|
extern double log2 (double x);
|
2016-08-19 07:56:34 -04:00
|
|
|
extern double trunc(double x);
|
2016-05-28 14:07:22 -04:00
|
|
|
#endif
|
2014-01-13 05:22:31 -05:00
|
|
|
#endif
|
|
|
|
|
2013-07-17 09:55:20 -04:00
|
|
|
#endif /* __ardour_msvc_extensions_h__ */
|