1 /*
2  * libInstPatch
3  * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; version 2.1
8  * of the License only.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA or on the web at http://www.gnu.org.
19  */
20 /*
21  * ipatch_priv.h - Private header file
22  */
23 #ifndef __IPATCH_PRIV_H__
24 #define __IPATCH_PRIV_H__
25 
26 #include <glib.h>
27 #include "IpatchItem.h"
28 #include "marshals.h"
29 #include "misc.h"
30 #include "i18n.h"
31 
32 #if HAVE_IO_H
33 #include <io.h> // _lseek(), _close(), _read(), _write() on windows
34 #endif
35 
36 #if HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39 
40 /*
41    In case of cross compiling from Linux to Win32, unistd.h and io.h
42    may be both present.
43    So, we provide here exclusive macros definition for files i/o.
44 */
45 #ifdef _WIN32
46 /* seek in file described by its file descriptor fd */
47 #define IPATCH_FD_LSEEK(fd, offset,origin) _lseek(fd, offset, origin)
48 /* read from file described by its file descriptor fd */
49 #define IPATCH_FD_READ(fd, bufdst, count)  _read(fd, bufdst, count)
50 /* read to file described by its file descriptor fd */
51 #define IPATCH_FD_WRITE(fd, bufsrc, count) _write(fd, bufsrc, count)
52 /* close a file described by its file descriptor fd */
53 #define IPATCH_FD_CLOSE(fd) _close(fd)
54 #else
55 #define IPATCH_FD_LSEEK(fd, offset,origin) lseek(fd, offset, origin)
56 #define IPATCH_FD_READ(fd, bufdst, count)  read(fd, bufdst, count)
57 #define IPATCH_FD_WRITE(fd, bufsrc, count) write(fd, bufsrc, count)
58 #define IPATCH_FD_CLOSE(fd) close(fd)
59 #endif
60 
61 #define IPATCH_UNTITLED		_("Untitled")
62 
63 /* macro for getting a GParamSpec property ID (FIXME - its a private field!) */
64 #define IPATCH_PARAM_SPEC_ID(pspec)    ((pspec)->param_id)
65 
66 /* size of buffers used for transfering sample data (in bytes)
67    Must be a multiple of 16 bytes */
68 #define IPATCH_SAMPLE_COPY_BUFFER_SIZE  (32 * 1024)
69 
70 /* Size of transform buffers used by IpatchSampleTransform objects in pool */
71 #define IPATCH_SAMPLE_TRANS_BUFFER_SIZE  (32 * 1024)
72 
73 /* size of buffers used for copying data */
74 #define IPATCH_COPY_BUFFER_SIZE (32 * 1024)
75 
76 /* So we can start using the glib 2.10 allocator now */
77 #ifndef g_slice_new
78 #define g_slice_new(type)        g_new (type, 1)
79 #define g_slice_new0(type)       g_new0 (type, 1)
80 #define g_slice_free(type, mem)  g_free (mem)
81 #define g_slice_alloc(size)      g_malloc(size)
82 #define g_slice_free1(size, mem) g_free (mem)
83 #endif
84 
85 /* can be used in place of g_assert_not_reached, for g_return(_val)_if_fail
86    to print error and return instead of terminating program */
87 #define NOT_REACHED 0
88 
89 #ifdef __GNUC__
90 
91 #define log_if_fail(expr)  (!(expr) && \
92       _ret_g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
93 	     "file %s: line %d (%s): assertion `%s' failed.", \
94 	     __FILE__, __LINE__, __PRETTY_FUNCTION__, \
95 	     #expr))
96 
97 #else  /* !GNUC */
98 
99 #define log_if_fail(expr)  (!(expr) && \
100       _ret_g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
101 	     "file %s: line %d: assertion `%s' failed.", \
102 	     __FILE__, __LINE__, \
103 	     #expr))
104 #endif
105 
106 
107 int _ret_g_log(const gchar *log_domain, GLogLevelFlags log_level,
108                const gchar *format, ...);
109 
110 #endif
111