Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Parallel loops

Hello guys,
I'm new to OpenSesame.
In an experiment I want to show pictures and play sounds in parallel.
An example:
1. For 2 mins, every 20 seconds a picture should appear (different pictures).
2. With the same beginning, every 7 seconds a sound should be played (every sound is different).

Each of these tasks in easy for me to implement in OpenSesame (loops with sketchpads/sampler) but the problem is how to do these two tasks in parallel.
Is there any solution with the Coroutine item? I tried it with loops but they are not available in Coroutines.

I hope you guys understand what my problem is ;)
Thanks for the help.

Comments

  • Hi Flippy,

    I don't know what your Python skills are, but I would solve this in inline_scripts accessing the sound and canvas functions directly. However, you can also consider trying to implement it with co-routines. They were designed to allow for parallel things to happen. I've never used them, so I can't help you much there. Sorry.

    Btw. Based on your description, you don't necessarily need parallelism. The tricky bit is to initialise the sketchpad and sounds at the right moment, which requires you have to access to the presentation at any time, but not necessarily access to both at the same time. ( At least I believe so).

    eduard

    Eduard

    Buy Me A Coffee

  • Hi eduard,
    thank you for your help. I'm a total beginner in Python and OpenSesame. Can you show me how accessing the sound and canvas functions in parallel would look like in an inline_script?
    Would be helpful for me :)

  • Hey,

    To get started, you can check out the examples in the links that I provided. If I have some time later this week, I'll try to fix a little script for you.

    Eduard

    Buy Me A Coffee

  • edited February 2017

    I need some more help with my script.
    The two functions picture_show and sound_play should run in parallel.
    When I call both functions individually everything works fine.
    The problem appears when I try to call the functions in threads. The keylog implemented in the sound_play function isn't working properly anymore. How I said, when I call just the sound_play function, all works fine.
    Do you have any idea why it isn't working with multithreading?

    Here is my code:

    def sound_play():
    
        j=1
    
        while j<9:
            #Abspielen des Sounds
            sound = "0" + str(j) + "_Set1_einfach_3.5sec.wav"       #Erzeugen des jeweiligen Soundnamens
            src = pool[sound]       #Auslesen des Pfades der aktuellen Sound-Datei 
            my_sampler = sampler(src, volume=1)             #Erstellung des Samplers mit dem Pfad src
            #my_sampler.block = True
            my_sampler.play()       #Abspielen des Sounds
            j=j + 1
            #t1=clock.time()
            clock.sleep(3500)       #Wartezeit 3,5 Sekunden bis Keylog aktiv wird
    
            #Zeitfenster 4 Sekunden für Keylog
            start_time = clock.time()   #aktuelle Laufzeit in Millisekunden     
    
            print("start: " + str(start_time))  #Ausgabe Startzeit
            key_response = keyboard(keylist = ['a'], timeout=4000)  #Erzeugung des Keyloggers
            key_response.flush()
            key, end_time = key_response.get_key()  #Übergabe der aktivierten Taste inkl Zeit des Tastendrucks
    
            #end_time = end_time - 1000     #????? Zeit des Tastendrucks ist eine Sekunde zu lang
            print(key)
            print("end: " + str(end_time))      #Ausgabe der Zeit des Tastendrucks
            var.response = key      #Übergabe an globale Variable
            var.response_time = end_time - start_time   #Antwortzeit ist Differenz aus Zeit des Tastendrucks und Startzeit
            print("response: " + str(var.response_time))        #Ausgabe der Antwortzeit
            diff = 4000 - int(var.response_time)        #Differenz aus Zeitfenster von 4000ms und Antwortzeit
            print("difference: " + str(diff))           #Ausgabe der Differenz
            clock.sleep(diff)               #Warte bis nächaster Sound abgespielt wird
        return
    
    
        #Funktion für Multithreading
    def thread_start():
        #thr1 = threading.Thread(target=picture_show, args=(), kwargs={})       #Erstellung und Zuweisung der Aufgabe "Bilder" für Thread 1
        thr2 = threading.Thread(target=sound_play, args=(), kwargs={})          #Erstellung und Zuweisung der Aufgabe "SOunds" für Thread 2
        #thr1.start() #Starte Thread 1
        thr2.start() #Starte Thread 2
        #thr1.join() #Hinzufügen von Thread 1 zum Mainthread
        thr2.join() #Hinzufügen von Thread 2 zum Mainthread
        return
    
    thread_start()
    
Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games