Get a Bar object and return the LilyPond equivalent in a string. The showkey and showtime parameters can be set to determine whether the key and the time should be shown.
(bar, showkey=True, showtime=True)
| 121 | |
| 122 | |
| 123 | def from_Bar(bar, showkey=True, showtime=True): |
| 124 | """Get a Bar object and return the LilyPond equivalent in a string. |
| 125 | |
| 126 | The showkey and showtime parameters can be set to determine whether the |
| 127 | key and the time should be shown. |
| 128 | """ |
| 129 | # Throw exception |
| 130 | if not hasattr(bar, "bar"): |
| 131 | return False |
| 132 | |
| 133 | # Process the key |
| 134 | if showkey: |
| 135 | key_note = Note(bar.key.key[0].upper() + bar.key.key[1:]) |
| 136 | key = "\\key %s \\%s " % ( |
| 137 | from_Note(key_note, False, standalone=False), |
| 138 | bar.key.mode, |
| 139 | ) |
| 140 | result = key |
| 141 | else: |
| 142 | result = "" |
| 143 | |
| 144 | # Handle the NoteContainers |
| 145 | latest_ratio = (1, 1) |
| 146 | ratio_has_changed = False |
| 147 | for bar_entry in bar.bar: |
| 148 | parsed_value = value.determine(bar_entry[1]) |
| 149 | ratio = parsed_value[2:] |
| 150 | if ratio == latest_ratio: |
| 151 | result += ( |
| 152 | from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " " |
| 153 | ) |
| 154 | else: |
| 155 | if ratio_has_changed: |
| 156 | result += "}" |
| 157 | result += "\\times %d/%d {" % (ratio[1], ratio[0]) |
| 158 | result += ( |
| 159 | from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + " " |
| 160 | ) |
| 161 | latest_ratio = ratio |
| 162 | ratio_has_changed = True |
| 163 | if ratio_has_changed: |
| 164 | result += "}" |
| 165 | |
| 166 | # Process the time |
| 167 | if showtime: |
| 168 | return "{ \\time %d/%d %s}" % (bar.meter[0], bar.meter[1], result) |
| 169 | else: |
| 170 | return "{ %s}" % result |
| 171 | |
| 172 | |
| 173 | def from_Track(track): |
no test coverage detected