1 //-----------------------------------------------------------------------------
2 // Project     : VST SDK
3 //
4 // Category    : Helpers
5 // Filename    : public.sdk/source/vst/hosting/eventlist.cpp
6 // Created by  : Steinberg, 03/05/2008.
7 // Description : VST 3 event list implementation
8 //
9 //-----------------------------------------------------------------------------
10 // LICENSE
11 // (c) 2020, Steinberg Media Technologies GmbH, All Rights Reserved
12 //-----------------------------------------------------------------------------
13 // Redistribution and use in source and binary forms, with or without modification,
14 // are permitted provided that the following conditions are met:
15 //
16 //   * Redistributions of source code must retain the above copyright notice,
17 //     this list of conditions and the following disclaimer.
18 //   * Redistributions in binary form must reproduce the above copyright notice,
19 //     this list of conditions and the following disclaimer in the documentation
20 //     and/or other materials provided with the distribution.
21 //   * Neither the name of the Steinberg Media Technologies nor the names of its
22 //     contributors may be used to endorse or promote products derived from this
23 //     software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED
34 // OF THE POSSIBILITY OF SUCH DAMAGE.
35 //-----------------------------------------------------------------------------
36 
37 #include "eventlist.h"
38 
39 namespace Steinberg {
40 namespace Vst {
41 
42 //-----------------------------------------------------------------------------
IMPLEMENT_FUNKNOWN_METHODS(EventList,IEventList,IEventList::iid)43 IMPLEMENT_FUNKNOWN_METHODS (EventList, IEventList, IEventList::iid)
44 
45 //-----------------------------------------------------------------------------
46 EventList::EventList (int32 maxSize) : events (nullptr), maxSize (maxSize), fillCount (0)
47 {
48 	FUNKNOWN_CTOR
49 	setMaxSize (maxSize);
50 }
51 
52 //-----------------------------------------------------------------------------
~EventList()53 EventList::~EventList ()
54 {
55 	setMaxSize (0);
56 	FUNKNOWN_DTOR
57 }
58 
59 //-----------------------------------------------------------------------------
setMaxSize(int32 _maxSize)60 void EventList::setMaxSize (int32 _maxSize)
61 {
62 	if (events)
63 	{
64 		delete[] events;
65 		events = nullptr;
66 	}
67 	if (_maxSize > 0)
68 		events = new Event[_maxSize];
69 	maxSize = _maxSize;
70 }
71 
72 //-----------------------------------------------------------------------------
getEvent(int32 index,Event & e)73 tresult PLUGIN_API EventList::getEvent (int32 index, Event& e)
74 {
75 	if (fillCount > index)
76 	{
77 		memcpy (&e, &events[index], sizeof (Event));
78 		return kResultTrue;
79 	}
80 	return kResultFalse;
81 }
82 
83 //-----------------------------------------------------------------------------
addEvent(Event & e)84 tresult PLUGIN_API EventList::addEvent (Event& e)
85 {
86 	if (maxSize > fillCount)
87 	{
88 		memcpy (&events[fillCount], &e, sizeof (Event));
89 		fillCount++;
90 		return kResultTrue;
91 	}
92 	return kResultFalse;
93 }
94 
95 //-----------------------------------------------------------------------------
getEventByIndex(int32 index)96 Event* EventList::getEventByIndex (int32 index)
97 {
98 	if (index < fillCount)
99 		return &events[index];
100 	return nullptr;
101 }
102 
103 //------------------------------------------------------------------------
104 } // namespace Vst
105 } // namespace Steinberg
106