hydrogen 1.2.6
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-2025 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#include <QTextStream>
28
29#include <utility>
30#include <vector>
31
32#include <core/Object.h>
33
34namespace H2Core {
35
36class Pattern;
37class PatternList;
38class Song;
39
41
42class LilyPond : public H2Core::Object<LilyPond>{
44public:
45 LilyPond();
46
47 /*
48 * Retrieve all needed data from an Hydrogen song
49 * @param song the Hydrogen song to convert
50 */
51 void extractData( const Song &song );
52
53 /*
54 * Write the LilyPond format into a file
55 * @param sFilename name of output file
56 */
57 void write( const QString &sFilename ) const;
58
59private:
60 /*
61 * This structure represents the notes in a measure.
62 * A measure is a vector containing the notes in it.
63 * The index in the main vector is 1/48th of a beat.
64 * An element in the main vector is the list of notes at this moment.
65 * A note is represented by its instrument and its velocity.
66 */
67 typedef std::vector<std::vector<std::pair<int, float> > > notes_t;
68
69 /*
70 * Retrieve the information in a PatternList
71 * @param list the PatternList where the information is
72 * @param notes where to store the information to
73 */
74 static void addPatternList( const PatternList &list, notes_t &notes );
75
76 /*
77 * Retrieve the information in a Pattern
78 * @param pattern the Pattern where the information is
79 * @param notes where to store the information to
80 */
81 static void addPattern( const Pattern &pattern, notes_t &notes );
82
84 void writeMeasures( QTextStream &stream ) const;
85
87 void writeUpper( QTextStream &stream, unsigned nMeasure ) const;
88
90 void writeLower( QTextStream &stream, unsigned nMeasure ) const;
91
92 /*
93 * Write voice of given measure to stream, ignore certain notes
94 * @param stream the stream to write to
95 * @param nMeasure the measure to write
96 * @param whiteList the list of notes to consider, the other are ignored
97 */
98 void writeVoice( QTextStream &stream,
99 unsigned nMeasure,
100 const std::vector<int> &whiteList ) const;
101
102 std::vector<notes_t> m_Measures;
103 QString m_sName;
104 QString m_sAuthor;
105 float m_fBPM;
106};
107}
108
109#endif // LILYPOND_H
#define H2_OBJECT(name)
Definition Object.h:227
QString m_sName
Name of the song.
Definition Lilypond.h:103
std::vector< std::vector< std::pair< int, float > > > notes_t
Definition Lilypond.h:67
void extractData(const Song &song)
Definition Lilypond.cpp:75
void writeMeasures(QTextStream &stream) const
Write measures in LilyPond format to stream.
Definition Lilypond.cpp:166
static void addPattern(const Pattern &pattern, notes_t &notes)
Definition Lilypond.cpp:145
QString m_sAuthor
Author of the song.
Definition Lilypond.h:104
static void addPatternList(const PatternList &list, notes_t &notes)
Definition Lilypond.cpp:136
void writeLower(QTextStream &stream, unsigned nMeasure) const
Write lower voice of given measure to stream.
Definition Lilypond.cpp:202
std::vector< notes_t > m_Measures
Representation of the song.
Definition Lilypond.h:102
void writeUpper(QTextStream &stream, unsigned nMeasure) const
Write upper voice of given measure to stream.
Definition Lilypond.cpp:186
void writeVoice(QTextStream &stream, unsigned nMeasure, const std::vector< int > &whiteList) const
Definition Lilypond.cpp:263
float m_fBPM
BPM of the song.
Definition Lilypond.h:105
void write(const QString &sFilename) const
Definition Lilypond.cpp:96
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