Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/commun.py
blob: 8109b345c9865802cd2b13856ef4ae56b3ffa167 (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#------------------------------------------------------------------------------

# Copyright 2008-2009 : François Sénéquier
# Email : francois.senequier@netcourrier.com

# This file is part of 'Theorie'.
#
# 'Theorie' 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 3 of the License, or
# any later version.
#
# 'Theorie' 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 'Theorie'.  If not, see <http://www.gnu.org/licenses/>.

#------------------------------------------------------------------------------

import time

import pygtk
import gtk
import pango

import modele
from gettext import gettext as _

#------------------------------------------------------------------------------

import logging
import logging.handlers

#LOG_FILENAME = "./theorìe.logs.txt"
#logger = logging.getLogger('MyLogger')
#logger.setLevel(logging.DEBUG)
#handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=50000, backupCount=5)
#logger.addHandler(handler)

#------------------------------------------------------------------------------

TXT_FNT_REF = "Arial 12 Bold"

#------------------------------------------------------------------------------

TXT_TIT_APP = _("Musical theory - Musical instruments")

TXT_CMP_MOD = _("Comparison mode")
TXT_CMP_QUI = _("Compared to")

# TRANS: A scale is any sequence of musical notes in an ascending or descending
# order -- http://en.wikipedia.org/wiki/Scale_(music)
TXT_CMP_GAM = _("scales")

# TRANS: A chord in music is any harmonic set of two or more notes that is
# heard as if sounding simultaneously. 
# -- http://en.wikipedia.org/wiki/Chord_(music)
TXT_CMP_ACC = _("chords")
TXT_CMP_INF = _("contained")
TXT_CMP_EGA = _("equal")
TXT_CMP_SUP = _("contains")

# TRANS: A scale is any sequence of musical notes in an ascending or descending
# order -- http://en.wikipedia.org/wiki/Scale_(music)
TXT_GAM = _("Scale")

# TRANS: A chord in music is any harmonic set of two or more notes that is
# heard as if sounding simultaneously. 
# -- http://en.wikipedia.org/wiki/Chord_(music)
TXT_ACC = _("Chord")

# TRANS: In music theory, the key of a piece usually refers to the tonic note
# and chord, which gives a subjective sense of arrival and rest.
# -- http://en.wikipedia.org/wiki/Key_(music)
TXT_TON = _("Key")

# TRANS: In music theory, the root of a chord (in French, basse fondamentale)
# is the note or pitch upon which a chord may be built by stacking thirds. 
# -- http://en.wikipedia.org/wiki/Root_(music)
TXT_FND = _("Root")

# TRANS: Mode generally refers to a type of scale, coupled with a set of
# characteristic melodic behaviours.
# -- http://en.wikipedia.org/wiki/Mode_(music)
TXT_MOD = _("Mode")

# TRANS: In music theory, the word inversion has several meanings. There are
# inverted chords, inverted melodies, inverted intervals, and (in counterpoint)
# inverted voices. -- http://en.wikipedia.org/wiki/Inversion_(music)
TXT_REN = _("Inversion")

# TRANS: In music, parallel keys are the major and minor scales that have the
# same tonic. A major and minor scale sharing the same tonic are said to be in
# a parallel relationship. -- http://en.wikipedia.org/wiki/Parallel_(music)
TXT_REL = _("Parallel")
TXT_NOT = _("Tones")

# TRANS: In music theory, an interval is a combination of two notes, or the
# ratio between their frequencies.
# -- http://en.wikipedia.org/wiki/Intervals_(music)
TXT_INT = _("Intervals")

# TRANS: In music, tonality is the principle of organizing musical
# compositions around a central note, the tonic.
# -- http://www.britannica.com/EBchecked/topic/599046/tonality
TXT_TYP_TON = _("Tonality")
TXT_TYP_INS = _("Instrument")
TXT_TYP_GUI = _("Tuning")
TXT_TYP_NBC = _("Cases")

# TRANS: In music, fingering is the choice of which fingers and hand positions
# to use when playing certain musical instruments.
# -- http://en.wikipedia.org/wiki/Fingering_(music)
TXT_TYP_DGT = _("Fingering")

# TRANS: In music, tension is the perceived need for relaxation or release
# created by a listener's expectations.
# -- http://en.wikipedia.org/wiki/Tension_(music)
TXT_TIT_TEN = _("Tension")

TXT_TIT_CMP = _("To compare")
TXT_TIT_NOT = _("Tone")
TXT_TIT_DEG = _("Degrees")

TXT_LIS_NOT = _("Tones list")
TXT_ENS_NOT = _("Tones set")

TXT_ONG_THE = _("Theory")
TXT_ONG_INS = _("Instruments")

TXT_ONG_QUA = _("Quadrant")
TXT_ONG_CMP = _("Comparisons")
TXT_ONG_REC = _("Ear training")
TXT_ONG_ECO = _("Playing")

TXT_ONG_PIA = _("Piano")
TXT_ONG_HAR = _("Harmonica")
TXT_ONG_FLU = _("Recorder")
TXT_ONG_GUI = _("Guitar")
TXT_ONG_CLA = _("Clarinet")

# TRANS: A scale is any sequence of musical notes in an ascending or descending
# order -- http://en.wikipedia.org/wiki/Scale_(music)
TXT_ONG_GAM = _("Scales")

# TRANS: A chord in music is any harmonic set of two or more notes that is
# heard as if sounding simultaneously. 
# -- http://en.wikipedia.org/wiki/Chord_(music)
TXT_ONG_ACC = _("Chords")
TXT_ONG_NOT = _("Tones")

# TRANS: In music, an octave or perfect octave is the interval between one
# musical pitch and another with half or double its frequency.
# -- http://en.wikipedia.org/wiki/Octave
TXT_OCT_PRM = _("First octave")

# TRANS: In music, an octave or perfect octave is the interval between one
# musical pitch and another with half or double its frequency.
# -- http://en.wikipedia.org/wiki/Octave
TXT_OCT_NBR = _("Number of octaves")

TXT_DGT_4E6 = _("4 tones, 6 cases")
TXT_DGT_3E5 = _("3 tones, 5 cases")
TXT_DGT_EGG = _("left, left")
TXT_DGT_EGD = _("left, right")


# TRANS: In music, an octave or perfect octave is the interval between one
# musical pitch and another with half or double its frequency.
# -- http://en.wikipedia.org/wiki/Octave
TXT_DEG_OCT = _("Octave")

# TRANS: In music, Unison may refer to two notes sounding the same pitch,
# often but not always at the same time.
# -- http://en.wikipedia.org/wiki/Unison
TXT_DEG_UNI = _("Unison")

TXT_ABR_OCT = _("Oct.")
TXT_CHX_NOM = _("the names")
TXT_CHX_EDT = _("in half tones")

TXT_HAR_SOU = _("Blo")
TXT_HAR_ASP = _("Asp")

TXT_REC_LIS = _("Listen")
TXT_REC_INT = _("Intervals recognition")

# TRANS: In music, the term note has two primary meanings, A sign used in
# musical notation to represent the relative duration and pitch of a sound or
# A pitched sound itself.
# -- http://en.wikipedia.org/wiki/Note
TXT_REC_NOT = _("Notes recognition")

# TRANS: In music theory, an interval is a combination of two notes, or the
# ratio between their frequencies.
# -- http://en.wikipedia.org/wiki/Intervals_(music)
TXT_REC_LII = _("Listen to this interval and try to identify it")
TXT_REC_LNI = _("Listen to this note and try to identify it")

TXT_REC_SUC = _("Try number %d : good, this is a %s indeed !")
TXT_REC_ERR = _("Try number %d : error, this is not a %s !")

#------------------------------------------------------------------------------

ESPACE = 4

def definirButton(txt):
	obj = gtk.Button(txt)
	obj.show()
	return obj

def definirArrow(sens):
	obj = gtk.Arrow(sens, gtk.SHADOW_ETCHED_IN)
	return obj

def definirToggleButton(txt):
	obj = gtk.ToggleButton(txt)
	obj.show()
	return obj

def definirCheckButton(txt):
	obj = gtk.CheckButton(txt, True)
	obj.show()
	return obj

def definirCombo(lis):
	obj = gtk.combo_box_new_text()
	for elt in lis:
		obj.append_text(elt)
	obj.set_active(0)
	obj.show()
	return obj
	
def definirLabel(nom):
	obj = gtk.Label(nom)
	obj.show()
	return obj

def definirVSeparator():
	obj = gtk.VSeparator()
	obj.show()
	return obj

def definirHSeparator():
	obj = gtk.HSeparator()
	obj.show()
	return obj

def definirLabelCombo(nom, lis):
	label = definirLabel(nom + " ")
	combo = definirCombo(lis)
	return label, combo

def definirROW(lab, rnd, typ, pos):
	tvc = gtk.TreeViewColumn(lab)
	tvc.pack_start(rnd, True)
	tvc.add_attribute(rnd, typ, pos)
	return tvc

def definirFrame(tit, elt):
	obj = gtk.Frame(tit)
	if elt != None:
		obj.add(elt)
	obj.set_border_width(ESPACE)
	obj.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
	obj.set_label_align(0.0,0.5)
	obj.show()
	return obj

def definirScrolledWindow(elt, viewport = None, xpa = gtk.POLICY_AUTOMATIC, ypa = gtk.POLICY_AUTOMATIC):
	obj = gtk.ScrolledWindow()
	if viewport == None:
		obj.add(elt)
	else:
		obj.add_with_viewport(elt)
	obj.set_policy(xpa, ypa)
	obj.show()
	return obj

def definirNotebook(posTIT, lisNOM, lisOBJ, pagSEL):
	pcd = pango.FontDescription(TXT_FNT_REF)
	obj = gtk.Notebook()
	obj.set_scrollable(True)
	obj.set_show_tabs(True)
	obj.set_show_border(True)
	obj.set_tab_pos(posTIT)
	for ind in range(len(lisNOM)):
		nom = lisNOM[ind]
		val = lisOBJ[ind]
		lab = gtk.Label(nom)
		lab.modify_font(pcd)
		obj.append_page(val, lab)
	obj.set_current_page(pagSEL)
	obj.show()
	return obj

def definirHBOX(lis, expand = True, fill = True):
	obj = gtk.HBox(False, ESPACE)
	for elt in lis:
		obj.pack_start(elt, expand, fill, ESPACE)
	obj.show()
	return obj

def definirVBOX(lis, expand = True, fill = True):
	obj = gtk.VBox(False, ESPACE)
	for elt in lis:
		obj.pack_start(elt, expand, fill, ESPACE)
	obj.show()
	return obj

def definirHPANED(haut, bas):
	obj = gtk.HPaned()
	obj.add1(haut)
	obj.add2(bas)
	obj.show()
	return obj

def definirVPANED(haut, bas):
	obj = gtk.VPaned()
	obj.add1(haut)
	obj.add2(bas)
	obj.show()
	return obj

def definirTOOLBAR(lis):
	tlb = gtk.Toolbar()
	tlb.set_show_arrow(True)
	tlb.set_orientation(gtk.ORIENTATION_HORIZONTAL)
	tlb.set_border_width(ESPACE)
	for elt in lis:
		if elt != "":
			tlb.append_widget(elt, "", "private")
		else:
			tlb.append_space()
	tlb.show()
	return tlb

#------------------------------------------------------------------------------

def disconnectEVENT(widget, handle):
	try:
		widget.disconnect(handle)
	except:
		pass

#------------------------------------------------------------------------------

def formater(deb, sep, fin, lis):
	txt = str(deb) + str(lis[0])
	lis = lis[1:]
	for elt in lis:
		txt += str(sep) + str(elt)
	txt += fin
	return txt

def ajouterNotes(ens, vpo, vno):
	ens = modele.Ensemble("", ens.getListe())
	nbr = len(ens)
	if nbr > 0:
		dec = modele.NOMBRE_NOTES_OCTAVE
		for voc in range(vno-1):
			for ind in range(nbr):
				elt = modele.Son(ens.getListe()[ind])
				elt.decaler(dec)
				ens.ajouter(elt)
			dec += modele.NOMBRE_NOTES_OCTAVE
		elt = modele.Son(ens.getListe()[0])
		elt.decaler(dec)
		ens.ajouter(elt)
		ens.decaler(vpo*modele.NOMBRE_NOTES_OCTAVE)
	return ens

#------------------------------------------------------------------------------

def tracer(classe, methode, message=""):
	temps = time.strftime("%H:%M:%S")
	mesg = "%s : %s.%s() : %s" %(temps, classe, methode, message)
	#logger.debug(mesg)
	print mesg