9.6.3 Writing a new Event

Suppose we want to fade the volume down to silence using a Gain MarSystem. We
could accomplish this using the scheduler and several EvValUpd events. Assuming
the gain control is at 1.0 to begin we just issue 10 EvValUpd events each with
a progressively lower volume amount: 0.9, 0.8, 0.7, ... and each at a time that
is a little bit later than the previous. This is messy and repetitive. Why not
make a new event, called EvRampCtrl, that encapsulates this behaviour.

We start by defining a new EvRampCtrl class that inherits from the EvEvent
class. We define a constructor that takes a MarSystem to act upon, a control
to modify, a starting value, an ending value, and a step amount. The implicit
assumption is that this event will only work on values of type mrs_real
so that values we supply must all be of the correct type. The header and cpp
files are supplied below.

We will need an additional variable to save the current adjustment value. Also,
the event will need to repeat so we will maintain a repeat flag that is true
until we pass the end value. We override the repeat() method of
EvEvent to return the current value of the repeat flag. The required
variables are shown in the header file below.

The main logic for our event is contained in the dispatch method. Basically, we
check to see if we have passed the end value during ramping and if so set the
repeat flag to false. The next time that the scheduler checks to see if the
event repeats the scheduler will read the false value and delete the event. If
we have not passed the end value then we set the specified control to the
current ramp value and decrement the current value by the ramp amount. The
scheduler will see that the event is to be repeated, it will read the repeat
rate amount, and repost the event to the queue.

9.6.3.1 Expression Events

For a large number of events there is commonality. The Expression syntax
was developed to allow the creation of events without having to code
new custom event classes. In order to accomplish this there is a built
in compiler for the syntax that is invoked when supplying the expression
as a string to the Ex class.