Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 3416)
@@ -106,13 +106,12 @@
 	 * @param max the max
 	 * @param basename the basename
 	 */
-	public XTZDefaultPagerStep(XTZPager pager, File infile, String txtname, List<String> NoSpaceBefore,
-	List<String> NoSpaceAfter, def cssList) {
+	public XTZDefaultPagerStep(XTZPager pager, File infile, String txtname, List<String> NoSpaceBefore, List<String> NoSpaceAfter, def cssList) {
 		this.pager = pager;
 		this.paginationElement = pager.page_element;
 		this.paginate = pager.paginate
 		this.cssList = cssList;
-		this.basename = pager.corpusname;
+		this.c = pager.corpusname;
 		this.txtname = txtname;
 		this.outdir = pager.outputDirectory;
 		this.wordmax = pager.wordsPerPage;
@@ -410,6 +409,8 @@
 								pagedWriter.writeAttribute("class", "sync")
 								if (parser.getAttributeValue(null,"time") != null) {
 									pagedWriter.writeCharacters(parser.getAttributeValue(null,"time"))
+									
+									writeMediaAccess(parser.getAttributeValue(null,"time"), corpus, txtname)
 								}
 								break;
 							case "p":
@@ -635,7 +636,7 @@
 									endOfLastWord = lastword.subSequence(l-1, l)
 								}
 							
-								String interpvalue = anaValues.entrySet().join(", ")
+								String interpvalue = "- "+anaValues.entrySet().join("\n- ")+"\n- "+wordid
 							
 								if (NoSpaceBefore.contains(wordvalue) ||
 										NoSpaceAfter.contains(lastword) ||
@@ -704,4 +705,15 @@
 		}
 		return true;
 	}
+	
+	private void writeMediaAccess(def time) {
+		
+		pagedWriter.writeCharacters(" ");
+		pagedWriter.writeStartElement("a");
+		pagedWriter.writeAttribute("onclick", "txmcommand('id', 'org.txm.backtomedia.commands.function.BackToMedia', 'corpus', '"+basename+"', 'text', '"+txtname+"', 'time', '"+time+"')");
+		pagedWriter.writeAttribute("style", "cursor: pointer;")
+		pagedWriter.writeAttribute("class", "play-media")
+		pagedWriter.writeCharacters("▶");
+		pagedWriter.writeEndElement(); // a
+	}
 }
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImporter.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImporter.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImporter.groovy	(revision 3416)
@@ -378,7 +378,7 @@
 		
 		//if (wordTag != "w") {
 		if (!doTokenizeStep) {
-			println "No tokenization do to."
+			println "No tokenization to do."
 			// ConsoleProgressBar cpb = new ConsoleProgressBar(filesToProcess.size())
 			for (File f : filesToProcess) {
 				File outfile = new File(module.getBinaryDirectory(),"tokenized/"+f.getName());
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xml/pager.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xml/pager.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xml/pager.groovy	(revision 3416)
@@ -448,7 +448,8 @@
 							if (l > 0)
 								endOfLastWord = lastword.subSequence(l-1, l);
 
-							String interpvalue = anaValues.entrySet().join(", ")
+							anaValues.put("id", wordid)
+							String interpvalue = "- "+anaValues.entrySet().join("\n- ")
 							
 							if (NoSpaceBefore.contains(wordvalue) ||
 							NoSpaceAfter.contains(lastword) ||
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/pager.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/pager.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/pager.groovy	(revision 3416)
@@ -687,11 +687,11 @@
 							if (SIMPLE_TOOLTIP) {
 								if (type.contains("lemma") || type.contains("pos")) {
 									flaginterp=true;
-									interpvalue+=", ";
+									interpvalue+="\n- ";
 								}
 							} else {
 								flaginterp=true;
-								interpvalue+=", "+type+"="
+								interpvalue+="\n- "+type+"="
 							}
 							break;
 						
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/importer.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/importer.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/importer.groovy	(revision 3416)
@@ -188,7 +188,7 @@
 		
 		if (!doTokenizeStep) {
 			
-			println "No tokenization do to."
+			println "No tokenization to do."
 			cpb = new ConsoleProgressBar(files.length)
 			for (File f : files) {
 				File outfile = new File(tokenizedDir, f.getName());
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableV2Macro.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableV2Macro.groovy	(revision 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableV2Macro.groovy	(revision 3416)
@@ -1,407 +0,0 @@
-package org.txm.macro.transcription
-
-import java.nio.charset.Charset
-
-import java.time.LocalTime
-import java.time.format.DateTimeFormatter
-
-import org.eclipse.core.internal.localstore.IsSynchronizedVisitor
-import org.txm.utils.*
-import org.txm.utils.logger.*
-
-@Field @Option(name="metadataFile", usage="Tableau des metadonnées de sections", widget="FileOpen", required=true, def="")
-		File metadataFile;
-
-@Field @Option(name="trsDirectory", usage="Dossier qui contient les fichiers TRS", widget="Folder", required=true, def="")
-		File trsDirectory;
-
-@Field @Option(name="joinTRSColumn", usage="Colonne de jointure de transcription", widget="String", required=true, def="Lien notice principale")
-		def joinTRSColumn
-
-@Field @Option(name="startTimeColumn", usage="Colonne de timing de début de section", widget="String", required=true, def="antract_debut")
-		def startTimeColumn = "antract_debut"
-
-@Field @Option(name="endTimeColumn", usage="Colonne de timing de fin de section", widget="String", required=true, def="antract_fin")
-		def endTimeColumn = "antract_fin"
-
-@Field @Option(name="typeColumns", usage="Colonnes des métadonnées de type de section", widget="String", required=true, def="Titre propre")
-		def typeColumns
-
-@Field @Option(name="topicColumns", usage="Colonnes des métadonnées de topic de section", widget="String", required=true, def="Date de diffusion")
-		def topicColumns
-
-@Field @Option(name="metadataColumns", usage="Colonnes de metadonnées de section", widget="String", required=true, def="Titre propre;Date de diffusion;Identifiant de la notice;Notes du titre;Type de date;Durée;Genre;Langue VO / VE;Nature de production;Producteurs (Aff.);Thématique;Nom fichier segmenté (info);antract_video;antract_debut;antract_fin;antract_duree;antract_tc_type;antract_tc_date;Résumé;Séquences;Descripteurs (Aff. Lig.);Générique (Aff. Lig.)")
-		def metadataColumns
-
-@Field @Option(name="metadataColumnsGroups", usage="Colonnes des gruopes de metadonnées de section", widget="String", required=true, def="metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;secondary;secondary;secondary;secondary;secondary;secondary;secondary;text;text;text;text")
-		def metadataColumnsGroups
-
-@Field @Option(name="fixSectionsLimits", usage="Correction des limites de sections du tableau de metadonnees", widget="Boolean", required=true, def="true")
-		def fixSectionsLimits
-
-@Field @Option(name="sectionsMergeActivationThreashold", usage="marge d'erreur de corrections des limites de sections", widget="Float", required=true, def="1.0")
-		def sectionsMergeActivationThreashold
-
-@Field @Option(name="fixTurnsLimits", usage="Correction des limites de sections du tableau de metadonnees", widget="Boolean", required=true, def="true")
-		def fixTurnsLimits
-
-@Field @Option(name="turnsCutActivationThreashold", usage="marge d'erreur de corrections des limites de tours", widget="Float", required=true, def="0.1")
-		def turnsCutActivationThreashold
-
-@Field @Option(name="debug", usage="show debug messages", widget="String", required=true, def="false")
-		def debug
-
-if (!ParametersDialog.open(this)) return;
-debug = true
-
-typeColumns = typeColumns.split(";")
-topicColumns = topicColumns.split(";")
-metadataColumns = metadataColumns.split(";")
-metadataColumnsGroups = metadataColumnsGroups.split(";")
-
-if (metadataColumns.size() != metadataColumnsGroups.size()) {
-	println "ERROR in metadata declarations&groups:"
-	println "COLUMNS: "+metadataColumns
-	println "GROUPS : "+metadataColumnsGroups
-	return
-}
-
-if (!trsDirectory.exists()) {
-	println "$trsDirectory not found"
-	return
-}
-
-println "Loading data from $metadataFile..."
-TableReader reader = new TableReader(metadataFile)//, "\t".charAt(0), Charset.forName("UTF-8")
-reader.readHeaders()
-def header = reader.getHeaders()
-if (!header.contains(joinTRSColumn)) {
-	println "No TRS ID $joinTRSColumn column found"
-	return
-}
-if (!header.contains(startTimeColumn)) {
-	println "No start time $startTimeColumn column found"
-	return
-}
-if (!header.contains(endTimeColumn)) {
-	println "No end time $endTimeColumn column found"
-	return
-}
-for (def col : metadataColumns) {
-	if (!header.contains(endTimeColumn)) {
-		println "No $col column found"
-		return
-	}
-}
-for (def col : typeColumns) {
-	if (!header.contains(endTimeColumn)) {
-		println "No type $col column found"
-		return
-	}
-}
-for (def col : topicColumns) {
-	if (!header.contains(endTimeColumn)) {
-		println "No topic $col column found"
-		return
-	}
-}
-
-File outputDirectory = new File(trsDirectory, "out")
-println "Writing result to $outputDirectory..."
-
-dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_TIME
-def strTotime(def str) {
-	if (str.lastIndexOf(":") == -1) {
-		return null
-	}
-	
-	bonusFrame = Integer.parseInt(str.substring(str.lastIndexOf(":")+1))
-	//if (str.contains("135475")) println "ERROR $str in $infos -> $bonusFrame"
-	if (bonusFrame > 25) {
-		bonusFrame=0;
-	}
-	totalFrame = str.substring(0, str.lastIndexOf(":"))
-	
-	LocalTime time1 = LocalTime.parse(totalFrame, dateTimeFormatter)
-	totalFrame = (time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond()
-	
-	def ret = totalFrame + (bonusFrame/25)
-	return ret
-}
-
-try {
-	def sectionGroupsToInsert = [:]
-	println "Reading data..."
-	while (reader.readRecord()) { // loading & sorting sections
-		String id = reader.get(joinTRSColumn).trim()
-		if (id.endsWith(".mp4")) id = id.substring(0, id.length()-4)
-		if (id.length() == 0) continue;
-		
-		if (!sectionGroupsToInsert.containsKey(id)) {
-			sectionGroupsToInsert[id] = []
-		}
-		def section = sectionGroupsToInsert[id]
-		
-		if (reader.get(startTimeColumn) != null && reader.get(startTimeColumn).length() > 0) { // ignore non timed sections
-			
-			def m = [:]
-			
-			for (def todo : ["topic":topicColumns, "type":typeColumns]) {
-				def data = []
-				for (def col : todo.value) {
-					if (reader.get(col).trim().length() > 0) {
-						data << reader.get(col).trim().replace("\n", "")
-					}
-				}
-				m[todo.key] = data.join("\t")
-			}
-			def metadataList = []
-			def metadataGroupList = []
-			for (int i = 0 ;  i < metadataColumns.size() ; i++) {
-				def col = metadataColumns[i]
-				String c = AsciiUtils.buildAttributeId(col)
-				m[c] = reader.get(col)
-				metadataList << c
-				metadataGroupList << metadataColumnsGroups[i]
-			}
-			m["metadata"] = metadataList.join("|")
-			m["metadata_groups"] = metadataGroupList.join("|")
-			
-			m["startTime"] = strTotime(reader.get(startTimeColumn))
-			m["endTime"] = strTotime(reader.get(endTimeColumn))
-			m["synchronized"] = "true"
-			
-			section << [m["startTime"], m["endTime"], m]
-		}
-	}
-	
-	println "Inserting sections... "+sectionGroupsToInsert.size()
-	
-	ConsoleProgressBar cpb = new ConsoleProgressBar(sectionGroupsToInsert.keySet().size())
-	for (String id : sectionGroupsToInsert.keySet()) {
-		
-		File trsFile = new File(trsDirectory, id+".trs")
-		if (!trsFile.exists()) {
-			cpb.tick()
-			continue
-		}
-		
-		if (debug) println "== $id =="
-		else cpb.tick()
-		
-		//println "Processing $id..."
-		sections = sectionGroupsToInsert[id]
-		sections = sections.sort() { a, b -> a[0] <=> b[0] ?: a[1] <=> -b[1] } // negative second test for sections inclusion
-		
-		if (fixSectionsLimits) {
-			if (debug) println "Fixing sections of $id"
-			for (int iSection = 1 ; iSection < sections.size() ; iSection++) {
-				//println sections[iSection]
-				if (Math.abs(sections[iSection][0] - sections[iSection - 1][1]) < sectionsMergeActivationThreashold) {
-					if (debug) println "s=$iSection start <- end : "+sections[iSection][0]+ " <- "+sections[iSection - 1][1]
-					sections[iSection][0] = sections[iSection - 1][1] // fix the start time with the previous section end time
-				}
-			}
-		}
-		
-		// Open input file
-		slurper = new groovy.util.XmlParser(false, true, true);
-		slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) // allow DTD declaration
-		slurper.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "all"); // allow to read DTD from local file
-		trs = slurper.parse(trsFile.toURI().toString())
-		trsEpisodes = trs.Episode // 1
-		if (trsEpisodes.size() > 1) {
-			println "Error: multiple Episode node in $trsFile"
-			continue
-		}
-		def trsEpisode = trsEpisodes[0]
-		def trsSections =  trs.Episode.Section // 1
-		if (trsSections.size() > 1) {
-			println "Error: multiple Section node in $trsFile"
-			continue
-		}
-		
-		trsSection = trsSections[0]
-		
-		turns = trsSection.Turn
-		newSections = []
-		iSection = 0;
-		currentSection = null
-		currentNode = null
-		
-		foundSection=null
-		isTurnSynchronized=false
-		cutCheck=false
-		
-		// boucle sur les tours dans l'ordre
-		for (iTurn = 0 ; iTurn < turns.size() ; iTurn++) {
-			
-			turn = turns[iTurn]
-			start = Float.parseFloat(turn.@startTime)
-			end = Float.parseFloat(turn.@endTime)
-			//println "Turn: $iTurn ($start, $end)"
-			
-			// Etape 1 : y aura-t-il besoin de couper le tour, et dans quelle section est le tour (ou sa première partie)
-			foundSection = null;
-			for (int i = iSection ; i < sections.size() ; i++) {
-				// if section_end < turn_start OU |turn_start - section_end| < turn_threshold
-				if (sections[i][1] < start || Math.abs(start - sections[i][1]) < turnsCutActivationThreashold) { // Turn is after section
-					// Cas 1 : la section est complètement avant (modulo la marge)
-				} else {
-					// Cas 2 : on est arrivés à la section à considérer
-					iSection = i
-					// if section_start > turn_end OU |section_start - turn_end| < turn_threshold
-					if (sections[i][0] > end || Math.abs(sections[i][0] - end) < turnsCutActivationThreashold) { // Turn is before section
-						// Cas 2.1 : la section est complètement après (modulo la marge) (et les suivantes le seront aussi)
-						foundSection = null
-						isTurnSynchronized = false
-						cutCheck = false
-					} else {
-						// if |section_start - turn_start| > turn_threshold
-						if (Math.abs(start - sections[i][0]) > turnsCutActivationThreashold) { // Turn begins before section does
-							// Cas 2.2 : la section commence significativement après le début du tour (le début est non synchronisé)
-							foundSection = sections[i] // (c'est la première section rencontrée, mais elle sera pour le tour suivant)
-							isTurnSynchronized = false
-							cutCheck = true
-						} else {
-							// Cas 2.3 : le début du tour est dans la section (on n'a pas besoin de chercher d'autres sections car si ce n'est pas la seule on coupera le tour et ce sera un autre tour).
-							foundSection = sections[i]  // (c'est la section qui commence le tour, au moins)
-							isTurnSynchronized = true
-							cutCheck = true
-						}
-					}
-					break; // stop searching and set iSection to accelerate next search
-				}
-			}
-			
-			// Etape 2 : positionne *le* tour dans *le* noeud
-			// (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 (foundSection != currentSection || currentSection == null) {
-					if (currentNode != null && currentNode.@synchronized == "false") {
-						def tmp = currentNode.Turn
-						currentNode.@endTime = tmp[-1].@endTime
-					}
-					
-					currentSection = foundSection
-					currentNode = new Node(trsEpisode, "Section", currentSection[2])
-				}
-			} else { // on complète ou on ajoute un noeud (div) non synchronisé.
-				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":sections[iSection][0], "endTime":sections[iSection][1], "synchronized":"false"] )
-				    currentSection = null;
-                }
-			}
-			
-			// Etape 3 : on coupe le tour s'il y a besoin
-			if (cutCheck && fixTurnsLimits) {
-				if (isTurnSynchronized) {
-					cutTurn(true) // iSection++  et test avec le **end** de la section quand on coupe
-				} else {
-					if (foundSection != null) {
-						cutTurn(false) // test avec le **start** de la section quand on coupe
-					}
-				}
-			}
-			
-			trsSection.remove(turn)
-			currentNode.append(turn)
-		}
-		
-		outputDirectory.mkdir()
-		File outfile = new File(outputDirectory, trsFile.getName())
-		outfile.withWriter("UTF-8") { writer ->
-			writer.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE Trans SYSTEM "trans-14.dtd">\n')
-			def printer = new groovy.util.XmlNodePrinter(new PrintWriter(writer))
-			printer.setPreserveWhitespace(true)
-			printer.print(trs)
-		}
-	}
-	cpb.done()
-	reader.close()
-	println "Done."
-	
-} catch(Exception e) {
-	println "Error: "+e
-	Log.printStackTrace(e)
-}
-
-def cutTurn(def testWithSectionEndTime) {
-	def children = turn.children()
-	Node newTurnKaNode = null;//new Node(trsEpisode, "Turn", currentSection[2])
-	
-	def startSection = currentNode.@startTime
-	if (startSection instanceof String) startSection = Float.parseFloat(currentNode.@startTime)
-	def endSection = currentNode.@endTime
-	if (endSection instanceof String) endSection = Float.parseFloat(currentNode.@endTime)
-	//println "Cut the last turn if necessary"
-	for (int iChildren = 0 ; iChildren < children.size() ; iChildren++) {
-		
-		def c = children[iChildren]
-		if (c instanceof String) continue;
-		
-		if (newTurnKaNode != null) { // append the remaining children to the new turn
-			turn.remove(c)
-			newTurnKaNode.append(c)
-			if (debug) c.@moved="yes"
-			iChildren--
-		} else {
-			if ("w".equals(c.name())) {
-				def start2 = Float.parseFloat(c.@startTime)
-				def end2 = Float.parseFloat(c.@endTime)
-                    
-                boolean test = null
-                if (testWithSectionEndTime) {
-                   test = start2 > endSection
-                } else {
-                   test = start2 >= startSection
-                }
-				
-				if (test) { // && Math.abs(start2 - endSection) > turnsCutActivationThreashold // no more needed
-					if (debug) println "cut with a w at ($start2, $end2) for section ("+startSection+", "+endSection+")"
-					newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
-                    new Node(newTurnKaNode, "Sync", ["time":""+start2]) // TRS
-					turns.add(iTurn, newTurnKaNode)
-					iTurn--
-					if (debug) newTurnKaNode.@created = "yes"
-					turn.@endTime = ""+start2;
-					turn.remove(c)
-					newTurnKaNode.append(c)
-					
-					if (debug) c.@moved="yes"
-					if (testWithSectionEndTime) iSection++
-					iChildren--
-				}
-			} else if ("Sync".equals(c.name())) {
-				def start2 = c.@time
-				if (start2 instanceof String) start2 = Float.parseFloat(c.@time)
-				def end2 = start2
-                    
-                boolean test = null
-                if (testWithSectionEndTime) {
-                   test = start2 > endSection
-                } else {
-                   test = start2 >= startSection
-                }
-				
-				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)
-					iTurn--
-					if (debug) newTurnKaNode.@created = "yes"
-					turn.@endTime = ""+start2;
-					turn.remove(c)
-					if (debug) c.@moved="yes"
-					if (testWithSectionEndTime) iSection++
-					newTurnKaNode.append(c)
-					iChildren--
-				}
-			} else {
-				// no time to check
-			}
-		}
-	}
-}
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacroOld.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacroOld.groovy	(revision 0)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacroOld.groovy	(revision 3416)
@@ -0,0 +1,384 @@
+package org.txm.macro.transcription
+
+import java.nio.charset.Charset
+
+import java.time.LocalTime
+import java.time.format.DateTimeFormatter
+import org.txm.utils.*
+import org.txm.utils.logger.*
+
+@Field @Option(name="metadataFile", usage="Tableau des metadonnées de sections", widget="FileOpen", required=true, def="")
+		File metadataFile;
+
+@Field @Option(name="trsDirectory", usage="Dossier qui contient les fichiers TRS", widget="Folder", required=true, def="")
+		File trsDirectory;
+
+@Field @Option(name="joinTRSColumn", usage="Colonne de jointure de transcription", widget="String", required=true, def="Lien notice principale")
+		def joinTRSColumn
+
+@Field @Option(name="startTimeColumn", usage="Colonne de timing de début de section", widget="String", required=true, def="antract_debut")
+		def startTimeColumn = "antract_debut"
+
+@Field @Option(name="endTimeColumn", usage="Colonne de timing de fin de section", widget="String", required=true, def="antract_fin")
+		def endTimeColumn = "antract_fin"
+
+@Field @Option(name="typeColumns", usage="Colonnes des métadonnées de type de section", widget="String", required=true, def="Titre propre")
+		def typeColumns
+
+@Field @Option(name="topicColumns", usage="Colonnes des métadonnées de topic de section", widget="String", required=true, def="Date de diffusion")
+		def topicColumns
+
+@Field @Option(name="metadataColumns", usage="Colonnes de metadonnées de section", widget="String", required=true, def="Titre propre;Date de diffusion;Identifiant de la notice;Notes du titre;Type de date;Durée;Genre;Langue VO / VE;Nature de production;Producteurs (Aff.);Thématique;Nom fichier segmenté (info);antract_video;antract_debut;antract_fin;antract_duree;antract_tc_type;antract_tc_date;Résumé;Séquences;Descripteurs (Aff. Lig.);Générique (Aff. Lig.)")
+		def metadataColumns
+
+@Field @Option(name="metadataColumnsGroups", usage="Colonnes des gruopes de metadonnées de section", widget="String", required=true, def="metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;metadata;secondary;secondary;secondary;secondary;secondary;secondary;secondary;text;text;text;text")
+		def metadataColumnsGroups
+
+@Field @Option(name="fixSectionsLimits", usage="Correction des limites de sections du tableau de metadonnees", widget="Boolean", required=true, def="true")
+		def fixSectionsLimits
+
+@Field @Option(name="sectionsMergeActivationThreashold", usage="marge d'erreur de corrections des limites de sections", widget="Float", required=true, def="1.0")
+		def sectionsMergeActivationThreashold
+
+@Field @Option(name="fixTurnsLimits", usage="Correction des limites de sections du tableau de metadonnees", widget="Boolean", required=true, def="true")
+		def fixTurnsLimits
+
+@Field @Option(name="turnsCutActivationThreashold", usage="marge d'erreur de corrections des limites de tours", widget="Float", required=true, def="0.1")
+		def turnsCutActivationThreashold
+
+@Field @Option(name="debug", usage="show debug messages", widget="String", required=true, def="false")
+		def debug
+
+if (!ParametersDialog.open(this)) return;
+
+typeColumns = typeColumns.split(";")
+topicColumns = topicColumns.split(";")
+metadataColumns = metadataColumns.split(";")
+metadataColumnsGroups = metadataColumnsGroups.split(";")
+
+if (metadataColumns.size() != metadataColumnsGroups.size()) {
+	println "ERROR in metadata declarations&groups:"
+	println "COLUMNS: "+metadataColumns
+	println "GROUPS : "+metadataColumnsGroups
+	return
+}
+
+if (!trsDirectory.exists()) {
+	println "$trsDirectory not found"
+	return
+}
+
+println "Loading data from $metadataFile..."
+TableReader reader = new TableReader(metadataFile)//, "\t".charAt(0), Charset.forName("UTF-8")
+reader.readHeaders()
+def header = reader.getHeaders()
+if (!header.contains(joinTRSColumn)) {
+	println "No TRS ID $joinTRSColumn column found"
+	return
+}
+if (!header.contains(startTimeColumn)) {
+	println "No start time $startTimeColumn column found"
+	return
+}
+if (!header.contains(endTimeColumn)) {
+	println "No end time $endTimeColumn column found"
+	return
+}
+for (def col : metadataColumns) {
+	if (!header.contains(endTimeColumn)) {
+		println "No $col column found"
+		return
+	}
+}
+for (def col : typeColumns) {
+	if (!header.contains(endTimeColumn)) {
+		println "No type $col column found"
+		return
+	}
+}
+for (def col : topicColumns) {
+	if (!header.contains(endTimeColumn)) {
+		println "No topic $col column found"
+		return
+	}
+}
+
+File outputDirectory = new File(trsDirectory, "out")
+println "Writing result to $outputDirectory..."
+
+dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_TIME
+def strTotime(def str) {
+	if (str.lastIndexOf(":") == -1) {
+		return null
+	}
+	
+	bonusFrame = Integer.parseInt(str.substring(str.lastIndexOf(":")+1))
+	//if (str.contains("135475")) println "ERROR $str in $infos -> $bonusFrame"
+	if (bonusFrame > 25) {
+		bonusFrame=0;
+	}
+	totalFrame = str.substring(0, str.lastIndexOf(":"))
+	
+	LocalTime time1 = LocalTime.parse(totalFrame, dateTimeFormatter)
+	totalFrame = (time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond()
+	
+	def ret = totalFrame + (bonusFrame/25)
+	return ret
+}
+
+try {
+	def sectionGroupsToInsert = [:]
+	println "Reading data..."
+	while (reader.readRecord()) { // loading & sorting sections
+		String id = reader.get(joinTRSColumn).trim()
+		if (id.endsWith(".mp4")) id = id.substring(0, id.length()-4)
+		if (id.length() == 0) continue;
+		
+		if (!sectionGroupsToInsert.containsKey(id)) {
+			sectionGroupsToInsert[id] = []
+		}
+		def section = sectionGroupsToInsert[id]
+		
+		if (reader.get(startTimeColumn) != null && reader.get(startTimeColumn).length() > 0) { // ignore non timed sections
+			
+			def m = [:]
+			
+			for (def todo : ["topic":topicColumns, "type":typeColumns]) {
+				def data = []
+				for (def col : todo.value) {
+					if (reader.get(col).trim().length() > 0) {
+						data << reader.get(col).trim().replace("\n", "")
+					}
+				}
+				m[todo.key] = data.join("\t")
+			}
+			def metadataList = []
+			def metadataGroupList = []
+			for (int i = 0 ;  i < metadataColumns.size() ; i++) {
+				def col = metadataColumns[i]
+				String c = AsciiUtils.buildAttributeId(col)
+				m[c] = reader.get(col)
+				metadataList << c
+				metadataGroupList << metadataColumnsGroups[i]
+			}
+			m["metadata"] = metadataList.join("|")
+			m["metadata_groups"] = metadataGroupList.join("|")
+			
+			m["startTime"] = strTotime(reader.get(startTimeColumn))
+			m["endTime"] = strTotime(reader.get(endTimeColumn))
+			m["synchronized"] = "true"
+			
+			section << [m["startTime"], m["endTime"], m]
+		}
+	}
+	
+	println "Inserting sections... "+sectionGroupsToInsert.size()
+	
+	ConsoleProgressBar cpb = new ConsoleProgressBar(sectionGroupsToInsert.keySet().size())
+	for (String id : sectionGroupsToInsert.keySet()) {
+		
+		File trsFile = new File(trsDirectory, id+".trs")
+		if (!trsFile.exists()) {
+			cpb.tick()
+			continue
+		}
+		
+		if (debug) println "== $id =="
+		else cpb.tick()
+		
+		//println "Processing $id..."
+		def sections = sectionGroupsToInsert[id]
+		sections = sections.sort() { a, b -> a[0] <=> b[0] ?: a[1] <=> -b[1] } // negative second test for sections inclusion
+		
+		if (fixSectionsLimits) {
+			if (debug) println "Fixing sections of $id"
+			for (int iSection = 1 ; iSection < sections.size() ; iSection++) {
+				//println sections[iSection]
+				if (Math.abs(sections[iSection][0] - sections[iSection - 1][1]) < sectionsMergeActivationThreashold) {
+					if (debug) println "s=$iSection start <- end : "+sections[iSection][0]+ " <- "+sections[iSection - 1][1]
+					sections[iSection][0] = sections[iSection - 1][1] // fix the start time with the previous section end time
+				}
+			}
+		}
+		
+		// Open input file
+		def slurper = new groovy.util.XmlParser(false, true, true);
+		slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) // allow DTD declaration
+		slurper.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "all"); // allow to read DTD from local file
+		def trs = slurper.parse(trsFile.toURI().toString())
+		def trsEpisodes = trs.Episode // 1
+		if (trsEpisodes.size() > 1) {
+			println "Error: multiple Episode node in $trsFile"
+			continue
+		}
+		def trsEpisode = trsEpisodes[0]
+		def trsSections =  trs.Episode.Section // 1
+		if (trsSections.size() > 1) {
+			println "Error: multiple Section node in $trsFile"
+			continue
+		}
+		def trsSection = trsSections[0]
+		
+		def turns = trsSection.Turn
+		def newSections = []
+		def iSection = 0;
+		def currentSection = null
+		def currentNode = null
+		
+		for (int iTurn = 0 ; iTurn < turns.size() ; iTurn++) {
+			
+			def turn = turns[iTurn]
+			def start = Float.parseFloat(turn.@startTime)
+			def end = Float.parseFloat(turn.@endTime)
+			//println "Turn: $iTurn ($start, $end)"
+			
+			def foundSection = null;
+			for (int i = iSection ; i < sections.size() ; i++) {
+				if (end < sections[i][0]) { // the Turn is before the section
+					
+				} else if (sections[i][1] < start) { // the Turn is after the section
+					
+				} else {
+					foundSection = sections[i]
+					iSection = i
+					break; // stop searching and set iSection to accelerate next search
+				}
+			}
+			
+			if (foundSection == null) {
+				if (currentSection != null || currentNode == null) {
+					currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":turn.@startTime, "endTime":"", "synchronized":"false"] )
+					currentSection = null;
+				}
+			} else {
+				if (foundSection != currentSection) {
+					if (currentNode != null && currentNode.@synchronized == "false") { // set the un-synchronized section endTime using its last Turn endTime
+						def tmp = currentNode.Turn
+						currentNode.@endTime = tmp[-1].@endTime
+					}
+					
+					currentSection = foundSection
+					currentNode = new Node(trsEpisode, "Section", currentSection[2])
+				}
+			}
+			
+			trsSection.remove(turn)
+			currentNode.append(turn)
+		}
+		
+		//remove the initial section which is empty now
+		trsEpisode.remove(trsSection)
+		
+		if (fixTurnsLimits) {
+			if (debug) println "Fixing Turn limits..."
+			def partOfTurnToInsertInthePreviousSection = null;
+			def partOfTurnToInsertIntheNextSection = null;
+			sections = trs.Episode.Section
+			for (int i = 0 ; i < sections.size() ; i++) { // browse created sections but stop before the last one (whichc can not be fixed)
+				
+				def section = sections[i]
+				if (partOfTurnToInsertIntheNextSection != null) {
+					if (debug) println "Moving part-of turn: "+partOfTurnToInsertIntheNextSection+" in section ("+section.@startTime+", "+section.@endTime+")"
+					section.children().add(0, partOfTurnToInsertIntheNextSection) // insert the slited part of the turn in the section
+				}
+				
+				def startSection = section.@startTime // Float.parseFloat(section.@startTime)
+				def endSection = section.@endTime //  Float.parseFloat(section.@endTime)
+				if (startSection instanceof String) startSection = Float.parseFloat(section.@startTime)
+				if (endSection instanceof String) endSection = Float.parseFloat(section.@endTime)
+				
+				partOfTurnToInsertInthePreviousSection = null
+				partOfTurnToInsertIntheNextSection = null
+				
+				turns = section.Turn
+				if (turns.size() == 0) continue;
+				
+				// Fix the first Turn
+				def turn = turns[0]
+				start = turn.@startTime // Float.parseFloat(section.@startTime)
+				end = turn.@endTime //  Float.parseFloat(section.@endTime)
+				if (start instanceof String) start = Float.parseFloat(turn.@startTime)
+				if (end instanceof String) end = Float.parseFloat(turn.@endTime)
+				
+				if (start < startSection) { // the start of the Turn is outside of its current section
+					
+				}
+				
+				// Fix the last Turn
+				turn = turns[-1]
+				start = turn.@startTime // Float.parseFloat(section.@startTime)
+				end = turn.@endTime //  Float.parseFloat(section.@endTime)
+				if (start instanceof String) start = Float.parseFloat(turn.@startTime)
+				if (end instanceof String) end = Float.parseFloat(turn.@endTime)
+				if (end > endSection) { // the end of the Turn is outside of its current section
+					
+					def children = turn.children()
+					Node newTurnKaNode = null;//new Node(trsEpisode, "Turn", currentSection[2])
+					//println "Cut the last turn if necessary"
+					for (int iChildren = 0 ; iChildren < children.size() ; iChildren++) {
+						
+						def c = children[iChildren]
+						if (c instanceof String) continue;
+						
+						if (newTurnKaNode != null) {
+							turn.remove(c)
+							newTurnKaNode.append(c)
+							if (debug) c.@moved="yes"
+							iChildren--
+						} else {
+							if ("w".equals(c.name())) {
+								def start2 = Float.parseFloat(c.@startTime)
+								def end2 = Float.parseFloat(c.@endTime)
+								
+								if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
+									if (debug) println "cut with a w at [$start2, $end2] for section ("+startSection+", "+endSection+")"
+									newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
+									if (debug) newTurnKaNode.@created = "yes"
+									turn.@endTime = ""+start2;
+									turn.remove(c)
+									newTurnKaNode.append(c)
+									if (debug) c.@moved="yes"
+									iChildren--
+								}
+							} else if ("Sync".equals(c.name())) {
+								def start2 = Float.parseFloat(c.@time)
+								def end2 = Float.parseFloat(c.@time)
+								
+								if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
+									if (debug) println "cut with a Sync at [$start2, $end2] for section "+endSection
+									newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
+									if (debug) newTurnKaNode.@created = "yes"
+									turn.@endTime = ""+start2;
+									turn.remove(c)
+									if (debug) c.@moved="yes"
+									newTurnKaNode.append(c)
+									iChildren--
+								}
+							} else {
+								// no time to check
+							}
+						}
+					}
+					
+				}
+				partOfTurnToInsertIntheNextSection = newTurnKaNode
+			}
+		}
+		
+		outputDirectory.mkdir()
+		File outfile = new File(outputDirectory, trsFile.getName())
+		outfile.withWriter("UTF-8") { writer ->
+			writer.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE Trans SYSTEM "trans-14.dtd">\n')
+			def printer = new groovy.util.XmlNodePrinter(new PrintWriter(writer))
+			printer.setPreserveWhitespace(true)
+			printer.print(trs)
+		}
+	}
+	cpb.done()
+	reader.close()
+	println "Done."
+	
+} catch(Exception e) {
+	println "Error: "+e
+	Log.printStackTrace(e)
+}
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 3415)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableMacro.groovy	(revision 3416)
@@ -4,6 +4,8 @@
 
 import java.time.LocalTime
 import java.time.format.DateTimeFormatter
+
+import org.eclipse.core.internal.localstore.IsSynchronizedVisitor
 import org.txm.utils.*
 import org.txm.utils.logger.*
 
@@ -39,18 +41,17 @@
 
 @Field @Option(name="sectionsMergeActivationThreashold", usage="marge d'erreur de corrections des limites de sections", widget="Float", required=true, def="1.0")
 		def sectionsMergeActivationThreashold
-		
+
 @Field @Option(name="fixTurnsLimits", usage="Correction des limites de sections du tableau de metadonnees", widget="Boolean", required=true, def="true")
 		def fixTurnsLimits
 
 @Field @Option(name="turnsCutActivationThreashold", usage="marge d'erreur de corrections des limites de tours", widget="Float", required=true, def="0.1")
 		def turnsCutActivationThreashold
 
-@Field @Option(name="debug", usage="show debug messages", widget="String", required=true, def="false")
+@Field @Option(name="debug", usage="show debug messages", widget="Boolean", required=true, def="false")
 		def debug
 
 if (!ParametersDialog.open(this)) return;
-debug = true
 
 typeColumns = typeColumns.split(";")
 topicColumns = topicColumns.split(";")
@@ -188,7 +189,7 @@
 		else cpb.tick()
 		
 		//println "Processing $id..."
-		def sections = sectionGroupsToInsert[id]
+		sections = sectionGroupsToInsert[id]
 		sections = sections.sort() { a, b -> a[0] <=> b[0] ?: a[1] <=> -b[1] } // negative second test for sections inclusion
 		
 		if (fixSectionsLimits) {
@@ -203,11 +204,11 @@
 		}
 		
 		// Open input file
-		def slurper = new groovy.util.XmlParser(false, true, true);
+		slurper = new groovy.util.XmlParser(false, true, true);
 		slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) // allow DTD declaration
 		slurper.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "all"); // allow to read DTD from local file
-		def trs = slurper.parse(trsFile.toURI().toString())
-		def trsEpisodes = trs.Episode // 1
+		trs = slurper.parse(trsFile.toURI().toString())
+		trsEpisodes = trs.Episode // 1
 		if (trsEpisodes.size() > 1) {
 			println "Error: multiple Episode node in $trsFile"
 			continue
@@ -218,41 +219,66 @@
 			println "Error: multiple Section node in $trsFile"
 			continue
 		}
-		def trsSection = trsSections[0]
 		
-		def turns = trsSection.Turn
-		def newSections = []
-		def iSection = 0;
-		def currentSection = null
-		def currentNode = null
+		trsSection = trsSections[0]
 		
-		for (int iTurn = 0 ; iTurn < turns.size() ; iTurn++) {
-			
-			def turn = turns[iTurn]
-			def start = Float.parseFloat(turn.@startTime)
-			def end = Float.parseFloat(turn.@endTime)
+		turns = trsSection.Turn
+		newSections = []
+		iSection = 0;
+		currentSection = null
+		currentNode = null
+		
+		foundSection=null
+		isTurnSynchronized=false
+		cutCheck=false
+		
+		// boucle sur les tours dans l'ordre
+		for (iTurn = 0 ; iTurn < turns.size() ; iTurn++) {
+			if (debug) println "iTurn=$iTurn turn="+turns[iTurn].attributes()
+			turn = turns[iTurn]
+			start = Float.parseFloat(turn.@startTime)
+			end = Float.parseFloat(turn.@endTime)
 			//println "Turn: $iTurn ($start, $end)"
 			
-			def foundSection = null;
+			// Etape 1 : y aura-t-il besoin de couper le tour, et dans quelle section est le tour (ou sa première partie)
+			foundSection = null;
 			for (int i = iSection ; i < sections.size() ; i++) {
-				if (end < sections[i][0]) { // Turn is before section
-					
-				} else if (sections[i][1] < start) { // Section is before section
-					
+				// if section_end < turn_start OU |turn_start - section_end| < turn_threshold
+				if (sections[i][1] < start || Math.abs(start - sections[i][1]) < turnsCutActivationThreashold) { // Turn is after section
+					// Cas 1 : la section est complètement avant (modulo la marge)
 				} else {
-					foundSection = sections[i]
+					// Cas 2 : on est arrivés à la section à considérer
 					iSection = i
+					// if section_start > turn_end OU |section_start - turn_end| < turn_threshold
+					if (sections[i][0] > end || Math.abs(sections[i][0] - end) < turnsCutActivationThreashold) { // Turn is before section
+						// Cas 2.1 : la section est complètement après (modulo la marge) (et les suivantes le seront aussi)
+						foundSection = null
+						isTurnSynchronized = false
+						cutCheck = false
+					} else {
+						// if |section_start - turn_start| > turn_threshold
+						if (start - sections[i][0] < 0) { // Turn begins before section does
+							// Cas 2.2 : la section commence significativement après le début du tour (le début est non synchronisé)
+							foundSection = sections[i] // (c'est la première section rencontrée, mais elle sera pour le tour suivant)
+							isTurnSynchronized = false
+							cutCheck = true
+						} else {
+							// Cas 2.3 : le début du tour est dans la section (on n'a pas besoin de chercher d'autres sections car si ce n'est pas la seule on coupera le tour et ce sera un autre tour).
+							foundSection = sections[i]  // (c'est la section qui commence le tour, au moins)
+							isTurnSynchronized = true
+							cutCheck = true
+						}
+					}
 					break; // stop searching and set iSection to accelerate next search
 				}
 			}
 			
-			if (foundSection == null) {
-				if (currentSection != null || currentNode == null) {
-					currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":turn.@startTime, "endTime":"", "synchronized":"false"] )
-					currentSection = null;
-				}
-			} else {
-				if (foundSection != currentSection) {
+			// Etape 2 : positionne *le* tour dans *le* noeud
+			// (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 (foundSection != currentSection || currentSection == null) {
 					if (currentNode != null && currentNode.@synchronized == "false") {
 						def tmp = currentNode.Turn
 						currentNode.@endTime = tmp[-1].@endTime
@@ -260,93 +286,37 @@
 					
 					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 (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;
+					if (debug) println " create un-synchronized turn at "+turn.@startTime
+                }
 			}
 			
+			// 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 (isTurnSynchronized) {
+					cutTurn(true) // iSection++  et test avec le **end** de la section quand on coupe
+				} else {
+					if (foundSection != null) {
+						cutTurn(false) // test avec le **start** de la iSection quand on coupe
+					}
+				}
+			}
+			
+			if (debug) println " remove turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
+			turns.remove(turn)
 			trsSection.remove(turn)
 			currentNode.append(turn)
+			if (debug) println " removed turn in turns ("+turns.size()+") section ("+trsSection.children().size()+")"
 		}
 		
-		//remove the initial section which is empty now or not
 		trsEpisode.remove(trsSection)
 		
-		if (fixTurnsLimits) {
-			if (debug) println "Fixing Turn limits..."
-			def turnToInsert = null;
-			sections = trs.Episode.Section
-			for (int i = 0 ; i < sections.size() -1 ; i++) { // browse created sections but stop before the last one (whichc can not be fixed)
-				
-				def section = sections[i]
-				if (turnToInsert != null) {
-					if (debug) println "Moving part-of turn: "+turnToInsert+" in section ("+section.@startTime+", "+section.@endTime+")"
-					section.children().add(0, turnToInsert) // insert the slited part of the turn in the section
-				}
-				
-				def startSection = section.@startTime // Float.parseFloat(section.@startTime)
-				def endSection = section.@endTime //  Float.parseFloat(section.@endTime)
-				if (startSection instanceof String) startSection = Float.parseFloat(section.@startTime)
-				if (endSection instanceof String) endSection = Float.parseFloat(section.@endTime)
-					
-				turnToInsert = null
-				
-				turns = section.Turn
-				if (turns.size() == 0) continue;
-				
-				def turn = turns[-1]
-				
-				def children = turn.children()
-				Node newTurnKaNode = null;//new Node(trsEpisode, "Turn", currentSection[2])
-				//println "Cut the last turn if necessary"
-				for (int iChildren = 0 ; iChildren < children.size() ; iChildren++) {
-					
-					def c = children[iChildren]
-					if (c instanceof String) continue;
-					
-					if (newTurnKaNode != null) {
-						turn.remove(c)
-						newTurnKaNode.append(c)
-						if (debug) c.@moved="yes"
-						iChildren--
-					} else {
-						if ("w".equals(c.name())) {
-							def start2 = Float.parseFloat(c.@startTime)
-							def end2 = Float.parseFloat(c.@endTime)
-							
-							if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
-								if (debug) println "cut with a w at [$start2, $end2] for section ("+startSection+", "+endSection+")"
-								newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
-								if (debug) newTurnKaNode.@created = "yes"
-								turn.@endTime = ""+start2;
-								turn.remove(c)
-								newTurnKaNode.append(c)
-								if (debug) c.@moved="yes"
-								iChildren--
-							}
-						} else if ("Sync".equals(c.name())) {
-							def start2 = Float.parseFloat(c.@time)
-							def end2 = Float.parseFloat(c.@time)
-							
-							if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
-								if (debug) println "cut with a Sync at [$start2, $end2] for section "+endSection
-								newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
-								if (debug) newTurnKaNode.@created = "yes"
-								turn.@endTime = ""+start2;
-								turn.remove(c)
-								if (debug) c.@moved="yes"
-								newTurnKaNode.append(c)
-								iChildren--
-							}
-						} else {
-							// no time to check
-						}
-					}
-				}
-				
-				turnToInsert = newTurnKaNode
-				
-			}
-		}
-		
 		outputDirectory.mkdir()
 		File outfile = new File(outputDirectory, trsFile.getName())
 		outfile.withWriter("UTF-8") { writer ->
@@ -364,3 +334,83 @@
 	println "Error: "+e
 	Log.printStackTrace(e)
 }
+
+def cutTurn(def testWithSectionEndTime) {
+	
+	def children = turn.children()
+	Node newTurnKaNode = null;//new Node(trsEpisode, "Turn", currentSection[2])
+	
+	def startSection = sections[iSection][0] // currentNode.@startTime
+	if (startSection instanceof String) startSection = Float.parseFloat(sections[iSection][0]) //currentNode.@startTime)
+	def endSection = sections[iSection][1] // currentNode.@endTime
+	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()
+	for (int iChildren = 0 ; iChildren < children.size() ; iChildren++) {
+		
+		def c = children[iChildren]
+		if (c instanceof String) continue; // a Turn contains Sync or w tags
+		
+		if (newTurnKaNode != null) { // append the remaining children to the new turn
+			turn.remove(c)
+			newTurnKaNode.append(c)
+			if (debug) c.@moved="yes"
+			iChildren--
+		} else {
+			if ("w".equals(c.name())) {
+				def start2 = Float.parseFloat(c.@startTime)
+				def end2 = Float.parseFloat(c.@endTime)
+                    
+                boolean test = null
+                if (testWithSectionEndTime) {
+                   test = start2 > endSection
+                } else {
+                   test = start2 >= startSection
+                }
+				
+				if (test) { // && Math.abs(start2 - endSection) > turnsCutActivationThreashold // no more needed
+					if (debug) println " cut with a w at ($start2, $end2) for section ("+startSection+", "+endSection+")"
+					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
+					iTurn--
+					if (debug) newTurnKaNode.@created = "yes"
+					turn.@endTime = ""+start2;
+					turn.remove(c)
+					newTurnKaNode.append(c)
+					
+					if (debug) c.@moved="yes"
+					iChildren--
+				}
+			} else if ("Sync".equals(c.name())) {
+				def start2 = c.@time
+				if (start2 instanceof String) start2 = Float.parseFloat(c.@time)
+				def end2 = start2
+                    
+                boolean test = null
+                if (testWithSectionEndTime) {
+                   test = start2 > endSection
+                } else {
+                   test = start2 >= startSection
+                }
+				
+				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)
+					iTurn--
+					if (debug) newTurnKaNode.@created = "yes"
+					turn.@endTime = ""+start2;
+					turn.remove(c)
+					if (debug) c.@moved="yes"
+					newTurnKaNode.append(c)
+					iChildren--
+				}
+			} else {
+				// no time to check
+			}
+		}
+	}
+}
