Integrated Freestyle to rendering pipeline
[blender.git] / release / scripts / blenderLipSynchro.py
1 #!BPY
2 # coding: utf-8
3 """
4 Name: 'BlenderLipSynchro'
5 Blender: 242
6 Group: 'Animation'
7 Tooltip: 'Import phonemes from Papagayo or JLipSync for lip synchronization'
8 """
9
10 __author__ = "Dienben: Benoit Foucque dienben_mail@yahoo.fr"
11 __url__ = ["blenderLipSynchro Blog, http://blenderlipsynchro.blogspot.com/",
12 "Papagayo (Python), http://www.lostmarble.com/papagayo/index.shtml",
13 "JLipSync (Java), http://jlipsync.sourceforge.net/"]
14 __version__ = "2.0"
15 __bpydoc__ = """\
16 Description:
17
18 This script imports Voice Export made by Papagayo or JLipSync and maps the export with your shapes.
19
20 Usage:
21
22 Import a Papagayo or JLipSync voice export file and link it with your shapes.
23
24 Note:<br>
25 - Naturally, you need files exported from one of the supported lip synching
26 programs. Check their sites to learn more and download them.
27
28 """
29
30 # --------------------------------------------------------------------------
31 # BlenderLipSynchro
32 # --------------------------------------------------------------------------
33 # ***** BEGIN GPL LICENSE BLOCK *****
34 #
35 # This program is free software; you can redistribute it and/or
36 # modify it under the terms of the GNU General Public License
37 # as published by the Free Software Foundation; either version 2
38 # of the License, or (at your option) any later version.
39 #
40 # This program is distributed in the hope that it will be useful,
41 # but WITHOUT ANY WARRANTY; without even the implied warranty of
42 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43 # GNU General Public License for more details.
44 #
45 # You should have received a copy of the GNU General Public License
46 # along with this program; if not, write to the Free Software Foundation,
47 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
48 #
49 # ***** END GPL LICENCE BLOCK *****
50 # -------------------------------------------------------------------------- 
51
52
53
54 #il y a 3 etapes
55 #la deuxieme on charge le dictionnaire de correspondance
56 #la troisieme on fait le choix des correpondance
57 #la quatrieme on construit les cles a partir du fichiers frame
58
59 #there are 3 stages
60 #the second one load the mapping dictionnary 
61 #the tird make the mapping
62 #the fourth make the key in the IPO Curve
63
64 #voici mes differents imports
65 #the imports
66 import os
67 import Blender
68
69 from Blender import Ipo
70 from Blender.Draw import *
71 from Blender.BGL import *
72 from Blender.sys import basename
73
74
75
76 #ici commencent mes fonctions
77 #here begin my functions
78 #cette fonction trace l'interface graphique
79 #this functions draw the User interface
80 def trace():
81         #voici mes variables pouvant etre modifie
82         #my variables
83         global nbr_phoneme, mon_fichier_dico
84         global let01, let02, let03, let04,let05, let06, let07, let08, let09, let10
85         global let11, let12, let13, let14,let15, let16, let17, let18, let19, let20
86         global let21, let22, let23, let24
87
88         global let01selectkey,let02selectkey,let03selectkey,let04selectkey,let05selectkey
89         global let06selectkey,let07selectkey,let08selectkey,let09selectkey,let10selectkey,let11selectkey
90         global let12selectkey,let13selectkey,let14selectkey,let15selectkey,let16selectkey,let17selectkey
91         global let18selectkey,let19selectkey,let20selectkey,let21selectkey,let22selectkey,let23selectkey
92         global let24selectkey
93
94         glClearColor(0.4,0.5,0.6 ,0.0)
95         glClear(GL_COLOR_BUFFER_BIT)
96
97         glColor3d(1,1,1)
98         glRasterPos2i(87, 375)
99         Text("Blendersynchro V 2.0")
100         glColor3d(1,1,1)
101         glRasterPos2i(84, 360)
102         Text("Programming: Dienben")
103
104         glColor3d(0,0,0)
105         glRasterPos2i(13, 342)
106         Text("Lip Synchronization Tool")
107         glColor3d(0,0,0)
108         glRasterPos2i(13, 326)
109         Text("Thanks to Chris Clawson and Liubomir Kovatchev")
110
111         glColor3d(1,1,1)
112         glRasterPos2i(5, 320)
113         Text("_______________________________________________________")
114         glColor3d(0,0,0)
115         glRasterPos2i(6, 318)
116         Text("_______________________________________________________")
117
118
119         if (etape==1):
120                 #cette etape permet de choisi la correspondance entre les phonemes et les cles
121                 #this stage offer the possibility to choose the mapping between phonems and shapes
122
123                 glColor3d(1,1,1)
124                 glRasterPos2i(140, 300)
125                 Text("Objet: "+Blender.Object.GetSelected()[0].getName() )
126
127                 glColor3d(1,1,1)
128                 glRasterPos2i(5, 215)
129                 Text("Assign phonems to shapes:")
130
131                 #on mesure la taille de la liste de phonemes
132                 #this is the lenght of the phonem list
133                 nbr_phoneme=len(liste_phoneme)
134
135                 #on dessine les listes de choix
136                 #we draw the choice list
137
138                 #
139                 if (nbr_phoneme > 0):
140                         let01 = String(" ", 4, 5, 185, 30, 16, liste_phoneme[0], 3)
141                         glColor3d(0,0,0)
142                         glRasterPos2i(40, 188)
143                         Text("=")
144                         let01selectkey = Menu(key_menu, 50, 50, 185, 70, 16, let01selectkey.val)
145
146         #
147                 if (nbr_phoneme > 1):
148                         let02 = String(" ", 4, 150, 185, 30, 16, liste_phoneme[1], 2)
149                         glColor3d(0,0,0)
150                         glRasterPos2i(185, 188)
151                         Text("=")
152                         let02selectkey = Menu(key_menu, 51, 195, 185, 70, 16, let02selectkey.val)
153
154         #
155                 if (nbr_phoneme > 2):
156                         let03 = String(" ", 4, 5, 165, 30, 16, liste_phoneme[2], 2)
157                         glColor3d(0,0,0)
158                         glRasterPos2i(40, 168)
159                         Text("=")
160                         let03selectkey = Menu(key_menu, 52, 50, 165, 70, 16, let03selectkey.val)
161
162         #
163                 if (nbr_phoneme > 3):
164                         let04 = String(" ", 4, 150, 165, 30, 16, liste_phoneme[3], 2)
165                         glColor3d(0,0,0)
166                         glRasterPos2i(185, 168)
167                         Text("=")
168                         let04selectkey = Menu(key_menu, 53, 195, 165, 70, 16, let04selectkey.val)
169
170         #
171                 if (nbr_phoneme > 4):
172                         let05 = String(" ", 4, 5, 145, 30, 16, liste_phoneme[4], 2)
173                         glColor3d(0,0,0)
174                         glRasterPos2i(40, 148)
175                         Text("=")
176                         let05selectkey = Menu(key_menu, 54, 50, 145, 70, 16, let05selectkey.val)
177
178                 #
179                 if (nbr_phoneme > 5):
180                         let06 = String(" ", 4, 150, 145, 30, 16, liste_phoneme[5], 2)
181                         glColor3d(0,0,0)
182                         glRasterPos2i(185, 148)
183                         Text("=")
184                         let06selectkey = Menu(key_menu, 55, 195, 145, 70, 16, let06selectkey.val)
185
186         #
187                 if (nbr_phoneme > 6):
188                         let07 = String(" ", 4, 5, 125, 30, 16, liste_phoneme[6], 2)
189                         glColor3d(0,0,0)
190                         glRasterPos2i(40, 128)
191                         Text("=")
192                         let07selectkey = Menu(key_menu, 56, 50, 125, 70, 16, let07selectkey.val)
193
194                 #
195                 if (nbr_phoneme > 7):
196                         let08 = String(" ", 4, 150, 125, 30, 16, liste_phoneme[7], 2)
197                         glColor3d(0,0,0)
198                         glRasterPos2i(185, 128)
199                         Text("=")
200                         let08selectkey = Menu(key_menu, 57, 195, 125, 70, 16,let08selectkey.val)
201
202                 #
203                 if (nbr_phoneme > 8):
204                         let09 = String(" ", 4, 5, 105, 30, 16, liste_phoneme[8], 2)
205                         glColor3d(0,0,0)
206                         glRasterPos2i(40, 108)
207                         Text("=")
208                         let09selectkey = Menu(key_menu, 58, 50, 105, 70, 16,let09selectkey.val)
209
210                 #
211                 if (nbr_phoneme > 9):
212                         let10 = String(" ", 4, 150, 105, 30, 16, liste_phoneme[9], 2)
213                         glColor3d(0,0,0)
214                         glRasterPos2i(185, 108)
215                         Text("=")
216                         let10selectkey = Menu(key_menu, 59, 195, 105, 70, 16, let10selectkey.val)
217
218                 #
219                 if (nbr_phoneme > 10):
220                         let11 = String(" ", 4, 5, 85, 30, 16, liste_phoneme[10], 2)
221                         glColor3d(0,0,0)
222                         glRasterPos2i(40, 88)
223                         Text("=")
224                         let11selectkey = Menu(key_menu, 60, 50, 85, 70, 16, let11selectkey.val)
225
226                 #
227                 if (nbr_phoneme > 11):
228                         let12 = String(" ", 4, 150, 85, 30, 16, liste_phoneme[11], 2)
229                         glColor3d(0,0,0)
230                         Text("=")
231                         let12selectkey = Menu(key_menu, 61, 195, 85, 70, 16, let12selectkey.val)
232
233                 #
234                 if (nbr_phoneme > 12):
235                         let13 = String(" ", 4, 5, 65, 30, 16, liste_phoneme[12], 2)
236                         glColor3d(0,0,0)
237                         glRasterPos2i(40, 68)
238                         Text("=")
239                         let13selectkey = Menu(key_menu, 62, 50, 65, 70, 16, let13selectkey.val)
240
241                 #
242                 if (nbr_phoneme > 13):
243                         let14 = String(" ", 4, 150, 65, 30, 16, liste_phoneme[13], 2)
244                         glColor3d(0,0,0)
245                         glRasterPos2i(185, 68)
246                         Text("=")
247                         let14selectkey = Menu(key_menu, 63, 195, 65, 70, 16, let14selectkey.val)
248
249                 #
250                 if (nbr_phoneme > 14):
251                         let15 = String(" ", 4, 5, 45, 30, 16, liste_phoneme[14], 2)
252                         glColor3d(0,0,0)
253                         glRasterPos2i(40, 48)
254                         Text("=")
255                         let15selectkey = Menu(key_menu, 64, 50, 45, 70, 16, let15selectkey.val)
256
257                 #
258                 if (nbr_phoneme > 15):
259                         let16 = String(" ", 4, 150, 45, 30, 16, liste_phoneme[15], 2)
260                         glColor3d(0,0,0)                                                        
261                         glRasterPos2i(185, 48)
262                         Text("=")
263                         let16selectkey = Menu(key_menu, 65, 195, 45, 70, 16, let16selectkey.val)
264
265                 #
266                 if (nbr_phoneme > 16):
267                         let17 = String(" ", 4, 295, 185, 30, 16, liste_phoneme[16], 2)
268                         glColor3d(0,0,0)
269                         glRasterPos2i(330, 188)
270                         Text("=")
271                         let17selectkey = Menu(key_menu, 66, 340, 185, 70, 16, let17selectkey.val)
272
273                 #
274                 if (nbr_phoneme > 17):
275                         let18 = String(" ", 4, 440, 185, 70, 16, liste_phoneme[17], 8)
276                         glColor3d(0,0,0)
277                         glRasterPos2i(515, 188)
278                         Text("=")
279                         let18selectkey = Menu(key_menu, 67, 525, 185, 70, 16, let18selectkey.val)
280
281                 #
282                 if (nbr_phoneme > 18):
283                         let19 = String(" ", 4, 295, 165, 30, 16, liste_phoneme[18], 2)
284                         glColor3d(0,0,0)
285                         glRasterPos2i(330, 168)
286                         Text("=")
287                         let19selectkey = Menu(key_menu, 68, 340, 165, 70, 16, let19selectkey.val)
288
289                 #
290                 if (nbr_phoneme > 19):
291                         let20 = String(" ", 4, 440, 165, 70, 16, liste_phoneme[19], 8)
292                         glColor3d(0,0,0)
293                         glRasterPos2i(515, 168)
294                         Text("=")
295                         let20selectkey = Menu(key_menu, 69, 525, 165, 70, 16, let20selectkey.val)
296
297                 #
298                 if (nbr_phoneme > 20):
299                         let21 = String(" ", 4, 295, 145, 30, 16, liste_phoneme[20], 2)
300                         glColor3d(0,0,0)
301                         glRasterPos2i(330, 148)
302                         Text("=")
303                         let21selectkey = Menu(key_menu, 70, 340, 145, 70, 16, let21selectkey.val)
304
305                 #
306                 if (nbr_phoneme > 21):
307                         let22 = String(" ", 4, 440, 145, 70, 16, liste_phoneme[21], 8)
308                         glColor3d(0,0,0)                                                        
309                         glRasterPos2i(515, 148)
310                         Text("=")
311                         let22selectkey = Menu(key_menu, 71, 525, 145, 70, 16, let22selectkey.val)
312
313                 #
314                 if (nbr_phoneme > 22):
315                         let23 = String(" ", 4, 295, 125, 30, 16, liste_phoneme[22], 2)
316                         glColor3d(0,0,0)
317                         glRasterPos2i(330, 128)
318                         Text("=")
319                         let23selectkey = Menu(key_menu, 72, 340, 125, 70, 16,let23selectkey.val)
320
321                 #
322                 if (nbr_phoneme > 23):
323                         let24 = String(" ", 4, 440, 125, 70, 16, liste_phoneme[23], 8)
324                         glColor3d(0,0,0)
325                         glRasterPos2i(515, 128)
326                         Text("=")
327                         let24selectkey = Menu(key_menu, 73, 525, 125, 70, 16, let24selectkey.val)
328
329                 #
330                 if (nbr_phoneme > 24):
331                         let25 = String(" ", 4, 295, 105, 30, 16, liste_phoneme[24], 2)
332                         glColor3d(0,0,0)
333                         glRasterPos2i(330, 108)
334                         Text("=")
335                         let25selectkey = Menu(key_menu, 74, 340, 105, 70, 16, let25selectkey.val)
336
337                 #
338                 if (nbr_phoneme > 25):
339                         let26 = String(" ", 4, 440, 105, 70, 16, liste_phoneme[25], 8)
340                         glColor3d(0,0,0)
341                         glRasterPos2i(515, 108)
342                         Text("=")
343                         let26selectkey = Menu(key_menu, 75, 525, 105, 70, 16,let26selectkey.val)
344
345                 #
346                 if (nbr_phoneme > 26):
347                         let27 = String(" ", 4, 295, 85, 30, 16, liste_phoneme[26], 2)
348                         glColor3d(0,0,0)
349                         glRasterPos2i(330, 88)
350                         Text("=")
351                         let27selectkey = Menu(key_menu, 76, 340, 85, 70, 16, let27selectkey.val)
352
353                 #
354                 if (nbr_phoneme > 27):
355                         let28 = String(" ", 4, 440, 85, 70, 16, liste_phoneme[27], 8)
356                         glColor3d(0,0,0)
357                         glRasterPos2i(515, 88)
358                         Text("=")
359                         let28selectkey = Menu(key_menu, 77, 525, 85, 70, 16,let28selectkey.val)
360
361                 #
362                 if (nbr_phoneme > 28):
363                         let29 = String(" ", 4, 295, 65, 30, 16, liste_phoneme[28], 2)
364                         glColor3d(0,0,0)
365                         glRasterPos2i(330, 68)
366                         Text("=")
367                         let29selectkey = Menu(key_menu, 78, 340, 65, 70, 16, let29selectkey.val)
368
369                 #
370                 if (nbr_phoneme > 29):
371                         let30 = String(" ", 4, 440, 65, 70, 16, liste_phoneme[29], 8)
372                         glColor3d(0,0,0)
373                         glRasterPos2i(515, 68)
374                         Text("=")
375                         let30selectkey = Menu(key_menu, 79, 525, 65, 70, 16, let30selectkey.val)
376
377                 #
378                 if (nbr_phoneme > 30):
379                         let31 = String(" ", 4, 295, 45, 30, 16, liste_phoneme[30], 2)
380                         glColor3d(0,0,0)
381                         glRasterPos2i(330, 48)
382                         Text("=")
383                         let31selectkey = Menu(key_menu, 80, 340, 45, 70, 16, let31selectkey.val)
384
385                 #
386                 if (nbr_phoneme > 31):
387                         let32 = String(" ", 4, 440, 45, 70, 16, liste_phoneme[31], 8)
388                         glColor3d(0,0,0)
389                         glRasterPos2i(515, 48)
390                         Text("=")
391                         let32selectkey = Menu(key_menu, 81, 525, 45, 70, 16, let32selectkey.val)
392
393                 Button("Go", 3, 155, 5, 145, 22)
394         
395         if (etape==2):
396                 glColor3d(1,1,1)
397                 glRasterPos2i(125, 200)
398                 Text("Operation Completed")
399
400         if (etape==0):
401                 glColor3d(1,1,1)
402                 glRasterPos2i(125, 200)
403                 Text("Please select a Mesh'Object and Create all the IPO Curves for your Shapes")
404
405         if (etape==3):
406                 #this stage permits to load a custom dictionnary
407                 load_file_text = "Load File"
408                 if mon_fichier_dico:
409                         Button("Import Loaded File", 2, 5, 5, 145, 22)
410                         glColor3d(1,1,1)
411                         glRasterPos2i(6, 50)
412                         Text("loaded file: %s" % basename(mon_fichier_dico))
413                         load_file_text = "Choose Another File"
414                 Button(load_file_text, 8, 125, 180, 145, 22)
415
416         glRasterPos2i(6, 40)
417         Text("_______________________________________________________")
418         glColor3d(0,0,0)
419         glRasterPos2i(6, 38)
420         Text("_______________________________________________________")
421         
422         Button("Exit", 1, 305, 5, 80, 22)
423
424
425
426 #cette fonction sur evenement quite en cas d'ESC
427 #this functions catch the ESC event and quit
428 def event(evt,val):
429         if (evt == ESCKEY and not val): Exit()
430
431 #cette fonction gere les evenements
432 #the event functions
433 def bevent(evt):
434         global etape,soft_type,liste_phoneme,dico_phoneme_export
435
436         if (evt == 1):
437                 Exit()
438         
439         elif (evt == 2):
440                 #c'est l'import du dictionnaire
441                 #we create and import the dictionnary
442                 lecture_chaine(mon_fichier_dico,dico_phoneme_export)
443                 construction_dictionnaire_phoneme()
444                 #we change the stage
445                 etape=1
446         
447         elif (evt == 3):
448                 #c'est l'import
449                 #we import 
450                 lecture_chaine(mon_fichier_export,dico_phoneme_export)
451                 construction_dico_correspondance()
452                 construction_lipsynchro()
453                 #on change d'etape
454                 #we change the stage
455                 etape=2
456                 
457         elif (evt == 8):
458                 #we choose the file
459                 Blender.Window.FileSelector(selectionner_fichier,"Select File")
460                 
461         Blender.Redraw()
462
463 #cette fonction recupere le nom et le chemin du fichier dictionnaire
464 #we catch the name and the path of the dictionnary
465 def selectionner_fichier(filename):
466         global mon_fichier_dico,mon_fichier_export
467         mon_fichier_dico=filename
468         mon_fichier_export=filename
469
470 #fonction de lecture de la liste frame phoneme
471 #we read the frame and phonems
472 def lecture_chaine(fichier,liste):
473         mon_fichier=open(fichier)
474         #je lis la premiere ligne qui contiens la version de moho
475         #first, we read the moho version
476         mon_fichier.readline()
477
478         #je lis jusqu'a la fin
479         #then we read until the end of the file
480         while 1:
481                 ma_ligne=mon_fichier.readline()
482                 if ma_ligne=='':
483                         break
484                 decoup=ma_ligne.split()
485                 liste[decoup[0]]=decoup[1]
486         print liste
487
488
489
490
491 #fonction qui construit la liste dictionnaire simple
492 #we make the dictionnary
493 def construction_dictionnaire_phoneme():
494         global liste_phoneme
495         index_liste=0
496         #je transforme mon dictionnaire en list de tulpes
497         #we transform the list in tulpes
498         ma_liste=dico_phoneme_export.items()
499         #je parcours ma liste a la recherche d'elements non existant
500         #we read the list to find non existing elements
501         print dico_phoneme
502         for index in range(len(ma_liste)):
503                 if ma_liste[index][1] not in liste_phoneme:
504                         liste_phoneme[index_liste:index_liste]=[ma_liste[index][1]]
505                         index_liste=index_liste+1
506         print liste_phoneme
507
508
509 #cette fonction recupere les courbes cible 
510 #this functon catch the IPO curve
511 def recuperation_courbe():
512         global key_menu,dico_key
513
514         #on recupere le nom des shapes
515         #we catch the shapes
516         key=Blender.Object.GetSelected()[0].getData().getKey().getBlocks()
517         for n in range(len(key)):
518                 #on vire la première cle (en effet basic n'est pas une cle en tant que telle)
519                 #we threw away the basic shapes
520                 if (n>0):
521                         key_menu=key_menu+key[n].name + " %x" + str(n-1) + "|"
522                         dico_key[str(n-1)]=Blender.Object.GetSelected()[0].getData().getKey().getIpo().getCurves()[n-1]
523         
524         
525         print "dico_key"
526         print dico_key
527         print 'end dico_key'
528
529 #cette fonction construit un dictionnaire de correspondance entre les phonemes prononces et les cles a utiliser
530 #we make the dictionnary for the mapping between shapes and phonems
531 def construction_dico_correspondance():
532         global dico_correspondance
533         #je parcours les phonemes
534         #we read the phonems
535         if (nbr_phoneme>0):
536                 dico_correspondance[liste_phoneme[0]]=dico_key[str(let01selectkey.val)]
537         if (nbr_phoneme>1):
538                 dico_correspondance[liste_phoneme[1]]=dico_key[str(let02selectkey.val)]
539         if (nbr_phoneme>2):
540                 dico_correspondance[liste_phoneme[2]]=dico_key[str(let03selectkey.val)]
541         if (nbr_phoneme>3):
542                 dico_correspondance[liste_phoneme[3]]=dico_key[str(let04selectkey.val)]
543         if (nbr_phoneme>4):
544                 dico_correspondance[liste_phoneme[4]]=dico_key[str(let05selectkey.val)]
545         if (nbr_phoneme>5):
546                 dico_correspondance[liste_phoneme[5]]=dico_key[str(let06selectkey.val)]
547         if (nbr_phoneme>6):
548                 dico_correspondance[liste_phoneme[6]]=dico_key[str(let07selectkey.val)]
549         if (nbr_phoneme>7):
550                 dico_correspondance[liste_phoneme[7]]=dico_key[str(let08selectkey.val)]
551         if (nbr_phoneme>8):
552                 dico_correspondance[liste_phoneme[8]]=dico_key[str(let09selectkey.val)]
553         if (nbr_phoneme>9):
554                 dico_correspondance[liste_phoneme[9]]=dico_key[str(let10selectkey.val)]
555         if (nbr_phoneme>10):
556                 dico_correspondance[liste_phoneme[10]]=dico_key[str(let11selectkey.val)]
557         if (nbr_phoneme>11):
558                 dico_correspondance[liste_phoneme[11]]=dico_key[str(let12selectkey.val)]
559         if (nbr_phoneme>12):
560                 dico_correspondance[liste_phoneme[12]]=dico_key[str(let13selectkey.val)]
561         if (nbr_phoneme>13):
562                 dico_correspondance[liste_phoneme[13]]=dico_key[str(let14selectkey.val)]
563         if (nbr_phoneme>14):
564                 dico_correspondance[liste_phoneme[14]]=dico_key[str(let15selectkey.val)]
565         if (nbr_phoneme>15):
566                 dico_correspondance[liste_phoneme[15]]=dico_key[str(let16selectkey.val)]
567         if (nbr_phoneme>16):
568                 dico_correspondance[liste_phoneme[16]]=dico_key[str(let17selectkey.val)]
569         if (nbr_phoneme>17):
570                 dico_correspondance[liste_phoneme[17]]=dico_key[str(let18selectkey.val)]
571         if (nbr_phoneme>18):
572                 dico_correspondance[liste_phoneme[18]]=dico_key[str(let19selectkey.val)]
573         if (nbr_phoneme>19):
574                 dico_correspondance[liste_phoneme[19]]=dico_key[str(let20selectkey.val)]
575         if (nbr_phoneme>20):
576                 dico_correspondance[liste_phoneme[20]]=dico_key[str(let21selectkey.val)]
577         if (nbr_phoneme>21):
578                 dico_correspondance[liste_phoneme[21]]=dico_key[str(let22selectkey.val)]
579         if (nbr_phoneme>22):
580                 dico_correspondance[liste_phoneme[22]]=dico_key[str(let23selectkey.val)]
581         if (nbr_phoneme>23):
582                 dico_correspondance[liste_phoneme[23]]=dico_key[str(let24selectkey.val)]
583         if (nbr_phoneme>24):
584                 dico_correspondance[liste_phoneme[24]]=dico_key[str(let25selectkey.val)]
585         if (nbr_phoneme>25):
586                 dico_correspondance[liste_phoneme[25]]=dico_key[str(let26selectkey.val)]
587         if (nbr_phoneme>26):
588                 dico_correspondance[liste_phoneme[26]]=dico_key[str(let27selectkey.val)]
589         if (nbr_phoneme>27):
590                 dico_correspondance[liste_phoneme[27]]=dico_key[str(let28selectkey.val)]
591         if (nbr_phoneme>28):
592                 dico_correspondance[liste_phoneme[28]]=dico_key[str(let29selectkey.val)]
593         if (nbr_phoneme>29):
594                 dico_correspondance[liste_phoneme[29]]=dico_key[str(let30selectkey.val)]
595         if (nbr_phoneme>30):
596                 dico_correspondance[liste_phoneme[30]]=dico_key[str(let31selectkey.val)]
597         if (nbr_phoneme>31):
598                 dico_correspondance[liste_phoneme[31]]=dico_key[str(let32selectkey.val)]
599
600         print dico_correspondance
601
602
603 #cette fonction ajoute un points a la cle donnee a la frame donnee
604 #we add a point to the IPO curve Target
605 def ajoute_point(cle,frame,valeur):
606         cle.setInterpolation('Linear')
607         cle.append((frame,valeur))
608         cle.Recalc()
609
610 #cette fonction parcours le dictionnaire des frame à ajouter et construit les points
611 #we add all the point to the IPO Curve
612 def construction_lipsynchro():
613         print "je construit"
614         doublet_old=""
615         #construction de la liste des frame
616         cpt=0
617         liste_frame=[]
618         for frame in dico_phoneme_export:
619                 liste_frame.append(int(frame))
620                 cpt=cpt+1
621         liste_frame.sort()
622         print "listeframe"
623         print liste_frame
624         print "fini"
625
626         for doublet in liste_frame:
627                 ajoute_point(dico_correspondance[dico_phoneme_export[str(doublet)]],doublet,1)
628                 if (doublet_old==""):
629                         ajoute_point(dico_correspondance[dico_phoneme_export[str(doublet)]],(doublet-2),0)
630                 if (doublet_old!=''):
631                         if (dico_correspondance[dico_phoneme_export[str(doublet)]]!=dico_correspondance[dico_phoneme_export[doublet_old]]):
632                                 print "doublet:"+str(doublet)
633                                 print "doublet old:"+doublet_old
634                                 ajoute_point(dico_correspondance[dico_phoneme_export[doublet_old]],(int(doublet_old)+2),0)
635                                 ajoute_point(dico_correspondance[dico_phoneme_export[str(doublet)]],(doublet-2),0)
636                 doublet_old=str(doublet)
637
638
639 #end of my functions we begin the execution       
640 #je commence l execution-----------------------------------------------------------------------------------------------
641 #voici mes variables
642
643 #declaration et instanciation
644 #decleration and instanciation
645
646
647 #voici mon objet de travail
648 objet_travail=Create(0)
649
650 #my soft type
651 soft_type=1
652
653 #voici la liste des phoneme effectivement utilise
654 #the phonems'list
655 #liste_phoneme_papagayo=['AI','E','O','U','FV','L','WQ','MBP','etc','rest']
656 #liste_phoneme_jlipsinch=['A','B','C','Closed','D','E','F','G','I','K','L','M','N','O','P','Q','R','S','SH','T','TH','U','V','W']
657
658 liste_phoneme=[]
659 #voici mon dictionnaire des frames o
660 dico_phoneme_export = Create(0)
661 dico_phoneme_export={}
662 dico_phoneme={}
663
664
665 #voici mes cle
666 key_menu=""
667 dico_key={}
668
669 #voici mes ipo
670 dico_bloc={}
671 iponame = Create(0)
672
673 #voici mon dictionnaire de correspondance
674 dico_correspondance={}
675
676 try:
677         #on verifie est bien une mesh et qu'il a des courbes
678         if ((Blender.Object.GetSelected()[0].getType()=='Mesh')):
679                 #on verifie que l'objet a bien toute ses Courbes
680                 if (len(Blender.Object.GetSelected()[0].getData().getKey().getBlocks())-1==Blender.Object.GetSelected()[0].getData().getKey().getIpo().getNcurves()):
681                         etape=3
682                         #on lance la creation du dictionnaire
683                         recuperation_courbe()
684                 else:
685                         print "not the good number of IPO Curve"
686                         etape = 0
687         else:
688                 print "error: bad object Type:"
689                 print Blender.Object.GetSelected()[0].getType()
690                 etape = 0
691 except:
692         print 'error: exception'
693         etape = 0
694
695
696 #voici le fichier dictionnaire
697 mon_fichier_dico=""
698
699 #voici le fichier export pamela
700 mon_fichier_export=""
701
702
703 let01selectkey = Create(0)
704 let02selectkey = Create(0)
705 let03selectkey = Create(0)
706 let04selectkey = Create(0)
707 let05selectkey = Create(0)
708 let06selectkey = Create(0)
709 let07selectkey = Create(0)
710 let08selectkey = Create(0)
711 let09selectkey = Create(0)
712 let10selectkey = Create(0)
713 let11selectkey = Create(0)
714 let12selectkey = Create(0)
715 let13selectkey = Create(0)
716 let14selectkey = Create(0)
717 let15selectkey = Create(0)
718 let16selectkey = Create(0)
719 let17selectkey = Create(0)
720 let18selectkey = Create(0)
721 let19selectkey = Create(0)
722 let20selectkey = Create(0)
723 let21selectkey = Create(0)
724 let22selectkey = Create(0)
725 let23selectkey = Create(0)
726 let24selectkey = Create(0)
727
728
729 Register (trace,event,bevent)