forked from recotana/ArdOSC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern.cpp
More file actions
88 lines (63 loc) · 2.25 KB
/
Pattern.cpp
File metadata and controls
88 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
ArdOSC 2.1 - OSC Library for Arduino.
(RoboCore v_1.0)
-------- License -----------------------------------------------------------
ArdOSC
The MIT License
Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved
+ updates by RoboCore ( http://www.RoboCore.net/ )
*/
#include <stdlib.h>
#include <string.h>
#include "OSCCommon/OSCServer.h"
#include "OSCCommon/OSCcommon.h"
#include "OSCCommon/OSCMessage.h"
#include "OSCCommon/Pattern.h"
#ifdef USE_WILDCARD
#include <String_Functions.h> //instead of using the String class (used by djspark)
#endif
//----------------------------------------------------------------------------
Pattern::Pattern(){
patternNum = 0;
}
//----------------------------------------------------------------------------
Pattern::~Pattern(){
}
//----------------------------------------------------------------------------
void Pattern::addOscAddress(char *_adr , AdrFunc _func){
//check for array limit
if(patternNum >= kMaxPatternMatch)
return;
adrFunc[patternNum] = _func;
addr[patternNum] = _adr;
patternNum++;
}
//----------------------------------------------------------------------------
void Pattern::execFunc(uint8_t _index,OSCMessage *_mes){
adrFunc[_index](_mes);
}
//----------------------------------------------------------------------------
void Pattern::paternComp(OSCMessage *_mes){
for (uint8_t i=0 ; i < patternNum ; i++) {
#ifdef USE_WILDCARD
//supports calls to addresses with wildcard at the end
// uses <String_Functions.h> instead of String class, supposedly with
// bugs and to avoid memory allocation
// (based on code written by djspark - https://github.com/djspark)
int pos = StrFind(addr[i], '^');
int addr_len = StrLength(addr[i]) - 1; //subtract the last character ('^')
if(pos == addr_len){ //found valid address with wildcard
int comparison = StrCompare(_mes->_oscAddress, addr[i], 0, addr_len);
if(comparison == addr_len) //addresses are equal
execFunc(i, _mes);
} else {
if(strcmp(addr[i], _mes->_oscAddress) == 0)
execFunc(i, _mes);
}
#else
if(strcmp(addr[i], _mes->_oscAddress) == 0)
execFunc( i , _mes );
#endif
}
}
//----------------------------------------------------------------------------