1 //Create a class for music player
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class MusicPlayers {
9 private int deviceNumbers
10 private List musicPlayers
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "musicPlayerID0"
15 private String label = "musicPlayer0"
16 private String displayName = "musicPlayer0"
17 private int level = 20
18 private String mute = "unmuted"
19 private String status = "paused"
20 private int trackNumber = 1
21 private String trackData = "someTrack"
22 private String trackDescription = "someDescriptions"
26 MusicPlayers(Closure sendEvent, int deviceNumbers) {
27 this.sendEvent = sendEvent
28 this.deviceNumbers = deviceNumbers
29 this.musicPlayers = []
31 /*def initLevel = Verify.getIntFromList(10, 20, 30)
32 this.level = initLevel
33 def initMute = Verify.getBoolean()
39 def initStatus = Verify.getInt(0,2)
40 if (initStatus == 0) {
41 this.status = "paused"
42 } else if (initStatus == 1) {
43 this.status = "playing"
45 this.status = "stopped"
47 def initTrack = Verify.getIntFromList(1, 2, 3)
48 this.trackNumber = initTrack
49 def initData = Verify.getBoolean()
51 this.trackData = "someTrack"
53 this.trackData = "someOtherTrack"
55 def initDesc = Verify.getBoolean()
57 this.trackDescription = "someDescriptions"
59 this.trackDescription = "someOtherDescriptions"
61 musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
65 def setValue(LinkedHashMap eventDataMap) {
66 if (eventDataMap["name"] == "status") {
67 if (eventDataMap["value"] != musicPlayers[0].status) {
68 this.status = eventDataMap["value"]
69 musicPlayers[0].setValue(eventDataMap["value"], "status")
70 sendEvent(eventDataMap)
72 } else if (eventDataMap["name"] == "level") {
73 if (eventDataMap["value"].toInteger() != musicPlayers[0].level) {
74 this.level = eventDataMap["value"].toInteger()
75 musicPlayers[0].setValue(eventDataMap["value"], "level")
76 sendEvent(eventDataMap)
78 } else if (eventDataMap["name"] == "trackDescription") {
79 if (eventDataMap["value"] != musicPlayers[0].trackDescription) {
80 this.trackDescription = eventDataMap["value"]
81 musicPlayers[0].setValue(eventDataMap["value"], "trackDescription")
82 sendEvent(eventDataMap)
84 } else if (eventDataMap["name"] == "trackData") {
85 if (eventDataMap["value"] != musicPlayers[0].trackData) {
86 this.trackData = eventDataMap["value"]
87 musicPlayers[0].setValue(eventDataMap["value"], "trackData")
88 sendEvent(eventDataMap)
90 } else if (eventDataMap["name"] == "mute") {
91 if (eventDataMap["value"] != musicPlayers[0].mute) {
92 this.mute = eventDataMap["value"]
93 musicPlayers[0].setValue(eventDataMap["value"], "mute")
94 sendEvent(eventDataMap)
99 //Methods for closures
100 def count(Closure Input) {
101 musicPlayers.count(Input)
106 def each(Closure Input) {
107 musicPlayers.each(Input)
109 def find(Closure Input) {
110 musicPlayers.find(Input)
112 def sort(Closure Input) {
113 musicPlayers.sort(Input)
115 def collect(Closure Input) {
116 musicPlayers.collect(Input)
121 if (mute != "muted") {
123 musicPlayers[0].mute()
127 if (status != "playing") {
128 this.status = "playing"
130 this.trackNumber = this.trackNumber+1
131 musicPlayers[0].nextTrack()
134 if (status != "paused") {
135 this.status = "paused"
136 musicPlayers[0].pause()
140 if (status != "playing") {
141 this.status = "playing"
142 musicPlayers[0].play()
145 def playTrack(String trackToPlay) {
146 if (status != "playing") {
147 this.status = "playing"
149 musicPlayers[0].playTrack(trackToPlay)
151 def previousTrack() {
152 if (status != "playing") {
153 this.status = "playing"
155 if (this.trackNumber != 1)
156 this.trackNumber = this.trackNumber-1
157 musicPlayers[0].previousTrack()
159 def restoreTrack(String trackToRestore) {
160 musicPlayers[0].restoreTrack(trackToRestore)
162 def resumeTrack(String trackToResume) {
163 if (status != "playing") {
164 this.status = "playing"
166 musicPlayers[0].resumeTrack(trackToResume)
168 def setLevel(int level) {
169 if (level != this.level) {
171 musicPlayers[0].setLevel(level)
174 def setTrack(String trackToSet) {
175 if (status != "playing") {
176 this.status = "playing"
178 musicPlayers[0].setTrack(trackToSet)
181 if (status != "stopped") {
182 this.status = "stopped"
183 musicPlayers[0].stop()
186 def playText(String text) {
187 if (status != "playing") {
188 this.status = "playing"
190 musicPlayers[0].playText(text)
193 def currentValue(String deviceFeature) {
194 musicPlayers[0].currentValue(deviceFeature)
197 def latestValue(String deviceFeature) {
198 musicPlayers[0].latestValue(deviceFeature)