[go: up one dir, main page]

File: rhythmtapping2.py

package info (click to toggle)
solfege 3.10.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,408 kB
  • ctags: 4,270
  • sloc: python: 22,161; xml: 7,536; ansic: 4,442; makefile: 685; sh: 308
file content (82 lines) | stat: -rw-r--r-- 3,405 bytes parent folder | download
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
# GNU Solfege - free ear training software
# Copyright (C) 2006, 2007, 2008  Tom Cato Amundsen
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

import gtk
import abstract
import lessonfile
import mpd
import rhythmtapping

class Teacher(abstract.RhythmAddOnClass, rhythmtapping.Teacher):
    def __init__(self, exname, app):
        rhythmtapping.Teacher.__init__(self, exname, app)
        self.lessonfileclass = lessonfile.HeaderLessonfile
    def play_question(self):
        self.play_rhythm(self.get_music_string())
    def get_timedelta_list(self):
        """
        Return a list of the number of seconds between it should be between
        each tap.
        """
        lexer = mpd.parser.Lexer(self.get_music_notenames(False))
        x = len(lexer.m_string)
        retval = []
        while lexer.m_idx < x:
            toc, toc_data = lexer.get()
            retval.append(float(toc_data.m_duration.get_rat_value()) * 4 / self.m_P.header.bpm * 60)
        return retval

class Gui(rhythmtapping.Gui, abstract.RhythmAddOnGuiClass):
    def __init__(self, teacher, window):
        rhythmtapping.Gui.__init__(self, teacher, window)
        self.add_select_elements_gui()
        self.add_select_num_beats_gui()
    def do_at_question_start_show_play(self):
        """
        It will show and/or play music based on
        the header.at_question_start  variable.

        The Teacher class of all exercises that use this method must
        have a .play_question method.
        """
        if self.m_t.m_P.header.at_question_start == 'show':
            self.show_answer()
        elif self.m_t.m_P.header.at_question_start == 'play':
            self.m_t.play_question()
            #if 'cuemusic' in self.m_t.m_P.get_question():
            #    self.display_music('cuemusic')
        else:
            # Have to do it this way because both lesson files with question
            # blocks and lesson files with only a lesson file header use
            # this method. And only lesson files based on QuestionsLessonfile
            # implement .play_question.
            self.m_t.play_question()
            if 'show' in self.m_t.m_P.header.at_question_start \
                and 'play' in self.m_t.m_P.header.at_question_start:
                self.show_answer()
    def on_repeat(self, widget):
        self.m_t.play_question()
        self.g_tap.grab_focus()
    def on_start_practise(self):
        self.m_t.m_custom_mode = bool(self.m_t.m_P.header.configurable_rhythm_elements)
        self.m_t.set_elements_variables()
        if self.m_t.m_custom_mode:
            self.update_select_elements_buttons()
            self.g_element_frame.show()
        else:
            self.g_element_frame.hide()
        self.m_t.set_default_header_values()
        rhythmtapping.Gui.on_start_practise(self)