Package jazzparser :: Package harmonical :: Module tstuner
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.harmonical.tstuner

 1  from __future__ import absolute_import 
 2  """Tonal space retuning GUI interface. 
 3   
 4  Super-cool awesome. 
 5   
 6  """ 
 7  """ 
 8  ============================== License ======================================== 
 9   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
10    
11   This file is part of The Jazz Parser. 
12    
13   The Jazz Parser is free software: you can redistribute it and/or modify 
14   it under the terms of the GNU General Public License as published by 
15   the Free Software Foundation, either version 3 of the License, or 
16   (at your option) any later version. 
17    
18   The Jazz Parser is distributed in the hope that it will be useful, 
19   but WITHOUT ANY WARRANTY; without even the implied warranty of 
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
21   GNU General Public License for more details. 
22    
23   You should have received a copy of the GNU General Public License 
24   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
25   
26  ============================ End license ====================================== 
27   
28  """ 
29  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
30   
31  import gtk, sys, gobject 
32   
33  from . import tsgui 
34   
35  OCTAVE_REGION = [ 
36      (-1, -1, 1), 
37      (-1, 0,  1), 
38      (-1, 1,  1), 
39      (0,  -1, 1), 
40      (0,  0,  0), 
41      (0,  1,  0), 
42      (1,  -1, 0), 
43      (1,  0,  0), 
44      (1,  1,  0), 
45      (2,  -1, 0), 
46      (2,  0, -1), 
47      (2,  1, -1), 
48  ] 
49   
50  from jazzparser.utils.tonalspace import coordinate_to_et 
51   
52 -class TonalSpaceRetunerWindow(tsgui.TonalSpaceWindow):
53 - def on_key_press(self, widget, event):
54 keyname = gtk.gdk.keyval_name(event.keyval) 55 control = event.state & gtk.gdk.CONTROL_MASK 56 if keyname == "space": 57 # Retune to the currently selected tonal centre 58 # Display the region we've tuned to as a selection 59 self.clear_selection() 60 # Tune each note in the region around the tonal centre 61 cursor = self.cursor 62 # Centre the grid on this point 63 self.center_grid(*self.cursor) 64 for rel_col,rel_row,__ in OCTAVE_REGION: 65 col = cursor[0]+rel_col 66 row = cursor[1]+rel_row 67 # Work out the native octave of this point 68 note_number = coordinate_to_et((col,row,0)) + 60 69 octave_number = note_number / 12 70 for keyboard_octave in range(0, 11): 71 # Shift the octave to this keyboard octave and retune the note 72 octave_shift = keyboard_octave-octave_number 73 cell = self.get_cell(col, row) 74 cell.retune_note(octave_shift) 75 cell.select() 76 else: 77 super(TonalSpaceRetunerWindow, self).on_key_press(widget, event)
78