Skip to content
Snippets Groups Projects
Verified Commit 7d14cb74 authored by dos's avatar dos
Browse files

Cache tempo marks

parent bedeb5e4
No related branches found
No related tags found
No related merge requests found
from st3m.ui.view import BaseView, ViewTransitionBlend from st3m.ui.view import BaseView, ViewTransitionBlend
import gc import gc
import sys_display import time
import song import song
import utils import utils
...@@ -43,5 +43,10 @@ class LoadingView(BaseView): ...@@ -43,5 +43,10 @@ class LoadingView(BaseView):
utils.blm_timeout(self, delta_ms) utils.blm_timeout(self, delta_ms)
if self.vm.transitioning or not self.is_active(): return if self.vm.transitioning or not self.is_active(): return
#gc.collect() #gc.collect()
self.vm.replace(song.SongView(self.app, self.song, self.difficulty), ViewTransitionBlend()) t = time.ticks_ms()
view = song.SongView(self.app, self.song, self.difficulty)
t = time.ticks_ms() - t
if t < 2000:
time.sleep_ms(2000 - t)
self.vm.replace(view, ViewTransitionBlend())
gc.collect() gc.collect()
...@@ -125,6 +125,9 @@ class MidiReader(midi.MidiOutStream): ...@@ -125,6 +125,9 @@ class MidiReader(midi.MidiOutStream):
self.nTracks = -1 self.nTracks = -1
self.ignored = False self.ignored = False
self.current_tempo_marker = 0
self.scaledTime = 0
def addEvent(self, track, event): def addEvent(self, track, event):
time = event.time time = event.time
if time is None: if time is None:
...@@ -139,26 +142,27 @@ class MidiReader(midi.MidiOutStream): ...@@ -139,26 +142,27 @@ class MidiReader(midi.MidiOutStream):
#elif track < len(self.tracks): #elif track < len(self.tracks):
# self.tracks[track].addEvent(time, event) # self.tracks[track].addEvent(time, event)
def abs_time(self): def ticksToBeats(self, ticks, bpm):
def ticksToBeats(ticks, bpm):
return (60000.0 * ticks) / (bpm * self.ticksPerBeat) return (60000.0 * ticks) / (bpm * self.ticksPerBeat)
def abs_time(self):
if self.bpm: if self.bpm:
currentTime = midi.MidiOutStream.abs_time(self) currentTime = midi.MidiOutStream.abs_time(self)
# Find out the current scaled time. if self.current_tempo_marker == 0:
# Yeah, this is reeally slow, but fast enough :) tempoMarkerTime, currentBpm = 0.0, self.bpm
scaledTime = 0.0 else:
tempoMarkerTime = 0.0 # Find out the current scaled time. tempoMarkerTime, currentBpm = self.tempoMarkers[self.current_tempo_marker - 1]
currentBpm = self.bpm while len(self.tempoMarkers) > self.current_tempo_marker:
for i in range(len(self.tempoMarkers)): time, bpm = self.tempoMarkers[self.current_tempo_marker]
time, bpm = self.tempoMarkers[i]
if time > currentTime: if time > currentTime:
break break
scaledTime += ticksToBeats(time - tempoMarkerTime, currentBpm) self.scaledTime += self.ticksToBeats(time - tempoMarkerTime, currentBpm)
self.current_tempo_marker += 1
tempoMarkerTime, currentBpm = time, bpm tempoMarkerTime, currentBpm = time, bpm
return scaledTime + ticksToBeats(currentTime - tempoMarkerTime, currentBpm)
return self.scaledTime + self.ticksToBeats(currentTime - tempoMarkerTime, currentBpm)
return 0.0 return 0.0
def header(self, format, nTracks, division): def header(self, format, nTracks, division):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment