|
From: Felix B. <fbe...@us...> - 2010-05-22 05:01:43
|
Module: performous
Branch: master
Commit: dc2cb48f05fe2e17c10389b3edf20ace69c43c32
Author: Felix Bertram <fl...@be...>
Date: Fri May 21 20:13:49 2010 -0700
Cleanup for song sections
---
game/midifile.cc | 2 +-
game/midifile.hh | 8 +++---
game/screen_sing.cc | 56 +++++++++++++++--------------------------------
game/song.cc | 24 ++++++++++++++++++++
game/song.hh | 2 +
game/songparser-ini.cc | 15 +++++++-----
6 files changed, 58 insertions(+), 49 deletions(-)
diff --git a/game/midifile.cc b/game/midifile.cc
index ca3a236..064ead9 100644
--- a/game/midifile.cc
+++ b/game/midifile.cc
@@ -189,7 +189,7 @@ MidiFileParser::Track MidiFileParser::read_track(MidiStream& stream) {
#if MIDI_DEBUG_LEVEL > 2
std::cout << "Section: " << sect_name << " at " << get_seconds(miditime) << std::endl;
#endif
- songsections.push_back(SongSection(sect_name, get_seconds(miditime)));
+ midisections.push_back(MidiSection(sect_name, get_seconds(miditime)));
} else cmdevents.push_back(std::string(data)); // see songparser-ini.cc: we need to keep the BRE in cmdevents
}
else cmdevents.push_back(std::string(data));
diff --git a/game/midifile.hh b/game/midifile.hh
index 6db8258..463181c 100644
--- a/game/midifile.hh
+++ b/game/midifile.hh
@@ -76,13 +76,13 @@ class MidiFileParser{
};
typedef std::vector<Track> Tracks;
Tracks tracks;
- struct SongSection {
+ struct MidiSection {
std::string name;
double begin;
- SongSection(std::string const& name, const double begin): name(name), begin(begin) {}
+ MidiSection(std::string const& name, const double begin): name(name), begin(begin) {}
};
- typedef std::vector<SongSection> SongSections;
- SongSections songsections; ///< vector of song sections
+ typedef std::vector<MidiSection> MidiSections;
+ MidiSections midisections; ///< vector of song sections
uint16_t parse_header(MidiStream&);
Track read_track(MidiStream&);
void cout_midi_event(uint8_t type, uint8_t arg1, uint8_t arg2, uint32_t miditime);
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 51e4bfa..c10dcc0 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -264,46 +264,26 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_F6) dispInFlash(++config["audio/controller_delay"]);
bool seekback = false;
- if (m_song->songsections.empty()) {
- // standard seeking in 5s increments
- if (m_song->danceTracks.empty()) { // Seeking backwards is currently not permitted for dance songs
- if (key == SDLK_HOME) { m_audio.seekPos(0.0); seekback = true; }
- if (key == SDLK_LEFT) { m_audio.seek(-5.0); seekback = true;}
- }
- if (key == SDLK_RIGHT) m_audio.seek(5.0);
- } else {
- // seeking to the next song section
- if (m_song->danceTracks.empty()) { // Seeking backwards is currently not permitted for dance songs
- if (key == SDLK_HOME) { m_audio.seekPos(0.0); seekback = true; }
- if (key == SDLK_LEFT) {
- double pos = m_audio.getPosition();
- for (std::vector<Song::SongSection>::reverse_iterator it= m_song->songsections.rbegin(); it != m_song->songsections.rend(); it++) {
- double begin = it->begin;
- if (begin < pos - 1.0) { // make sure we can jump across a marker!
- m_audio.seekPos(begin);
- // TODO: display popup with section name
- const std::string name = it->name;
- std::cout << "seek left from " << pos << " to " << name << " at " << begin << std::endl;
- break;
- }
- }
- seekback = true;
- }
- }
- if (key == SDLK_RIGHT) {
- double pos = m_audio.getPosition();
- for (std::vector<Song::SongSection>::iterator it= m_song->songsections.begin(); it != m_song->songsections.end(); it++) {
- double begin = it->begin;
- if (begin > pos) {
- m_audio.seekPos(begin);
- // TODO: display popup with section name
- const std::string name = it->name;
- std::cout << "seek right from " << pos << " to " << name << " at " << begin << std::endl;
- break;
- }
- }
+ if (m_song->danceTracks.empty()) { // Seeking backwards is currently not permitted for dance songs
+ if (key == SDLK_HOME) { m_audio.seekPos(0.0); seekback = true; }
+ if (key == SDLK_LEFT) {
+ Song::SongSection section("error", 0);
+ if (m_song->getPrevSection(m_audio.getPosition(), section)) {
+ m_audio.seekPos(section.begin);
+ // TODO: display popup with section.name here
+ std::cout << section.name << std::endl;
+ } else m_audio.seek(-5.0);
+ seekback = true;
}
}
+ if (key == SDLK_RIGHT) {
+ Song::SongSection section("error", 0);
+ if (m_song->getNextSection(m_audio.getPosition(), section)) {
+ m_audio.seekPos(section.begin);
+ // TODO: display popup with section.name here
+ std::cout << section.name << std::endl;
+ } else m_audio.seek(5.0);
+ }
// Some things must be reset after seeking backwards
if (seekback) m_layout_singer->reset();
diff --git a/game/song.cc b/game/song.cc
index c6274e6..e8c13c8 100644
--- a/game/song.cc
+++ b/game/song.cc
@@ -79,3 +79,27 @@ Song::Status Song::status(double time) const {
return NORMAL;
}
+bool Song::getNextSection(double pos, SongSection §ion) {
+ if (songsections.empty()) return false;
+ for (std::vector<Song::SongSection>::iterator it= songsections.begin(); it != songsections.end(); it++) {
+ if (it->begin > pos) {
+ section = *it;
+ return true;
+ }
+ }
+ // returning false here will jump forward 5s (see screen_sing.cc)
+ return false;
+}
+
+bool Song::getPrevSection(double pos, SongSection §ion) {
+ if (songsections.empty()) return false;
+ for (std::vector<Song::SongSection>::reverse_iterator it= songsections.rbegin(); it != songsections.rend(); it++) {
+ // subtract 1 second so we can jump across a section
+ if (it->begin < pos - 1.0) {
+ section = *it;
+ return true;
+ }
+ }
+ // returning false here will jump backwards by 5s (see screen_sing.cc)
+ return false;
+}
diff --git a/game/song.hh b/game/song.hh
index fba45f0..37aed1b 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -99,6 +99,8 @@ class Song: boost::noncopyable {
};
typedef std::vector<SongSection> SongSections;
SongSections songsections; ///< vector of song sections
+ bool getNextSection(double pos, SongSection §ion);
+ bool getPrevSection(double pos, SongSection §ion);
};
static inline bool operator<(Song const& l, Song const& r) { return l.collateByArtist < r.collateByArtist; }
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index c110d50..b6ceede 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -130,12 +130,6 @@ void SongParser::iniParseHeader() {
}
}
}
- // populate song sections
- for (std::vector<MidiFileParser::SongSection>::iterator it= midi.songsections.begin(); it != midi.songsections.end(); it++) {
- Song::SongSection tmp(it->name, it->begin);
- s.songsections.push_back(tmp);
- //std::cout << "Section " << tmp.name << " at " << tmp.begin << std::endl;
- }
}
/// Parse notes
@@ -270,6 +264,15 @@ void SongParser::iniParse() {
s.vocals.noteMin = s.vocals.noteMax = n.note = 60;
s.vocals.notes.push_back(n);
}*/
+ // copy midi sections to song section
+ // design goals: (1) keep midi parser free of dependencies on song (2) store data in song as parsers are discarded before song
+ // one option would be to pass a song reference to the midi parser however, that conflicts with goal (1)
+ for (std::vector<MidiFileParser::MidiSection>::iterator it= midi.midisections.begin(); it != midi.midisections.end(); it++) {
+ Song::SongSection tmp(it->name, it->begin);
+ s.songsections.push_back(tmp);
+ //std::cout << "Section " << tmp.name << " at " << tmp.begin << std::endl;
+ }
+
}
|