hydrogen 1.2.3
Lilypond.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef LILYPOND_H
24#define LILYPOND_H
25
26#include <QString>
27
28#include <fstream>
29#include <utility>
30#include <vector>
31
32namespace H2Core {
33
34class Pattern;
35class PatternList;
36class Song;
37
39
40class LilyPond {
41public:
42 LilyPond();
43
44 /*
45 * Retrieve all needed data from an Hydrogen song
46 * @param song the Hydrogen song to convert
47 */
48 void extractData( const Song &song );
49
50 /*
51 * Write the LilyPond format into a file
52 * @param sFilename name of output file
53 */
54 void write( const QString &sFilename ) const;
55
56private:
57 /*
58 * This structure represents the notes in a measure.
59 * A measure is a vector containing the notes in it.
60 * The index in the main vector is 1/48th of a beat.
61 * An element in the main vector is the list of notes at this moment.
62 * A note is represented by its instrument and its velocity.
63 */
64 typedef std::vector<std::vector<std::pair<int, float> > > notes_t;
65
66 /*
67 * Retrieve the information in a PatternList
68 * @param list the PatternList where the information is
69 * @param notes where to store the information to
70 */
71 static void addPatternList( const PatternList &list, notes_t &notes );
72
73 /*
74 * Retrieve the information in a Pattern
75 * @param pattern the Pattern where the information is
76 * @param notes where to store the information to
77 */
78 static void addPattern( const Pattern &pattern, notes_t &notes );
79
81 void writeMeasures( std::ofstream &stream ) const;
82
84 void writeUpper( std::ofstream &stream, unsigned nMeasure ) const;
85
87 void writeLower( std::ofstream &stream, unsigned nMeasure ) const;
88
89 /*
90 * Write voice of given measure to stream, ignore certain notes
91 * @param stream the stream to write to
92 * @param nMeasure the measure to write
93 * @param whiteList the list of notes to consider, the other are ignored
94 */
95 void writeVoice( std::ofstream &stream,
96 unsigned nMeasure,
97 const std::vector<int> &whiteList ) const;
98
99 std::vector<notes_t> m_Measures;
100 QString m_sName;
101 QString m_sAuthor;
102 float m_fBPM;
103};
104}
105
106#endif // LILYPOND_H
A class to convert a Hydrogen song to LilyPond format.
Definition Lilypond.h:40
QString m_sName
Name of the song.
Definition Lilypond.h:100
std::vector< std::vector< std::pair< int, float > > > notes_t
Definition Lilypond.h:64
void extractData(const Song &song)
Definition Lilypond.cpp:65
static void addPattern(const Pattern &pattern, notes_t &notes)
Definition Lilypond.cpp:124
QString m_sAuthor
Author of the song.
Definition Lilypond.h:101
static void addPatternList(const PatternList &list, notes_t &notes)
Definition Lilypond.cpp:115
std::vector< notes_t > m_Measures
Representation of the song.
Definition Lilypond.h:99
void writeUpper(std::ofstream &stream, unsigned nMeasure) const
Write upper voice of given measure to stream.
Definition Lilypond.cpp:165
void writeLower(std::ofstream &stream, unsigned nMeasure) const
Write lower voice of given measure to stream.
Definition Lilypond.cpp:181
void writeVoice(std::ofstream &stream, unsigned nMeasure, const std::vector< int > &whiteList) const
Definition Lilypond.cpp:242
void writeMeasures(std::ofstream &stream) const
Write measures in LilyPond format to stream.
Definition Lilypond.cpp:145
float m_fBPM
BPM of the song.
Definition Lilypond.h:102
void write(const QString &sFilename) const
Definition Lilypond.cpp:86
PatternList is a collection of patterns.
Definition PatternList.h:43
Pattern class is a Note container.
Definition Pattern.h:46
Song class.
Definition Song.h:61