109109 uicontrol(handles .software_group , ' Style' , ' radiobutton' , ' String' , ' SpikeGLX' , ' Units' , ' normalized' , ' Position' , [0.5 , 0.3 , 0.4 , 0.4 ], ' Tag' , ' SpikeGLX' , ' FontSize' , 10 );
110110
111111 % Panel 1: Behavior
112- p1 = uipanel(' Title' , ' 1. Behavior' , ' FontSize' , 12 , ' FontWeight' , ' bold' , ' BorderType' , ' etchedin' , ' BorderWidth' , 1 , ' Units' , ' normalized' , ' Position' , [0.02 , 0.74 , 0.6 , 0.13 ]);
112+ p1 = uipanel(' Title' , ' 1. Behavior' , ' FontSize' , 12 , ' FontWeight' , ' bold' , ' BorderType' , ' etchedin' , ' BorderWidth' , 1 , ' Units' , ' normalized' , ' Position' , [0.02 , 0.74 , 0.6 , 0.13 ]);
113113 uicontrol(p1 , ' Style' , ' text' , ' String' , ' Protocol Name:' , ' Units' , ' normalized' , ' Position' , [0.05 , 0.7 , 0.22 , 0.25 ], ' HorizontalAlignment' , ' right' );
114114 handles.protocol_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' ArpitSoundCatContinuous' , ' Units' , ' normalized' , ' Position' , [0.3 , 0.7 , 0.45 , 0.25 ]);
115115 handles.manual_test = uicontrol(p1 , ' Style' , ' checkbox' , ' String' , ' Manual Test' , ' Value' , 1 , ' Units' , ' normalized' , ' Position' , [0.78 , 0.7 , 0.2 , 0.25 ]);
116- uicontrol(p1 , ' Style' , ' text' , ' String' , ' Experimenter:' , ' Units' , ' normalized' , ' Position' , [0.05 , 0.4 , 0.22 , 0.25 ], ' HorizontalAlignment' , ' right' );
117- handles.exp_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' lida' , ' Units' , ' normalized' , ' Position' , [0.3 , 0.4 , 0.65 , 0.25 ], ' Callback' , {@(h ,e ) feval(mfilename , obj , ' update_subject_id' )});
118- uicontrol(p1 , ' Style' , ' text' , ' String' , ' Rat Name:' , ' Units' , ' normalized' , ' Position' , [0.05 , 0.1 , 0.22 , 0.25 ], ' HorizontalAlignment' , ' right' );
119- handles.rat_name_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' LP12' , ' Units' , ' normalized' , ' Position' , [0.3 , 0.1 , 0.4 , 0.25 ], ' Callback' , {@(h ,e ) feval(mfilename , obj , ' update_subject_id' )});
120- uicontrol(p1 , ' Style' , ' text' , ' String' , ' Path:' , ' Units' , ' normalized' , ' Position' , [0.72 , 0.1 , 0.08 , 0.25 ], ' HorizontalAlignment' , ' right' );
121- handles.behav_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' C:\r atter' , ' Units' , ' normalized' , ' Position' , [0.81 , 0.1 , 0.18 , 0.25 ]);
122-
116+ uicontrol(p1 , ' Style' , ' text' , ' String' , ' Experimenter:' , ' Units' , ' normalized' , ' Position' , [0.02 , 0.4 , 0.2 , 0.25 ], ' HorizontalAlignment' , ' right' );
117+ handles.exp_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' lida' , ' Units' , ' normalized' , ' Position' , [0.23 , 0.4 , 0.25 , 0.25 ], ' Callback' , {@(h ,e ) feval(mfilename , obj , ' update_subject_id' )});
118+ uicontrol(p1 , ' Style' , ' text' , ' String' , ' Rat Name:' , ' Units' , ' normalized' , ' Position' , [0.50 , 0.4 , 0.18 , 0.25 ], ' HorizontalAlignment' , ' right' );
119+ handles.rat_name_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' LP12' , ' Units' , ' normalized' , ' Position' , [0.69 , 0.4 , 0.30 , 0.25 ], ' Callback' , {@(h ,e ) feval(mfilename , obj , ' update_subject_id' )});
120+ uicontrol(p1 , ' Style' , ' text' , ' String' , ' Distribution:' , ' Units' , ' normalized' , ' Position' , [0.02 , 0.1 , 0.18 , 0.25 ], ' HorizontalAlignment' , ' right' );
121+ handles.distribution_popup = uicontrol(p1 , ' Style' , ' popupmenu' , ...
122+ ' String' , {' random' , ' Uniform' , ' Hard A' , ' Hard B' }, ...
123+ ' Units' , ' normalized' , ...
124+ ' Position' , [0.21 , 0.1 , 0.35 , 0.25 ]);
125+ uicontrol(p1 , ' Style' , ' text' , ' String' , ' Path:' , ' Units' , ' normalized' , ' Position' , [0.58 , 0.1 , 0.1 , 0.25 ], ' HorizontalAlignment' , ' right' );
126+ handles.behav_edit = uicontrol(p1 , ' Style' , ' edit' , ' String' , ' C:\r atter' , ' Units' , ' normalized' , ' Position' , [0.69 , 0.1 , 0.30 , 0.25 ]);%
127+
128+
123129 % Panel 2: NeuroBlueprint Format
124130 p2 = uipanel(' Title' , ' 2. NeuroBlueprint Format' , ' FontSize' , 12 , ' FontWeight' , ' bold' , ' BorderType' , ' etchedin' , ' BorderWidth' , 1 , ' Units' , ' normalized' , ' Position' , [0.02 , 0.42 , 0.6 , 0.31 ]);
125131 uicontrol(p2 , ' Style' , ' text' , ' String' , ' Project Name:' , ' Units' , ' normalized' , ' Position' , [0.01 , 0.85 , 0.28 , 0.1 ], ' HorizontalAlignment' , ' right' );
317323 else % SpikeGLX
318324 log_message(handles , ' Initializing SpikeGLX controller...' );
319325 controller = SpikeGL(params .sglx_host_ip , params .sglx_port );
320- if ~controller .IsConnected(), error(' Failed to connect to SpikeGLX' ); end
326+ % if ~controller.IsConnected(), error('Failed to connect to SpikeGLX'); end
321327 end
322328 recording_controller.value = controller ;
323329 log_message(handles , sprintf(' %s controller initialized successfully.' , software ));
344350 if strcmp(software , ' OpenEphys' )
345351 controller .setRecordPath(params .oe_rec_node_id , save_path );
346352 else % SpikeGLX
347- controller .SetDataDir(save_path );
353+ controller = SetDataDir( controller , 0 , save_path );
354+ recording_controller.value = controller ;
348355 end
349356 log_message(handles , sprintf(' Recording path set to: %s ' , save_path ));
350357 catch ME
374381 else % SpikeGLX
375382 log_message(handles , ' Starting SpikeGLX recording...' );
376383 run_name = sprintf(' experiment_%s ' , datestr(now , ' yyyymmdd_HHMMSS' ));
377- controller .SetRunName(run_name );
378- controller .StartRun();
384+ boolval = IsInitialized( controller );
385+ if boolval
386+ spikeglx_params = GetParams( controller );
387+ controller = SetRunName(controller ,run_name ); % setting run name
388+ controller = StartRun(controller ); % starting acquisition
389+ pause(2 );
390+
391+ runningval = false ;
392+ while ~runningval % waiting for acquisition to start
393+ runningval = IsRunning( controller );
394+ if runningval
395+ controller = SetRecordingEnable( controller , 1 ) ; % Start Recording
396+ end
397+ end
398+ recording_controller.value = controller ;
399+ end
379400 end
380401
381402 log_message(handles , ' Electrophysiology recording is LIVE.' );
399420 controller .idle();
400421 else % SpikeGLX
401422 log_message(handles , ' Stopping SpikeGLX recording...' );
402- controller .StopRun();
423+ boolval = IsSaving( controller );
424+ if boolval
425+ controller = SetRecordingEnable( controller , 0 ) ;
426+ pause(1 ); % Brief pause to ensure recording stops
427+ controller = StopRun(controller );
428+ else
429+ controller = StopRun(controller );
430+ end
431+ recording_controller.value = controller ;
403432 end
404433
405434 log_message(handles , ' Electrophysiology recording stopped.' );
482511 video_save_dir = fullfile(params .local_path , value(session_base_path ), ' behav' );
483512 try
484513 log_message(handles , ' Loading main behavioral protocol...' );
485- feval(mfilename , obj , ' behav_control' , ' load_main_protocol' , params .experimenter , params .rat_name , params .protocol_name , video_save_dir , params .behav_path );
514+ feval(mfilename , obj , ' behav_control' , ' load_main_protocol' , params .experimenter , params .rat_name , params .protocol_name , video_save_dir , params .behav_path , params . stim_distribution );
486515 log_message(handles , ' Behavior system loaded and ready.' );
487516 log_message(handles , ' --- LOAD sequence complete. Ready to run. ---' );
488517 currentState.value = ' Run' ;
546575 switch sub_action
547576 case ' load_main_protocol'
548577 experimenter = args{1 }; ratname = args{2 }; protocol_name = args{3 };
549- video_save_dir = args{4 }; behav_path = args{5 };
578+ video_save_dir = args{4 }; behav_path = args{5 }; stim_distribution = args{ 6 };
550579 log_message(handles , [' Loading protocol: ' protocol_name ]);
551580 dispatcher(' set_protocol' , protocol_name );
552581 rath = get_sphandle(' name' , ' ratname' , ' owner' , protocol_name );
556585 log_message(handles , [' Loading settings for ' ratname ]);
557586 [~ , sfile ] = load_solouiparamvalues(ratname , ' experimenter' , experimenter , ' owner' , class(protobj ), ' interactive' , 0 );
558587 feval(protocol_name , protobj , ' set_setting_params' , ratname , experimenter , sfile , char(datetime(' now' )), video_save_dir );
588+ feval(protocol_name , protobj , ' set_stim_distribution' ,stim_distribution );
559589 if ~dispatcher(' is_running' ), pop_history(class(protobj ), ' include_non_gui' , 1 ); feval(protocol_name , protobj , ' prepare_next_trial' ); end
560590
561591 case ' crashed'
585615 load_soloparamvalues(ratname , ' experimenter' , experimenter , ' owner' , protocol_name , ' interactive' , 0 ,' data_file' ,fullfile(temp_data_dir ,temp_data_file ));
586616 dispatcher(' runstart_enable' );
587617 end
618+ feval(protocol_name , protobj , ' psychometricUpdate_aftercrash' ); % update parameters for psychometric plots which were not saved so cant be loaded
588619 if ~dispatcher(' is_running' ), pop_history(class(protobj ), ' include_non_gui' , 1 ); feval(protocol_name , protobj , ' prepare_next_trial' ); end
589620 catch
590621 log_message(handles , [' Loading settings for ' ratname ]);
10291060 params.do_manual_test = get(handles .manual_test , ' Value' );
10301061 params.experimenter = get(handles .exp_edit , ' String' );
10311062 params.rat_name = get(handles .rat_name_edit , ' String' );
1063+ popup_string = get(handles .distribution_popup ,' String' );
1064+ params.stim_distribution = popup_string{get(handles .distribution_popup ,' Value' )};
10321065 params.behav_path = get(handles .behav_edit , ' String' );
10331066 params.project_name = get(handles .proj_edit , ' String' );
10341067 params.subject_id = get(handles .sub_edit , ' String' );
@@ -1151,13 +1184,13 @@ function log_message(handles,logStr)
11511184 try
11521185 if ~isfield(handles , ' log_box' ) || ~isvalid(handles .log_box ), return ; end
11531186 current_text = get(handles .log_box , ' String' );
1154- timestamp = datestr( now , ' [HH:MM:SS ] ' );
1187+ timestamp = char(datetime( ' now' , ' Format ' , ' [HH:mm:ss ] ' ) );
11551188 new_line = [timestamp , logStr ];
11561189 new_text = [current_text ; {new_line }];
11571190 set(handles .log_box , ' String' , new_text , ' Value' , numel(new_text ));
11581191 drawnow ;
11591192 catch
1160- fprintf(' %s : %s\n ' , datestr( now , ' [HH:MM:SS] ' ), logStr );
1193+ fprintf(' %s : %s\n ' , char(datetime( ' now' , ' Format ' , ' [HH:mm:ss] ' ) ), logStr );
11611194 end
11621195
11631196function toggle_button_color(~, ~, button_handle )
@@ -1180,18 +1213,20 @@ function commit_to_svn(handles, file_path_data,file_path_settings, root_dir)
11801213 return ;
11811214 end
11821215 load(configFilePath , ' svn_user' , ' svn_password' );
1183- logmsg = char(strcat(' automated commit from GUI for data and settings for ' , {' ' } ,fname_data ,{' @' }));
1216+ logmsg_data = char(strcat(' automated commit from GUI for data and settings for ' , {' ' } ,fname_data ,{' @' }));
11841217 % current_dir = cd;
11851218 cd(pname_data );
11861219 add_cmd_data = char(strcat(' svn add' , {' ' }, fname_data , ' .mat' ,{' @' }));
1187- system(add_cmd_data );
1220+ system(add_cmd_data );
1221+ commit_cmd_data = sprintf(' svn ci --username="%s " --password="%s " -m "%s "' , svn_user , svn_password , logmsg_data );
1222+ [status , ~ ] = system(commit_cmd_data );
11881223
11891224 cd(pname_settings );
11901225 add_cmd_settings = char(strcat(' svn add' , {' ' }, fname_settings , ' .mat' ,{' @' }));
11911226 system(add_cmd_settings );
1192-
1193- commit_cmd = sprintf(' svn ci --username="%s " --password="%s " -m "%s "' , svn_user , svn_password , logmsg );
1194- [status , ~ ] = system(commit_cmd );
1227+ logmsg_setting = char(strcat( ' automated commit from GUI for data and settings for ' , { ' ' } , fname_settings ,{ ' @ ' }));
1228+ commit_cmd_setting = sprintf(' svn ci --username="%s " --password="%s " -m "%s "' , svn_user , svn_password , logmsg_setting );
1229+ [status , ~ ] = system(commit_cmd_setting );
11951230
11961231 if status == 0
11971232 log_message(handles , [' SVN commit successful for ' fname_data ]);
0 commit comments