~ubuntu-branches/ubuntu/precise/ultrastar-ng/precise

« back to all changes in this revision

Viewing changes to include/songs.h

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz, Miriam Ruiz, Mario Bonino, Jon Dowland, Ansgar Burchardt
  • Date: 2008-06-07 16:43:18 UTC
  • mfrom: (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080607164318-4cnzizck1tp8mrwp
Tags: 0.2.1-1
[ Miriam Ruiz ]
* New Upstream Release (Closes: #453132)
* Removed unneeded patches
* Added packages to build deps:
  + libtool
  + portaudio19-dev | portaudio-dev
  + libboost-dev, libboost-thread-dev, libboost-serialization-dev
  + libboost-program-options-dev, libboost-regex-dev
* Moved shared objects to private directory: /usr/lib/ultraster-ng
* Added rpath to binaries to search for shared objects in the private dir
* Uses ultrastar-ng-gstreamer as default, instead of ultrastar-ng-xine,
  since there are significantly less issues with GStreamer.
* Added patch to fix upstream desktop file
* Added -Wl,-as-needed to LDFLAGS
* Replaced fftw3-dev by libfftw3-dev in build dependencies.
* Standards-Version upgraded to 3.7.3

[ Mario Bonino ]
* Fixed data/Makefile.am to install .desktop file and icon

[ Jon Dowland ]
* add Homepage: control field to source stanza
* fix a bashism in debian/rules (Closes: #478634)

[ Ansgar Burchardt ]
* debian/control: Change XS-Vcs-* to Vcs-*
* Remove Homepage semi-field from description

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#define __SONGS_H__
3
3
 
4
4
#include "../config.h"
5
 
 
6
 
typedef struct _SBpm {
7
 
        float bpm;
8
 
        float start;
9
 
} TBpm ;
10
 
 
11
 
typedef struct _SScore {
12
 
        char * name;
13
 
        int hits;
14
 
        int total;
15
 
        int score;
16
 
        char * length;
17
 
} TScore ;
18
 
 
19
 
#define TYPE_NOTE_FREESTYLE 0
20
 
#define TYPE_NOTE_NORMAL  1
21
 
#define TYPE_NOTE_GOLDEN 2
22
 
#define TYPE_NOTE_SLEEP 3
23
 
 
24
 
typedef struct _SNote {
25
 
        int type;
26
 
        int timestamp;
27
 
        int length;
 
5
#include <boost/noncopyable.hpp>
 
6
#include <boost/ptr_container/ptr_set.hpp>
 
7
#include <boost/scoped_ptr.hpp>
 
8
#include <set>
 
9
#include <string>
 
10
#include <vector>
 
11
 
 
12
class MusicalScale {
 
13
        double m_baseFreq;
 
14
        static const int m_baseId = 33;
 
15
  public:
 
16
        MusicalScale(double baseFreq = 440.0): m_baseFreq(baseFreq) {}
 
17
        std::string getNoteStr(double freq) const;
 
18
        unsigned int getNoteNum(int id) const;
 
19
        bool isSharp(int id) const;
 
20
        double getNoteFreq(int id) const;
 
21
        int getNoteId(double freq) const;
 
22
        double getNote(double freq) const;
 
23
        double getNoteOffset(double freq) const;
 
24
};
 
25
 
 
26
struct Note {
 
27
        double begin, end;
 
28
        enum Type { FREESTYLE = 'F', NORMAL = ':', GOLDEN = '*', SLEEP = '-'} type;
28
29
        int note;
29
 
        int curMaxScore;
30
 
        char * syllable;
31
 
} TNote;
32
 
 
33
 
class CSong {
34
 
        public:
35
 
        CSong();
36
 
        ~CSong() {};
37
 
        void parseFile( void );
38
 
 
39
 
        unsigned int index;
40
 
        char * path;
41
 
        char * filename;
42
 
        std::vector <char *> category;
43
 
        char * genre;
44
 
        char * edition;
45
 
        char * title;
46
 
        char * artist;
47
 
        char * text;
48
 
        char * creator;
49
 
        char * cover;
50
 
        SDL_Surface * coverSurf;
51
 
        char * mp3;
52
 
        char * background;
53
 
         SDL_Surface * backgroundSurf;  
54
 
        char * video;
55
 
        float videoGap;
56
 
        int noteGap;
57
 
        float start;
58
 
        int end;
59
 
        bool relative;
60
 
        std::vector <TBpm> bpm;
61
 
        float gap;
62
 
        TScore score[3];
63
 
        int noteMin;
64
 
        int noteMax;
65
 
        std::vector <TNote *> notes;
66
 
        bool visible;
67
 
        bool main;
68
 
        int orderNum;
69
 
        int orderType;
70
 
        int maxScore;
71
 
};
72
 
 
73
 
class CSongs {
74
 
        public:
75
 
                CSongs();
76
 
                ~CSongs();
77
 
                CSong * getSong( unsigned int i );
78
 
                int nbSongs( void ) {return songs.size();};
79
 
                bool parseFile( CSong * tmp );
80
 
                void sortByEdition( void );
81
 
                void sortByGenre( void );
82
 
                void sortByTitle( void );
83
 
                void sortByArtist( void );
84
 
                int getOrder( void ) {return order;};
85
 
        private:
86
 
                std::vector <CSong*> songs;
87
 
                int selected;
88
 
                int order;
89
 
                int category;
90
 
                SDL_Surface * surface_nocover;
 
30
        std::string syllable;
 
31
        double diff(double n) const;
 
32
        double maxScore() const;
 
33
        double score(double freq, double b, double e) const;
 
34
  private:
 
35
        double scoreMultiplier(double error) const;
 
36
};
 
37
 
 
38
class SongParser;
 
39
 
 
40
class Song: boost::noncopyable {
 
41
  public:
 
42
        friend class SongParser;
 
43
        Song(std::string const& path, std::string const& filename);
 
44
        ~Song() {
 
45
                unloadBackground();
 
46
                unloadCover();
 
47
        }
 
48
        // Temporary score calculation system
 
49
        void reset();
 
50
        void update(double time, double freq);
 
51
        int getScore() const { return 10000 * m_score; }
 
52
        bool parseField(std::string const& line);
 
53
        std::string str() const { return title + " by " + artist; }
 
54
        SDL_Surface* getCover() { loadCover(); return m_coverSurf; }
 
55
        SDL_Surface* getBackground() { loadBackground(); return m_backgroundSurf; }
 
56
        void loadBackground();
 
57
        void loadCover();
 
58
        void unloadBackground();
 
59
        void unloadCover();
 
60
        typedef std::vector<Note> notes_t;
 
61
        notes_t notes;
 
62
        int noteMin, noteMax;
 
63
        std::string path;
 
64
        std::string filename;
 
65
        std::vector<std::string> category;
 
66
        std::string genre;
 
67
        std::string edition;
 
68
        std::string title;
 
69
        std::string artist;
 
70
        std::string text;
 
71
        std::string creator;
 
72
        std::string mp3;
 
73
        std::string cover;
 
74
        std::string background;
 
75
        std::string video;
 
76
        double videoGap;
 
77
        double start;
 
78
        MusicalScale scale;
 
79
  private:
 
80
        SDL_Surface* m_coverSurf;
 
81
        SDL_Surface* m_backgroundSurf;
 
82
        double m_scoreFactor; // Normalization factor for the scoring system
 
83
        // Temporary score calculation system
 
84
        double m_score;
 
85
        double m_scoreTime;
 
86
        notes_t::const_iterator m_scoreIt;
 
87
};
 
88
 
 
89
bool operator<(Song const& l, Song const& r);
 
90
 
 
91
class Songs {
 
92
        std::set<std::string> m_songdirs;
 
93
  public:
 
94
        Songs(std::set<std::string> const& songdirs);
 
95
        ~Songs();
 
96
        void reload();
 
97
        Song& operator[](std::vector<Song*>::size_type pos) { return *m_filtered[pos]; }
 
98
        int size() const { return m_filtered.size(); };
 
99
        int empty() const { return m_filtered.empty(); };
 
100
        void advance(int diff) {
 
101
                m_current = (m_current + diff) % int(m_filtered.size());
 
102
                if (m_current < 0) m_current += m_filtered.size();
 
103
        }
 
104
        int currentId() const { return m_current; }
 
105
        Song& current() { return *m_filtered[m_current]; }
 
106
        Song const& current() const { return *m_filtered[m_current]; }
 
107
        void setFilter(std::string const& regex);
 
108
        std::string sortDesc() const;
 
109
        void random();
 
110
        void sortChange(int diff);
 
111
        void parseFile(Song& tmp);
 
112
        SDL_Surface* getEmptyCover() { return surface_nocover; }
 
113
  private:
 
114
        class RestoreSel;
 
115
        typedef boost::ptr_set<Song> songlist_t;
 
116
        songlist_t m_songs;
 
117
        typedef std::vector<Song*> filtered_t;
 
118
        filtered_t m_filtered;
 
119
        int m_current;
 
120
        int m_order;
 
121
        SDL_Surface* surface_nocover;
 
122
        void sort_internal();
91
123
};
92
124
 
93
125
#endif
 
126