Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacro.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacro.groovy	(revision 3420)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacro.groovy	(revision 3421)
@@ -223,7 +223,6 @@
 		trsSection = trsSections[0]
 		
 		turns = trsSection.Turn
-		newSections = []
 		iSection = 0;
 		currentSection = null
 		currentNode = null
@@ -234,7 +233,7 @@
 		
 		// boucle sur les tours dans l'ordre
 		for (iTurn = 0 ; iTurn < turns.size() ; iTurn++) {
-			if (debug) println "iTurn=$iTurn turn="+turns[iTurn].attributes()
+			if (debug) println "iTurn=$iTurn turn="+turns[iTurn].attributes()+" iSection=$iSection ("+sections[iSection][0]+", "+sections[iSection][1]+")"
 			turn = turns[iTurn]
 			start = Float.parseFloat(turn.@startTime)
 			end = Float.parseFloat(turn.@endTime)
@@ -277,7 +276,7 @@
 			// (on ne gère qu'un seul tour et un seul noeud à chaque itération de la boucle tour,
 			// puisqu'on a retaillé le tour pour qu'il ne concerne pas plusieurs noeuds)
 			if (foundSection != null) { // on complète ou on ajoute une div.
-				
+				if (debug) println "found iSection=$iSection ("+sections[iSection][0]+", "+sections[iSection][1]+")"
 				if (foundSection != currentSection || currentSection == null) {
 					if (currentNode != null && currentNode.@synchronized == "false") {
 						def tmp = currentNode.Turn
@@ -287,8 +286,9 @@
 					currentSection = foundSection
 					currentNode = new Node(trsEpisode, "Section", currentSection[2])
 					if (debug) println " create synchronized turn at start="+foundSection[0]
-				}
+				} 
 			} else { // on complète ou on ajoute un noeud (div) non synchronisé.
+				if (debug) println "not synchronized with current iSection=$iSection ("+sections[iSection][0]+", "+sections[iSection][1]+")"
 				if (currentSection != null || currentNode == null) { // create a new unsynchronized section if there is no opened synchronized section or no un-synchronized section
 				    currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":turn.@startTime, "endTime":"", "synchronized":"false"] )
 				    currentSection = null;
@@ -298,7 +298,7 @@
 			
 			// Etape 3 : on coupe le tour s'il y a besoin
 			if (cutCheck && fixTurnsLimits) {
-				if (debug) println " fixing turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
+				if (debug) println " fixing current turn iTurn=$iTurn ($start, $end) )in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
 				if (isTurnSynchronized) {
 					cutTurn(true) // iSection++  et test avec le **end** de la section quand on coupe
 				} else {
@@ -308,11 +308,11 @@
 				}
 			}
 			
-			if (debug) println " remove turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
-			turns.remove(turn)
+			if (debug) println " remove turn in initial section ("+trsSection.children().size()+" remaining turns before removing this one)"
+			//turns.remove(turn)
 			trsSection.remove(turn)
 			currentNode.append(turn)
-			if (debug) println " removed turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
+			//if (debug) println " removed turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
 		}
 		
 		trsEpisode.remove(trsSection)
@@ -346,7 +346,7 @@
 	if (endSection instanceof String) endSection = Float.parseFloat(sections[iSection][1]) //currentNode.@endTime)
 	//println "Cut the last turn if necessary"
 		
-	if (debug) println " cut turn and test with end ? $testWithSectionEndTime of iSection=$iSection at iTurn=$iTurn start=${turn.@startTime} end=${turn.@endTime} children="+turn.children().size()
+	if (debug) println " cut turn and test with end ? $testWithSectionEndTime of iSection=$iSection ($startSection, $endSection) at iTurn=$iTurn (${turn.@startTime}, ${turn.@endTime}) children="+turn.children().size()
 	for (int iChildren = 0 ; iChildren < children.size() ; iChildren++) {
 		
 		def c = children[iChildren]
@@ -374,7 +374,7 @@
 					newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
                     new Node(newTurnKaNode, "Sync", ["time":""+start2]) // TRS
 					
-					turns.add(iTurn, newTurnKaNode) // set as next turn to process
+					turns.add(iTurn+1, newTurnKaNode) // set as next turn to process
 					iTurn--
 					if (debug) newTurnKaNode.@created = "yes"
 					turn.@endTime = ""+start2;
@@ -399,7 +399,7 @@
 				if (test) { //  && Math.abs(start2 - endSection) > turnsCutActivationThreashold
 					if (debug) println " cut with a Sync at ($start2, $end2) for section ("+startSection+", "+endSection+")"
 					newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
-					turns.add(iTurn, newTurnKaNode)
+					turns.add(iTurn+1, newTurnKaNode)
 					iTurn--
 					if (debug) newTurnKaNode.@created = "yes"
 					turn.@endTime = ""+start2;
