com.e1.mxdublin.evlist
Class EvAbstractItem

java.lang.Object
  extended by com.e1.mxdublin.core.SeqEvent
      extended by com.e1.mxdublin.evlist.EvAbstractItem
All Implemented Interfaces:
Cloneable, Comparable<EvAbstractItem>, Runnable
Direct Known Subclasses:
EvAction, EvSender

public abstract class EvAbstractItem
extends SeqEvent
implements Cloneable, Comparable<EvAbstractItem>

Basic type for any event that is added to an event list. Objects that extends this class must implement the method play() that will activate the event. If the event must be stopped (like a midi note), the extended class must initialize the field len_tm that tells event duration and implement the method stop() that will de-activate the event.

Constructors and string arguments construction.

Event are design to be instanciated from a single string. First it simplify the process if the event can have mutliple arguments but only one is always used without the need of creating multiple constructors for each arguments. It also enable the event to be edited in the tracker GUI utility. setValue() is used to assign the event using a string argument. getValue() is also used to get the event content in a string format. This also enable the event to be fully serializable from XML form since the arguments is a simple string.

The character "@", "/" have special propose in event definition and they must not be used.

Properties and GroupProperties

Properties are used to share a common value across events. For example, with EvSender, the property @sender is used to assign the destination of the event to a specific pd/max receiver. They are specified in the string event constructor argument with the character (@).

GroupProperties are used to share common properties (like senders) to multiples event items. They are specified in the event arguments by using the property name gp. For example, @gp tata, will ask the event to assign each supported properties defined in the group-properties named tata.

Event serialization

To be able to save the content of the event, the most simple way is to simply override getValue() method and return the string content of the event. If the event has properties, it must also append the values of the overriden properties with method appendDefineProperties(String, String). If your event cannot be simplified into a string, you can override the method toXML() to add content to the XML element. loadElement() must also be overriden to read the new content into the event.

Note: this class has a natural ordering that is inconsistent with equals.


Field Summary
protected  GroupProperties gp
          The GroupProperties assigned to this item.
 int len_tm
          The item length time.
 
Fields inherited from class com.e1.mxdublin.core.SeqEvent
mandatory
 
Constructor Summary
EvAbstractItem()
           
EvAbstractItem(String value)
          Generic event constructor with defaultProp used as properties
EvAbstractItem(String value, GroupProperties gp)
           
 
Method Summary
protected  void appendDefinedProperties(StringBuffer sb)
          Appends the string representation of the defined properties.
 void bang()
          Will play the event by calling play() and the wait len_tm to call stop().
 void cancel()
          Cancels current task
 Object clone()
          Clone the abstract event.
 int compareTo(EvAbstractItem item)
          Event item position is compared with another one.
 boolean equals(Object comp)
          Returns true if the object value and time is equal to comp.
static EvAbstractItem fromXML(Element e)
          Return the Event based on the XML element.
 GroupProperties getGroupProperties()
          Returns the associated group-properties for this event.
 int getTm()
          Returns event time in ppq.
 String getValue()
          Returns event representation in string format.
abstract  boolean isLike(EvAbstractItem comp)
          Returns true if the content of this event is the same than event item 'comp'.
protected  boolean isSameGroupProperties(String key, String value)
          Returns true if the property key assigned with value is the same of the group-properties.
protected  void loadElement(Element e)
          Once the new class is instanciated with EvAbstractedItem.fromXML, the extended class should override this method to read extra attributes.
abstract  void play()
          Tells this event to execute.
 String repr()
          This will returns the complete definition of the event.
 void run()
          Called by the internal sequencer (com.e1.mxdublin.core.Sequencer) to be stopped.
 void setProperties(GroupProperties values)
          Set properties definition using property
 boolean setProperty(String name, String value)
          Set property.
 void setTm(float tm)
          Reset event ppq time in float (1 = 480, 1.5 = 720).
 void setTm(int tm)
          Reset event ppq time.
 void setValue(String value)
          Sets event definition using a string.
 void stop()
          Tells this event to stop executing.
 String toString()
          Returns the representation of this event item.
 Element toXML()
          Returns the XML representation of this event.
 
Methods inherited from class com.e1.mxdublin.core.SeqEvent
eventDebug
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

len_tm

public int len_tm
The item length time. If it has value of -1 (default), the stop() will not be scheduled.


gp

protected GroupProperties gp
The GroupProperties assigned to this item.

Constructor Detail

EvAbstractItem

public EvAbstractItem()

EvAbstractItem

public EvAbstractItem(String value)
Generic event constructor with defaultProp used as properties

Parameters:
value - string value of this event

EvAbstractItem

public EvAbstractItem(String value,
                      GroupProperties gp)
Method Detail

play

public abstract void play()
Tells this event to execute.


stop

public void stop()
Tells this event to stop executing. This method will be called when the len_tm is reached since the bang() was called.


bang

public void bang()
Will play the event by calling play() and the wait len_tm to call stop().


setValue

public void setValue(String value)
Sets event definition using a string.

Parameters:
value - String value

getValue

public String getValue()
Returns event representation in string format.

Returns:
the event represnetation in string format

setProperties

public void setProperties(GroupProperties values)
Set properties definition using property


setProperty

public boolean setProperty(String name,
                           String value)
Set property. If the property is not supported by the event, the event must return false.

Parameters:
name - property name
value - property value
Returns:
true if the property is supported

setTm

public void setTm(float tm)
Reset event ppq time in float (1 = 480, 1.5 = 720).

Parameters:
tm - new event time in ppq

setTm

public void setTm(int tm)
Reset event ppq time.

Parameters:
tm - event ppw time.

getTm

public int getTm()
Returns event time in ppq.

Returns:
event time in ppq

getGroupProperties

public GroupProperties getGroupProperties()
Returns the associated group-properties for this event.

Returns:
the associated group-properties for this event.

loadElement

protected void loadElement(Element e)
Once the new class is instanciated with EvAbstractedItem.fromXML, the extended class should override this method to read extra attributes. Otherwise, it will assign the string value.

Parameters:
e - the original XML element

fromXML

public static EvAbstractItem fromXML(Element e)
Return the Event based on the XML element.

Parameters:
e - the element that defines the event
Returns:
The newly created event from the XML

toXML

public Element toXML()
Returns the XML representation of this event.

Returns:
Element representation of this event

equals

public boolean equals(Object comp)
Returns true if the object value and time is equal to comp.

Overrides:
equals in class Object
Parameters:
comp - the object to compare
Returns:
true if the object is equal to comp
See Also:
Object.equals(java.lang.Object)

compareTo

public int compareTo(EvAbstractItem item)
Event item position is compared with another one.

Specified by:
compareTo in interface Comparable<EvAbstractItem>

clone

public Object clone()
Clone the abstract event. Special care should be taken since if the event is in a list, the owner of the cloned object will be set to null.

Overrides:
clone in class Object
See Also:
Object.clone()

toString

public String toString()
Returns the representation of this event item. Returns the value of the event and the overridden properties.

Overrides:
toString in class Object

appendDefinedProperties

protected void appendDefinedProperties(StringBuffer sb)
Appends the string representation of the defined properties. Properties thats are also in the group-properties and have the same values should not be appended.

Parameters:
sb - the StringBuffer to append the properties values

isSameGroupProperties

protected boolean isSameGroupProperties(String key,
                                        String value)
Returns true if the property key assigned with value is the same of the group-properties. Usually, if the property value is the same from the group-properties, the item must not append the group-properties value.

Parameters:
key - the name of the property
value - the value of the property
Returns:
true if the value in the group-properties is the same

isLike

public abstract boolean isLike(EvAbstractItem comp)
Returns true if the content of this event is the same than event item 'comp'. Unlike equals(Object o), the event time is not compared.

Parameters:
comp - the event item to compare
Returns:
returns true is the content is the same

repr

public String repr()
This will returns the complete definition of the event.

Returns:
returns the user friendly representation of the event

run

public final void run()
Called by the internal sequencer (com.e1.mxdublin.core.Sequencer) to be stopped. Event that have a len_tm > 1 will be sequence by the internal sequencer and the method stop will call the stop() method of this event.

Specified by:
run in interface Runnable
Specified by:
run in class SeqEvent

cancel

public void cancel()
Description copied from class: SeqEvent
Cancels current task

Overrides:
cancel in class SeqEvent