Mercurial > hg > beaglert
comparison projects/heavy/samphold/MessageQueue.h @ 160:5bcf04234f80 heavy-updated
- added -std=c99 to Makefile for user-supplied C files (required for heavy files)
- changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff)
- use build_pd.sh to compile and run pd files (-h for usage instructions)
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Thu, 05 Nov 2015 18:58:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
159:1e7db6610600 | 160:5bcf04234f80 |
---|---|
1 /** | |
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd. | |
3 * | |
4 * Permission to use, copy, modify, and/or distribute this software for any | |
5 * purpose with or without fee is hereby granted, provided that the above | |
6 * copyright notice and this permission notice appear in all copies. | |
7 * | |
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | |
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | |
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
14 * PERFORMANCE OF THIS SOFTWARE. | |
15 */ | |
16 | |
17 #ifndef _MESSAGE_QUEUE_H_ | |
18 #define _MESSAGE_QUEUE_H_ | |
19 | |
20 #include "HvMessage.h" | |
21 #include "MessagePool.h" | |
22 | |
23 struct HvBase; | |
24 | |
25 typedef struct MessageNode { | |
26 struct MessageNode *prev; // doubly linked list | |
27 struct MessageNode *next; | |
28 HvMessage *m; | |
29 void (*sendMessage)(struct HvBase *, int, const HvMessage *); | |
30 int let; | |
31 } MessageNode; | |
32 | |
33 /** A doubly linked list containing scheduled messages. */ | |
34 typedef struct MessageQueue { | |
35 MessageNode *head; // the head of the queue | |
36 MessageNode *tail; // the tail of the queue | |
37 MessageNode *pool; // the head of the reserve pool | |
38 MessagePool mp; | |
39 } MessageQueue; | |
40 | |
41 hv_size_t mq_init(MessageQueue *q); | |
42 | |
43 void mq_initWithPoolSize(MessageQueue *q, hv_size_t poolSizeKB); | |
44 | |
45 void mq_free(MessageQueue *q); | |
46 | |
47 int mq_size(MessageQueue *q); | |
48 | |
49 static inline HvMessage *mq_node_getMessage(MessageNode *n) { | |
50 return n->m; | |
51 } | |
52 | |
53 static inline int mq_node_getLet(MessageNode *n) { | |
54 return n->let; | |
55 } | |
56 | |
57 static inline bool mq_hasMessage(MessageQueue *q) { | |
58 return (q->head != NULL); | |
59 } | |
60 | |
61 // true if there is a message and it occurs before (<) timestamp | |
62 static inline bool mq_hasMessageBefore(MessageQueue *const q, const hv_uint32_t timestamp) { | |
63 return mq_hasMessage(q) && (msg_getTimestamp(mq_node_getMessage(q->head)) < timestamp); | |
64 } | |
65 | |
66 static inline MessageNode *mq_peek(MessageQueue *q) { | |
67 return q->head; | |
68 } | |
69 | |
70 /** Appends the message to the end of the queue. */ | |
71 HvMessage *mq_addMessage(MessageQueue *q, const HvMessage *m, int let, | |
72 void (*sendMessage)(struct HvBase *, int, const HvMessage *)); | |
73 | |
74 /** Insert in ascending order the message acccording to its timestamp. */ | |
75 HvMessage *mq_addMessageByTimestamp(MessageQueue *q, HvMessage *m, int let, | |
76 void (*sendMessage)(struct HvBase *, int, const HvMessage *)); | |
77 | |
78 /** Pop the message at the head of the queue (and free its memory). */ | |
79 void mq_pop(MessageQueue *q); | |
80 | |
81 /** Remove a message from the queue (and free its memory) */ | |
82 void mq_removeMessage(MessageQueue *q, HvMessage *m, | |
83 void (*sendMessage)(struct HvBase *, int, const HvMessage *)); | |
84 | |
85 /** Clears (and frees) all messages in the queue. */ | |
86 void mq_clear(MessageQueue *q); | |
87 | |
88 /** Removes all messages occuring at or after the given timestamp. */ | |
89 void mq_clearAfter(MessageQueue *q, const double timestamp); | |
90 | |
91 #endif // _MESSAGE_QUEUE_H_ |