-
Notifications
You must be signed in to change notification settings - Fork 14
/
EventReference.js
62 lines (55 loc) · 1.96 KB
/
EventReference.js
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
/*
* EventReference.js
* Author: Zoltan Komives ([email protected])
* Created: 04.07.2013
*
* Represents and event with its xmlid, but if the xmlid is not defined,
* it can also hold the timestamp that can be resolved as soon as the context that
* holds the event is established. When the tstamp reference is being resolved,
* the xml:id is calculated using the generic function tstamp2id(), then the xml:id stored,
* thus marking that the reference is resolved.
*/
MEI2VF.EventReference = function(xmlid) {
this.xmlid = xmlid;
}
MEI2VF.EventReference.prototype.setId = function(xmlid){
this.xmlid = xmlid;
}
MEI2VF.EventReference.prototype.setTStamp = function(tstamp){
this.tstamp = tstamp;
if (this.xmlid) {
this.tryResolveReference(true);
}
}
MEI2VF.EventReference.prototype.tryResolveReference = function(strict) {
var tstamp = this.tstamp;
var meicontext = this.meicontext;
if (!tstamp) throw new MEI2VF.RUNTIME_ERROR('MEI2VF:RERR:BADARG:EventRef001', 'EventReference: tstamp must be set in order to resolve reference.')
if (this.meicontext) {
//look up event corresponding to the given tstamp (strictly or losely)
this.xmlid = MeiLib.tstamp2id(this.tstamp, this.meicontext.layer, this.meicontext.meter);
} else {
this.xmlid = null;
}
}
/**
* @param params { meicontext, strict }; both parameters are optional;
* meicontext is an obejct { layer, meter };
* strict is boolean, false if not defined.
*
*/
MEI2VF.EventReference.prototype.getId = function(params) {
if (params && params.meicontext) this.setContext(params.meicontext);
if (this.xmlid) return this.xmlid;
if (this.tstamp) {
if (this.meicontext) {
//look up the closest event to tstamp within this.meicontext and return its ID
this.tryResolveReference(params && params.strict);
return this.xmlid;
}
}
return null;
}
MEI2VF.EventReference.prototype.setContext = function(meicontext) {
this.meicontext = meicontext;
}