1
# GNU Solfege - free ear training software
2
# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008 Tom Cato Amundsen
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
from __future__ import absolute_import
20
In addition to the names in this file, only this is public in
29
LOWEST_NOTENAME="c,,,,"
30
HIGHEST_NOTENAME="g''''''"
32
from solfege.mpd.musicalpitch import MusicalPitch, InvalidNotenameException
33
from solfege.mpd.interval import Interval
34
from solfege.mpd.mpdutils import notename_to_int, int_to_notename, int_to_user_notename
35
from solfege.mpd.rat import Rat
36
from solfege.mpd.track import Track, PercussionTrack
37
from solfege.mpd._exceptions import MpdException
39
def music_to_tracklist(music, start=None, end=None):
41
return a list of tracks, where track[0] use only channel 0,
42
track[1] only use channel 1 etc.
44
score = parser.parse_to_score_object(music)
45
tracks = score.get_midi_events(start, end)
48
def music_to_track(music, start=None, end=None):
49
score = parser.parse_to_score_object(music)
50
tracklist = score.get_midi_events(start, end)
52
for x in range(1, len(tracklist)):
53
track.merge_with(tracklist[x])
61
def transpose_notename(n, t):
62
assert isinstance(n, basestring)
63
assert isinstance(t, int)
70
return int_to_notename(notename_to_int(n) + t)
72
def compare_notenames(n1, n2):
73
return notename_to_int(n1) - notename_to_int(n2)
77
argument s is a string with notenames like this: " c e g c' f' g''"
79
lowest = HIGHEST_NOTENAME
80
highest = LOWEST_NOTENAME
82
if compare_notenames(n, lowest) < 0:
84
if compare_notenames(n, highest) > 1:
86
if compare_notenames(highest, "c'") < 0:
88
if compare_notenames(lowest, "c'") >= 0:
90
if compare_notenames(highest, "c'") > compare_notenames("c'", lowest):