33# Author:
44# Marian Dovgialo <marian.dowgialo@gmail.com>
55
6+ # requires pyo for sound
7+ from __future__ import print_function
68from ugm_blinking_engine import UgmBlinkingEngine
7- from PyQt4 .QtGui import QSound
9+ try :
10+ import pyo
11+ except ImportError :
12+ print ('ERROR no sound library.\n \t \t Installl pyo!\n \t \t sudo apt-get install python-pyo' )
813from obci .devices .haptics .HapticsControl import HapticStimulator
914from obci .utils import context as ctx
1015from obci .gui .ugm import ugm_engine
1116from PyQt4 import QtCore
1217import time
1318
19+
1420class UgmModalBlinkingEngine (UgmBlinkingEngine ):
1521 """A class representing ugm application. It is supposed to fire ugm,
1622 receive messages from outside (UGM_UPDATE_MESSAGES) and send`em to
@@ -34,7 +40,7 @@ def __init__(self, p_config_manager, p_connection,
3440 self .haptic = 'haptic' in modalities
3541 self .auditory = 'auditory' in modalities
3642
37- #must be here or else they connect to upper class methods
43+ #must be here or else they connect to parent class methods
3844 self ._blink_timer = QtCore .QTimer (self )
3945 self ._blink_timer .setSingleShot (True )
4046 self ._blink_timer .connect (self ._blink_timer , QtCore .SIGNAL ("timeout()" ), self ._blink )
@@ -53,7 +59,10 @@ def __init__(self, p_config_manager, p_connection,
5359
5460 def _init_auditory (self , configs ):
5561 soundfiles = configs .get_param ('soundfiles' ).split (';' )
56- sounds = [QSound (f ) for f in soundfiles ]
62+ self .audio_server = pyo .Server ()
63+ self .audio_server .boot ()
64+ self .audio_server .start ()
65+ sounds = [pyo .SfPlayer (f ) for f in soundfiles ]
5766 assert len (soundfiles ) == len (self ._active_ids )
5867 assert len (sounds ) == len (self ._active_ids )
5968 self ._sounds = dict (zip (self ._active_ids , sounds ))
@@ -81,17 +90,18 @@ def set_configs(self, configs):
8190
8291 def _blink (self ):
8392 '''Do blinking of configured modality'''
84- curr_blink_global_id = self ._active_ids [self ._curr_blink_id ]
8593 start_time = time .time ()
94+ curr_blink_global_id = self ._active_ids [self ._curr_blink_id ]
8695 if self .visual :
8796 self .update_from (self ._curr_blink_ugm )
97+ update_time = time .time ()
8898 if self .auditory :
89- self ._sounds [curr_blink_global_id ].play ()
99+ self ._sounds [curr_blink_global_id ].out ()
90100 if self .haptic :
91101 self .stimulator .stimulate (
92102 self ._haptic_map [curr_blink_global_id ],
93103 self ._haptic_duration )
94- update_time = time . time ()
104+
95105 if self ._blinks_count >= 0 :
96106 self ._blinks_count -= 1
97107 self .connection .send_blink (self ._curr_blink_id , update_time )
0 commit comments