forked from morevnaproject-org/papagayo-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMouthView.py
149 lines (129 loc) · 4.36 KB
/
MouthView.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: ISO-8859-1 -*-
# generated by wxGlade 0.3.5.1 on Fri Apr 15 17:02:14 2005
# Papagayo, a lip-sync tool for use with Lost Marble's Moho
# Copyright (C) 2005 Mike Clifton
# Contact information at http://www.lostmarble.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
import wx
import re
from utilities import *
# begin wxGlade: dependencies
# end wxGlade
def ProcessMouthDir(mouthView, dirname, names):
hasImages = False
#wx gives us a string instead of a list of filetypes
full_pattern = re.compile('[^a-zA-Z0-9.\\\/]|_')
supportedimagetypes = re.sub(full_pattern, '', wx.Image.GetImageExtWildcard()).split(".")
for file in names:
file = file.lower()
if file.split(".")[-1] in supportedimagetypes:
hasImages = True
if not hasImages:
return
mouthView.AddMouth(os.path.normpath(dirname), names)
class MouthView(wx.Panel):
def __init__(self, *args, **kwds):
# begin wxGlade: MouthView.__init__
kwds["style"] = wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.__set_properties()
self.__do_layout()
# end wxGlade
# Other initialization
self.doc = None
self.curFrame = 0
self.oldFrame = 0
self.chorusMode = False
self.currentPhoneme = "rest"
self.currentMouth = None
self.mouths = {}
self.LoadMouths()
# Connect event handlers
# window events
wx.EVT_PAINT(self, self.OnPaint)
def __set_properties(self):
# begin wxGlade: MouthView.__set_properties
self.SetMinSize((200, 200))
self.SetBackgroundColour(wx.Colour(255, 255, 255))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MouthView.__do_layout
pass
# end wxGlade
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DrawMe(dc)
def DrawMe(self, dc = None):
if (self.doc is not None) and (self.doc.sound is not None) and (self.doc.sound.IsPlaying()):
if self.doc.currentVoice is not None:
phoneme = self.doc.currentVoice.GetPhonemeAtFrame(self.curFrame)
if self.chorusMode:
for voice in self.doc.voices:
if voice.GetPhonemeAtFrame(self.curFrame) != "rest":
phoneme = voice.GetPhonemeAtFrame(self.curFrame)
else:
phoneme = "rest"
if phoneme == self.currentPhoneme:
return
else:
self.currentPhoneme = phoneme
else:
self.currentPhoneme = "rest"
if dc is None:
dc = wx.ClientDC(self)
freeDC = True
else:
freeDC = False
dc.BeginDrawing()
try:
bitmap = self.mouths[self.currentMouth][self.currentPhoneme]
width, height = self.GetClientSizeTuple()
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
dc.DrawBitmap(bitmap, width / 2 - bitmap.GetWidth() / 2, height / 2 - bitmap.GetHeight() / 2)
except:
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
dc.EndDrawing()
if freeDC:
del dc
def SetFrame(self, frame):
self.oldFrame = self.curFrame
self.curFrame = frame
self.DrawMe()
def SetDocument(self, doc):
self.doc = doc
self.DrawMe()
def ToggleChorus(self, event):
self.chorusMode = ~self.chorusMode
def LoadMouths(self):
os.path.walk(os.path.join(get_main_dir(), "rsrc/mouths"), ProcessMouthDir, self)
def AddMouth(self, dirname, names):
bitmaps = {}
for file in names:
if ".svn" in file:
continue
path = os.path.normpath(os.path.join(dirname, file))
nolog = wx.LogNull()
bitmaps[file.split('.')[0]] = wx.Bitmap(path, wx.BITMAP_TYPE_ANY)
del nolog
self.mouths[os.path.basename(dirname)] = bitmaps
if self.currentMouth is None:
self.currentMouth = os.path.basename(dirname)
# end of class MouthView