Creative Commons License R.Muralikrishnan, MPI for Empirical Aesthetics. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Licence.

##############################################################################
##                                                                          ##
##             Daisy : Auditory Study with Visual Primes                    ##
##                              Hanna                                       ##
##             Experiment Script for use with Presentation                  ##
##                       Author: R. Muralikrishnan                          ##
##                                                                          ##
##############################################################################

##############################################################################
# Scenario Description Language (SDL) Header Part
##############################################################################

# These button codes have to correspond to those set in 'Settings -> Response'
active_buttons = 3;      # There are 3 active buttons defined in 'Settings -> Response'
button_codes = 1,2,3;    # These are the codes of those buttons

response_matching = simple_matching;  # Enables features not in legacy_matching

# Only those button presses that one expects are logged; not all
response_logging = log_active;

# Needed for EEG Trigger files
write_codes = true;
pulse_width = 5;
default_output_port = 1;  # This is most probably going to be the same for everyone.
# This is the LPT Parallel port that you will define in the Port settings tab of
# Presentation.  This will be used as the output port for sending codes to EEG.
# Defining this here saves getting a port number in the PCL part from the output_manager
# and calling send_code etc.  Stimulus events themselves will send these for us, provided we
# define the correct port_codes in each Stimulus event.

# Default Settings for Font, FG and BG Colours etc.
default_background_color = "0, 0, 0";  # RGB codes in decimal; 000 => Black
default_font = "DejaVu Sans Mono";
default_font_size = 34;
default_text_color = "255, 255, 255";#"000, 102, 153"; #"100, 64, 28"; #  # An off-bluish foreground
default_text_align = align_center;

#"188, 145, 112";
#006699 #"000, 102, 153";
#9CBDDE #"156, 189, 222";
#E8F0F7 #"232, 240, 247";
#93A070 #"147, 160, 112";

default_deltat = 0;
default_picture_duration = next_picture; #/* This implies that all pictures ...
#/...are shown until the next picture is shown, unless otherwise specified */

#default_all_responses = false;

##############################################################################
# Scenario Description Language (SDL) Part
##############################################################################

begin;

# ============================
# SDL Variable Declarations: -
# ============================

#
# We don't use any variables.  All the timer parameters appear as numbers.

# ==============================
# Picture Stimuli Definitions: - Everything that is shown, including text!
# ==============================

# Screen definition for the trial that starts an Experimental Session.
# Used as the first screen that the participant sees.  Operator Controlled.

picture
{
    text { caption = "Willkommen! Das Experiment beginnt gleich."; };
    # text { caption = "ஆய்வு சில நொடிகளில் ஆரம்பம்."; };
    x = 0;
    y = 0;

} P_Start_Exp;

# Screen definition for the Pause trial
# Operator Controlled!
picture
{
    text { caption = "Kurze Pause."; };
    # text { caption = "ஒரு சிறிய இடைவேளைக்குப் பிறகு \n ஆய்வு தொடரும்."; };
    x = 0;
    y = 0;

} P_Pause;

# Screen definition for the Continue trial
# Participant Controlled!
picture
{
    text { caption = "Drücke eine Taste um fortzufahren."; };
    # text { caption = "தொடர ஏதேனும் ஒரு பொத்தானை அழுத்தவும்.";};
    x = 0;
    y = 0;

} P_Continue;

# Screen definition for the Interruption trial
# Operator Controlled!
picture
{
    text { caption = "Kurze Unterbrechung. Bitte warten."; };
    x = 0;
    y = 0;

} P_Interruption;

# Screen definition for showing the focus star
picture
{
   text { caption = "*";
	font_size = 48;};
   x = 0;
   y = 0;
} P_Focus_Star;

# Screen definition for showing the Forward Mask
picture
{
   text { caption = "############"; };
   x = 0;
   y = 0;
} P_Forward_Mask;

# Screen definition for showing the Colour Change
picture
{
   text { caption = "############"; } Txt_Colour_Change;
   x = 0;
   y = 0;
} P_Colour_Change;

# Screen definition for showing the Colour Reset
picture
{
   text { caption = "############"; } Txt_Colour_Reset;
   x = 0;
   y = 0;
} P_Colour_Reset;

# Screen definition for showing the Prime
picture
{
   text { caption = " "; } Txt_Prime;               # PCL fills this...
   x = 0;
   y = 0;
} P_Prime;

# Screen definition for showing the Backward Mask
picture
{
   text { caption = "XXXXXXXXXXXX"; } Txt_Backward_Mask;
   x = 0;
   y = 0;
} P_Backward_Mask;

# Screen definition for the End_Thanks trial
picture
{
    text {caption = "Geschafft! Vielen Dank!";};
    # text {caption = "ஆய்வு இத்துடன் நிறைவு பெற்றது. மிக்க நன்றி!";};
    x = 0;
    y = 0;

} P_End_Thanks;



####  Specific for presenting Probe Task from Textfile   ---------
# Screen definition for Probe Task (text)
picture
{
   text {caption = " ";} Txt_Probe;    # PCL Program fills the caption.
   x = 0;
   y = 0;
} P_Probe;

####  Specific for presenting Comprehension Questions from Textfile   ---------
# Screen definition for Comprehension questions (text)
picture
{
   text {caption = "?";
	font_size = 46;} ;    # PCL Program fills the caption.
 	x = 0;
   y = 0;
  } P_Show_Question_Mark;

#####

####  Specific for presenting Auditory Stimuli   -------------------------------
# ============================
# Sound Stimuli Definitions: -
# ============================

sound
{
    wavefile
    {
      filename = "";        # PCL Program below fills the file name
      preload = false;
    } Wav_Stimulus_Sentence;
} S_Stimulus_Sentence;

####

#=====================
# Trial Definitions: -
#=====================

/****
/#  Note that the name 'Trial' could be misleading.  Unless otherwise specified,
/#  what we mean by a 'Trial' here is actually a sub-trial or sub-task that is
/#  part - and thereby defines the structure - of an actual experimental trial.
****/

/****
/# Template for defining an SDL Trial.
/# trial
/# {
/#      Trial-related parameters such as trial_duration, trial_type etc.
/#     Trial-related parameters
/#
/#     Stimulus event 1 such as picture, sound, video, nothing or force-FB;
/#     Stimulus event parameters such as time, event code etc.
/#     If the parameters aren't specified, the default values are used!!!
/#
/#     Stimulus event 2;
/#     its parameters...and so on
/# }
****/
trial
{
    trial_duration = 1500;
    all_responses = false;

    stimulus_event
    {
        picture {};     # This is the default picture, which is nothing!
        code = "CLS";   # Comment this out to avoid seeing this in the logfile.
    };
} T_Blank_Screen;

# Definition of the Trial to start an Experimental Session.
# Operator Controlled!
trial
{
    trial_duration = forever;       # Keep running the trial...
    trial_type = specific_response; # ...until the following specific response.
    terminator_button = 3;          # Operator PC - ENTER key.
    stimulus_event
    {
        picture P_Start_Exp;        # Show P_Start_Exp.
        code = "Das Experiment beginnt nun.";
    };
} T_Start_Exp;

# Definition of the Trial to continue further.
# Participant Controlled!
trial
{
    trial_duration = forever;        # Keep running the trial...
    trial_type = specific_response;  # ...until the following specific response.
    terminator_button = 1,2;         # Participant Joystick - L or R button.

    stimulus_event
    {
        picture P_Continue;          # Show P_Continue.
        code = "Trials follow!";
    };
} T_Continue;

# Definition of the Trial to Launch an Experimental Trial
trial
{
    trial_duration = 500;       # Run the trial for 500 ms...
    all_responses = false;      # ..without recognising any key presses.

    stimulus_event
    {
        picture P_Focus_Star;   # Show the focus star for fixation.
        code = "";              # Code set below in the PCL program.
        # port_code = ;         # Port code set by the PCL program.
    } E_Launch_New_Trial;
} T_Launch_New_Trial;



trial
{
    trial_duration = stimuli_length;
    all_responses = false;

    stimulus_event
    {
        picture P_Forward_Mask;
        code = "Forward-Mask";
    } E_Forward_Mask1;

    stimulus_event
    {
        sound S_Stimulus_Sentence;
        # code = "Sound";  # PCL Program fills this!!!
        # port_code = ; # PCL Program fills this!!!
    } E_Stimulus_Sentence;

    stimulus_event
    {
        picture P_Colour_Change;
        code = "Colour-Change";
        # time = 200;
    } E_Colour_Change;

   # stimulus_event
   # {
   #     picture P_Colour_Reset;
    #    code = "Colour-Reset";
    #   deltat = 100;
   # } E_Colour_Reset;

    stimulus_event
    {
        picture P_Prime;
        code = "Prime"; # PCL Program fills this!!!
        #time = 63;  # This is set by the PCL Program after reading the target onset from the input file!!!
    } E_Prime;

    stimulus_event
    {
        picture P_Backward_Mask;
        code = "Backward-Mask";
        deltat = 60;
    } E_Backward_Mask;

} T_Masked_Priming;


# Definition of the Trial to show ??? for Acceptability Judgement.
trial
{
   trial_duration = 1000;
   trial_type = specific_response;
   terminator_button = 1,2;  # The exact response can be either of these;

    stimulus_event
    {
        picture P_Show_Question_Mark;
        code = "191";                    # PCL Program sets this.
        port_code = 191;                 # Send '191' to EEG
        target_button = 2;               # 2 is good, 1 is bad; as always!
    } E_Show_Question_Mark;
} T_Show_Question_Mark;


# Definition of the Trial to show the Probe Task
trial
{
   trial_duration = 2000;
   trial_type = specific_response;
   terminator_button = 1,2;  # The exact response can be either of these;

    stimulus_event
    {
        picture P_Probe;
        code = "195";                    # PCL Program sets this.
        port_code = 195;                 # Send '195' to EEG
        # target_button = 1,2;           # PCL Program sets this.
    } E_Probe;
} T_Probe;

#####

# Definition of the Trial to send a code indicating that a Timeout has occurred.
/*# When a button-pressed response occurs, 1 or 2 is sent to EEG depending upon the button pressed.
  # When a timeout occurs, nothing gets sent.  Just in order to have equal number of lines in the
  # trigger files later, it's better to send a code indicating timeout.
  # (Yes, IN ADDITION to the usual code 199 that will follow.)
*/
trial
{
    trial_duration = 10;
    all_responses = false;

    stimulus_event
    {
        nothing {};                   # This is the default picture, which is nothing!
        code = "Timeout";
        port_code = 3;
    } E_Report_Timeout_to_EEG;
} T_Report_Timeout_to_EEG;

# Definition of the Trial to send the response code to EEG
trial
{
    trial_duration = 20;
    all_responses = false;

    stimulus_event
    {
        nothing {};                  # Basically, nothing is done!
        time = 15;
        /* Start this event 15 seconds after the trial starts.  This is to provide a delay in
         sending the code to EEG to avoid trying to reach the port when it is still busy
           having just received the response 1 or 2 from the button box, or the timeout code.
        */
        # code = "Send Code";      # Comment this out to avoid seeing this in the logfile.
        # port_code = 196, 197 or 199, PCL Program fills this!!!
    } E_Response_Code_to_EEG;
} T_Response_Code_to_EEG;

# Definition of the Trial to show a Pause
# Operator Controlled
trial
{
trial_duration = forever;
trial_type = specific_response;
terminator_button = 3;

    stimulus_event
    {
        picture P_Pause;
        code = "Pause";
    };
} T_Pause;

# Definition of the Trial to Interrupt in the middle of a session
# Operator Controlled
trial
{
trial_duration = forever;
trial_type = specific_response;
terminator_button = 3;

    stimulus_event
    {
        picture P_Interruption;
        code = "Interrupted!!!";
    };
} T_Interruption;

# Definition of the Trial to end the session
# Operator Controlled
trial
{
    trial_duration = forever;
    all_responses = false;
    trial_type = first_response;

    stimulus_event
    {
        picture P_End_Thanks;
        code = "End of Session!";
    };
    picture P_End_Thanks;
} T_End_Thanks;

##############################################################################
# Presentation Control Language (PCL) Program Part
##############################################################################

begin_pcl;

preset string V_Version; # Prompt the version at the beginning!!!

int N_of_Trials = 120;                                 # Number of Experimental Trials per Session.
int N_of_Blocks = 2;                                 # Number of Blocks per Session.
int N_of_Trials_per_Block = N_of_Trials/N_of_Blocks; # Number of Experimental Trials per Block.

input_file F_Session_List = new input_file;
F_Session_List.open("Session_List_" + V_Version + ".txt");
# This is the file containing the list of stimuli for one session.
# Each line in this file must correspond to one experimental trial.

####  Specific for presenting Primes   --------------------------------

input_file F_Prime_List = new input_file;
F_Prime_List.open("Prime_List_" + V_Version + ".txt");


# Columns of strings in the order found in the input Session List file.
string V_Stimulus_Sentence;
string V_Dummy;
string V_Item;
string V_Condition;
string V_Condition_Code;
string V_Probe;
string V_Expected_Response;

# Columns of strings in the order found in the input Session List file.
string V_Stimulus;
string V_Prime;
string V_Target_Onset;
string V_Colour_Change;
string V_Colour_Change_Time;


int V_Prime_Onset;
int V_Colour_Reset_Time;

# output_port O_Port_to_EEG = output_port_manager.get_port(1);
stimulus_data D_Stimulus_Data = stimulus_manager.last_stimulus_data();

#========================
# Main Experiment Loop: -
#========================
loop     /*** Begin Main Loop 1 for Blocks ***/
    int V_Current_Block = 1

until
    V_Current_Block > N_of_Blocks

begin
    if V_Current_Block == 1 then
        T_Start_Exp.present();
    else
        T_Pause.present();
    end;

    T_Continue.present();
    T_Blank_Screen.present();


    #==========
    # Loop 2: -
    #==========
    loop    /*** Begin Loop 2 for Trials ***/
        int V_Current_Trial = 1

    until
        V_Current_Trial > N_of_Trials_per_Block

    begin
        V_Stimulus_Sentence = F_Session_List.get_string(); # Eg: 01SAI
        V_Dummy = F_Session_List.get_string();      # Eg: CQ01SAI
        V_Item = F_Session_List.get_string();              # Eg: 01
        V_Condition = F_Session_List.get_string();         # Eg: SAI
        V_Condition_Code = F_Session_List.get_string();    # Eg: 230
        V_Probe = F_Session_List.get_string();     # Eg: Q01SAIC
        V_Expected_Response = F_Session_List.get_string(); # Eg: 2 (Left button = Correct)

        V_Stimulus = F_Prime_List.get_string();
        V_Prime = F_Prime_List.get_string();
        V_Target_Onset = F_Prime_List.get_string();
        V_Colour_Change = F_Prime_List.get_string();
        V_Colour_Change_Time = F_Prime_List.get_string();




        # Do filename and event-code assignments valid during this exp-trial;
        # Load wavefile and bitmap stimuli that are needed for this trial;
        /* We do this before launching the experimental trial so as to keep
            as minimal intereference as possible in trial timings.  You see,
            these things consume processor time, however small they are!
        */
        ####  Specific for presenting Auditory Stimuli   -------------------------------
        Wav_Stimulus_Sentence.set_filename(V_Stimulus_Sentence + ".wav");
        Wav_Stimulus_Sentence.load();

        ####

        E_Launch_New_Trial.set_event_code("B" + string(V_Current_Block) + " T" + string(V_Current_Trial));

        ####  Specific for presenting Auditory Stimuli   -------------------------------
        E_Stimulus_Sentence.set_event_code(V_Stimulus_Sentence + ".wav");
        ####

        E_Probe.set_target_button(int(V_Expected_Response));


        # Execute the Experimental Trial!!!


/* NOT IN THE ORIGINAL SCRIPT USED FOR THE EXPERIMENT...ADDED AFTERWARDS*/

	#V_Item = string(int(V_Item) + 10 - 10); => This doesn't work!!!
        # So a hard-coded way to tackle 08 and 09 bug in Presentation!!!
        if (V_Item == "08") then
	    V_Item = "8";
	elseif (V_Item == "09") then
	    V_Item = "9";
	end;
/* NOT IN THE ORIGINAL SCRIPT USED FOR THE EXPERIMENT...ADDED AFTERWARDS*/

 E_Launch_New_Trial.set_port_code(int(V_Item));
 T_Launch_New_Trial.present(); # Show Star for 500 ms

  /************ Auditory Stimulus Presentation Begins *****************/

        E_Stimulus_Sentence.set_port_code(int(V_Condition_Code)); # Set Condition Code for sending to EEG

 /************ Masked Prime Preparation and Presentation ************/

 if (V_Prime == "Dummy") then
 V_Prime = "############";
 Txt_Backward_Mask.set_caption("############");
 Txt_Backward_Mask.redraw();
 else
 Txt_Backward_Mask.set_caption("XXXXXXXXXXXX");  # Reset Backward Mask (It was perhaps changed for an earlier trial)
 Txt_Backward_Mask.redraw();
 end;

 V_Prime_Onset = int(V_Target_Onset) - 110; # Actually -100, but -110 works out to -100 on screen.
 E_Prime.set_time(V_Prime_Onset);
 Txt_Prime.set_caption(V_Prime);
 Txt_Prime.redraw();

 #V_Colour_Reset_Time = V_Prime_Onset - 800;
 #E_Colour_Reset.set_time(V_Colour_Reset_Time);


 if (V_Colour_Change == "Y") then
  E_Colour_Change.set_time(int(V_Colour_Change_Time));
  Txt_Colour_Change.set_font_color(0,0,225);
  Txt_Colour_Change.redraw();

  #Txt_Colour_Reset.set_font_color(255,255,255);
  #Txt_Colour_Reset.redraw();

 else # Reset any previous colour changes
  E_Colour_Change.set_time(int(V_Colour_Change_Time));
  Txt_Colour_Change.set_font_color(255,255,255);
  Txt_Colour_Change.redraw();

  #Txt_Colour_Reset.set_font_color(255,255,255);
  #Txt_Colour_Reset.redraw();
 end;

 T_Masked_Priming.present();
 #T_Masked_Priming2.present();

 T_Blank_Screen.present();

        /*****************  Colour Change Perception Begins  **********************/

        T_Show_Question_Mark.present();  ##  Show ??? for 2000 ms; wait for response.

        # Monitor the Response and send appropriate port codes to EEG!!!
        D_Stimulus_Data = stimulus_manager.last_stimulus_data();

        # To delay sending the following codes to the Output Port!!!
        # Because these are almost at the same time as the Response there, so the port
        # cannot handle it unless there's a short delay.
        if (D_Stimulus_Data.type() == stimulus_hit) then
            E_Response_Code_to_EEG.set_port_code(192);
            E_Response_Code_to_EEG.set_event_code("Colour-Changed");
            T_Response_Code_to_EEG.present();

        elseif (D_Stimulus_Data.type() == stimulus_incorrect) then
            E_Response_Code_to_EEG.set_port_code(193);
            E_Response_Code_to_EEG.set_event_code("No-Colour-Change");
            T_Response_Code_to_EEG.present();

        elseif (D_Stimulus_Data.type() == stimulus_miss) then
            T_Report_Timeout_to_EEG.present();
            E_Response_Code_to_EEG.set_port_code(199);
            E_Response_Code_to_EEG.set_event_code("Timeout");
            T_Response_Code_to_EEG.present();
        end;
        /*****************  Acceptability Judgement Ends  **********************/


        /*****************  Probe Task Begins  **********************/

        #V_Probe = F_Probe.get_line(); # Read one line at a time from the file.

        Txt_Probe.set_caption(V_Probe);
        Txt_Probe.redraw();

        T_Blank_Screen.present();
        T_Probe.present();

        # Monitor the Response and send appropriate port codes to EEG!!!
        D_Stimulus_Data = stimulus_manager.last_stimulus_data();

        # To delay sending the following codes to the Output Port!!!
        # Because these are almost at the same time as the Response there, so the port
        # cannot handle it unless there's a short delay.
        if (D_Stimulus_Data.type() == stimulus_hit) then
            E_Response_Code_to_EEG.set_port_code(196);
            E_Response_Code_to_EEG.set_event_code("196");
            T_Response_Code_to_EEG.present();

        elseif (D_Stimulus_Data.type() == stimulus_incorrect) then
            E_Response_Code_to_EEG.set_port_code(197);
            E_Response_Code_to_EEG.set_event_code("197");
            T_Response_Code_to_EEG.present();

        elseif (D_Stimulus_Data.type() == stimulus_miss) then
            T_Report_Timeout_to_EEG.present();
            E_Response_Code_to_EEG.set_port_code(199);
            E_Response_Code_to_EEG.set_event_code("199");
            T_Response_Code_to_EEG.present();
        end;

         /*****************  Probe Task Ends  **********************/


 T_Blank_Screen.present();

 ####  Specific for presenting Auditory Stimuli   -------------------------------
 # Unload all memory occupiers such as wavefile stimuli.
 Wav_Stimulus_Sentence.unload();
 ####

 # Go to the Next Trial
 V_Current_Trial = V_Current_Trial + 1;

 #===========
 # End Loop 2
 #===========
 end; /*** End Loop 2 for Trials ***/

# Go to the Next Block
V_Current_Block = V_Current_Block + 1;

#================
# End Main Loop 1
#================
end; /*** End Main Loop 1 for Blocks ***/

# Close all the open files
F_Session_List.close();
F_Prime_List.close();
#F_Comp_Question.close();

# Finish off the session!!!
T_End_Thanks.present();