%returns the segment onset times and an array of delay between each pair of
%corresponding onsets. Also takes two arrays containing segments where 

function [segs1,segs2, differences] = getOnsetsAndSynchronyWithFillin(csv1, csv2, fill1,fill2)



%load the two audio segmentations
cello = csvread(csv1);
violin = csvread(csv2);


%use only the segmentation times
celloSegmentations = cello(:,1);
violinSegmentations = violin(:,1);

celloFills = [];
celloFillsi = [];
violinFills = [];
violinFillsi = [];

'length of fill1'
length(fill1)
'length of fill2'
length(fill2)


for i = 1:length(fill1)
  
    segNumber = fill1(1,i);
     thisSegment = celloSegmentations(segNumber)
    
     segLength = celloSegmentations(segNumber+1) - celloSegmentations(segNumber);
     segDivision = segLength * (fill1(2,i)/4);
     newSegPosition = thisSegment + segDivision;
     
     celloFills(i) = newSegPosition;
     celloFillsi(i) = segNumber+1;
     
end


for i = 1:length(fill2)
  
    segNumber = fill2(1,i);
     thisSegment = violinSegmentations(segNumber)
    
     segLength = violinSegmentations(segNumber+1) - violinSegmentations(segNumber);
     segDivision = segLength * (fill2(2,i)/4);
     newSegPosition = thisSegment + segDivision;
     
     violinFills(i) = newSegPosition;
     violinFillsi(i) = segNumber+1;
     
end


celloFills
violinFills

%NOW FILL IN THE DATA

segs1 = zeros(1,length(celloSegmentations)+length(celloFills));
segs1(celloFillsi+(0:length(celloFillsi)-1)) = celloFills;
segs1(~segs1) = celloSegmentations

segs2 = zeros(1,length(violinSegmentations)+length(violinFills));
segs2(violinFillsi+(0:length(violinFillsi)-1)) = violinFills;
segs2(~segs2) = violinSegmentations

%average out the segmentation times



segs1
segs2

length(segs1)
length(segs2)

differences = (segs1 - segs2);





end