An MP3 player is developed according to the division of the 3 parts of a system in Figure 5.8. It is included in the MP3Player/ subdirectory of SVM.
The model consists of the following files:
The FILE macro in the main model specifies the name of the MP3 file to be played. By default, it is empty. It must be redefined by the user on the command-line. The following statement under the INITIALIZER tests the validity of its value. The simulation halts if no file name is given:
if "[FILE]"=="":
print 'usage: svm MP3Player.des "FILE=[.mp3]"'
exit(1)
Figure 9.1 shows the graphical interface of the MP3 player. It is initialized by the following statements under the INTERACTOR descriptor:
from MP3PlayerGUI import MP3PlayerGUI # import the GUI class MP3PlayerGUI
root = Tk()
root.title(``MP3 player'')
gui = MP3PlayerGUI(root, eventhandler) # instantiate the GUI with the global eventhandler
eventhandler.start() # start the simulation of the model
root.mainloop() # loop infinitely to receive GUI events, until the window is closed
Because SCC supports actions and guards for the Python and C++ target languages, the user may synthesize code for this MP3 player in those languages. This produces a stand-alone application, which does not depend on the Python environment. The FILE macro must be explicitly redefined on the SCC command-line, since it is not possible to redefine it in the synthesized code. The user may use the following command to generate MP3Player.py, which encodes the complete behavior of the MP3 player (assuming that MP3 file music.mp3 exists):
scc -lpython -ext MP3Player.des "FILE=music.mp3"
The command to synthesize code in C++ is similar:
scc -lcpp -ext MP3Player.des "FILE=music.mp3"
Note that the user need not compile Python source, as Python is an interpreted language. MP3Player.py can be directly executed with Python and it plays music.mp3. However, the C++ source needs to be compiled and linked with the Python shared library. The need and the command for this compilation is printed to the console when SCC synthesizes the code.
CDPlayer is another meaningful model included in the SVM distribution. It is in the CDPlayer/ subdirectory. It models a CD player similar to the MP3 player. It is more complex because debugging and snapshotting are supported.