/[svn]/linuxsampler/trunk/src/network/lscpevent.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/network/lscpevent.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1765 - (show annotations) (download)
Sat Sep 6 16:44:42 2008 UTC (15 years, 7 months ago) by persson
File size: 5114 byte(s)
* refactoring: extracted lscp notification from main() to a separate
  function
* added helper function MidiInputPort::DispatchRaw for midi device
  implementations with raw byte data
* fixed a win32 build error (atomic.h is working on windows too)
* code cleanup: moved lscp classes into LinuxSampler namespace

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 /*********************************************************
25 * This class helps to constuct valid events per
26 * LSCP protocol specification
27 *
28 * It also helps LSCPServer lookup the events when
29 * a client is trying to subscribe to an event
30 *
31 * ******************************************************/
32
33 #include "lscpevent.h"
34
35 #include "../common/global_private.h"
36
37 namespace LinuxSampler {
38
39 std::map<LSCPEvent::event_t, String> LSCPEvent::EventNames = std::map<LSCPEvent::event_t, String>();
40
41 LSCPEvent::LSCPEvent(String eventName) throw (Exception) {
42 for (std::map<event_t, String>::iterator iter = EventNames.begin(); iter != EventNames.end(); iter++) {
43 if (iter->second == eventName) {
44 this->type = iter->first;
45 return;
46 }
47 }
48 throw Exception("Event does not exist");
49 }
50
51 LSCPEvent::LSCPEvent(event_t eventType, int uiData) {
52 this->type = eventType;
53 this->storage = ToString(uiData);
54 }
55
56 LSCPEvent::LSCPEvent(event_t eventType, String sData) {
57 this->type = eventType;
58 this->storage = sData;
59 }
60
61 LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2) {
62 this->type = eventType;
63 this->storage = ToString(uiData1) + " " + ToString(uiData2);
64 }
65
66 LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2, String sData3, int uiData4, int uiData5) {
67 this->type = eventType;
68 this->storage = ToString(uiData1) + " " + ToString(uiData2) + " " +
69 sData3 + " " + ToString(uiData4) + " " + ToString(uiData5);
70 }
71
72 LSCPEvent::LSCPEvent(event_t eventType, String sData, int uiData) {
73 this->type = eventType;
74 this->storage = sData + " " + ToString(uiData);
75 }
76
77 LSCPEvent::LSCPEvent(event_t eventType, String sData, double dData) {
78 this->type = eventType;
79 this->storage = sData + " " + ToString(dData);
80 }
81
82 LSCPEvent::LSCPEvent(event_t eventType, int uiData, String sData) {
83 this->type = eventType;
84 this->storage = ToString(uiData) + " " + sData;
85 }
86
87 LSCPEvent::LSCPEvent(event_t eventType, int uiData1, String sData2, int uiData3, int uiData4) {
88 this->type = eventType;
89 this->storage = ToString(uiData1) + " " + sData2 + " " +
90 ToString(uiData3) + " " + ToString(uiData4);
91 }
92
93 LSCPEvent::LSCPEvent(event_t eventType, int uiData1, int uiData2, int uiData3) {
94 this->type = eventType;
95 this->storage = ToString(uiData1) + " " + ToString(uiData2) + " " + ToString(uiData3);
96 }
97
98 LSCPEvent::LSCPEvent(event_t eventType, String sData1, String sData2, String sData3) {
99 this->type = eventType;
100 this->storage = sData1 + " " + sData2 + " " + sData3;
101 }
102
103 //Produce event string
104 String LSCPEvent::Produce(void) {
105 String result = "NOTIFY:";
106 result += EventNames[type];
107 result += ":";
108 result += storage;
109 result += "\r\n";
110 return result;
111 }
112
113 //This can later return handle and then we can get rid of event_t enum
114 //and make events fully dynamic
115 void LSCPEvent::RegisterEvent(event_t eventType, String EventName) {
116 EventNames[eventType] = EventName;
117 }
118
119 void LSCPEvent::UnregisterEvent(event_t eventType) {
120 EventNames.erase(eventType);
121 }
122
123 //The following static method is used to get names from types
124 String LSCPEvent::Name(event_t eventType) {
125 if (EventNames.count(eventType))
126 return EventNames[eventType];
127 return "UNKNOWN";
128 }
129
130 std::list<LSCPEvent::event_t> LSCPEvent::List( void ) {
131 std::list<event_t> result;
132 for (std::map<event_t, String>::iterator iter = EventNames.begin(); iter != EventNames.end(); iter++)
133 result.push_back(iter->first);
134 return result;
135 }
136
137 }

  ViewVC Help
Powered by ViewVC