38 "\\version \"2.16.2\"\n"
42 " (bassdrum default #f -3) ; Kick\n"
43 " (lowoodblock triangle #f 0) ; Stick\n"
44 " (snare default #f 1) ; Snare\n"
45 " (maracas triangle #f -3) ; Hand Clap\n"
46 " (highfloortom default #f -1) ; Tom Low\n"
47 " (hihat cross #f 5) ; Closed HH\n"
48 " (lowtom default #f 2) ; Tom Mid\n"
49 " (pedalhihat cross #f -5) ; Pedal HH\n"
50 " (hightom default #f 3) ; Tom Hi\n"
51 " (openhihat cross \"open\" 5) ; Open HH\n"
52 " (cowbell triangle #f 3) ; Cowbell\n"
53 " (ridecymbal cross #f 4) ; Main Ride\n"
54 " (crashcymbal cross #f 6) ; Main Crash\n"
55 " (ridecymbala cross #f 4) ; Additional Ride\n"
56 " (crashcymbala cross #f 7) ; Additional Crash\n"
73 if ( !group || group->size() == 0 ) {
77 unsigned nSize = group->size();
78 m_Measures = std::vector<notes_t>( nSize );
79 for (
unsigned nPatternList = 0; nPatternList < nSize; nPatternList++ ) {
80 if (
PatternList *pPatternList = ( *group )[ nPatternList ] ) {
81 addPatternList( *pPatternList, m_Measures[ nPatternList ] );
87 std::ofstream file( sFilename.toLocal8Bit() );
93 file <<
"\\header {\n";
94 file <<
" title = \"" << m_sName.toUtf8().constData() <<
"\"\n";
95 file <<
" composer = \"" << m_sAuthor.toUtf8().constData() <<
"\"\n";
96 file <<
" tagline = \"Generated by Hydrogen " H2CORE_VERSION "\"\n";
99 file <<
"\\score {\n";
100 file <<
" \\new DrumStaff <<\n";
101 file <<
" \\set DrumStaff.drumStyleTable = #(alist->hash-table "
103 file <<
" \\override Staff.TimeSignature #'style = #'() % Display "
105 file <<
" \\set Staff.beamExceptions = #'() % Beam "
106 "quavers two by two\n";
107 file <<
" \\drummode {\n";
108 file <<
" \\tempo 4 = " <<
static_cast<int>( m_fBPM ) <<
"\n\n";
109 writeMeasures( file );
117 for (
unsigned nPattern = 0; nPattern < list.
size(); nPattern++ ) {
118 if (
const Pattern *pPattern = list.
get( nPattern ) ) {
119 addPattern( *pPattern, to );
126 for (
unsigned nNote = 0; nNote < pattern.
get_length(); nNote++ ) {
127 if ( nNote >= notes.size() ) {
128 notes.push_back( std::vector<std::pair<int, float> >() );
132 if ( !pPatternNotes ) {
136 if (
Note *pNote = it->second ) {
137 int nId = pNote->get_instrument_id();
138 float fVelocity = pNote->get_velocity();
139 notes[ nNote ].push_back( std::make_pair( nId, fVelocity ) );
146 unsigned nSignature = 0;
147 for (
unsigned nMeasure = 0; nMeasure < m_Measures.size(); nMeasure++ ) {
149 stream <<
"\n % Measure " << nMeasure + 1 <<
"\n";
150 unsigned nNewSignature = m_Measures[ nMeasure ].size() / 48;
151 if ( nSignature != nNewSignature ) {
152 nSignature = nNewSignature;
153 stream <<
" \\time " << nSignature <<
"/4\n";
158 writeUpper( stream, nMeasure );
159 stream <<
" } \\\\ {\n";
160 writeLower( stream, nMeasure );
166 unsigned nMeasure )
const {
168 std::vector<int> whiteList;
169 whiteList.push_back( 6 );
170 whiteList.push_back( 7 );
171 whiteList.push_back( 9 );
172 whiteList.push_back( 10 );
173 whiteList.push_back( 11 );
174 whiteList.push_back( 12 );
175 whiteList.push_back( 13 );
176 whiteList.push_back( 14 );
177 whiteList.push_back( 15 );
178 writeVoice( stream, nMeasure, whiteList );
182 unsigned nMeasure )
const {
183 std::vector<int> whiteList;
184 whiteList.push_back( 0 );
185 whiteList.push_back( 1 );
186 whiteList.push_back( 2 );
187 whiteList.push_back( 3 );
188 whiteList.push_back( 4 );
189 whiteList.push_back( 5 );
190 whiteList.push_back( 8 );
191 writeVoice( stream, nMeasure, whiteList );
195static const char *
const sNames[] = {
"bd",
"wbl",
"sn",
"mar",
196 "sn",
"tomfh",
"hh",
"toml",
197 "hhp",
"tomh",
"hho",
"cb",
198 "cymr",
"cymc",
"cymra",
"cymca" };
201static void writeNote( std::ofstream &stream,
const std::vector<int> ¬es ) {
202 switch ( notes.size() ) {
203 case 0: stream <<
"r";
break;
204 case 1: stream <<
sNames[ notes[ 0 ] ];
break;
207 for (
unsigned i = 0; i < notes.size(); i++ ) {
208 stream <<
sNames[ notes[ i ] ] <<
" ";
216 if ( 48 % duration == 0 ) {
218 if ( duration % 2 ) {
221 stream << 4 * 48 / duration;
223 }
else if ( duration % 3 == 0 && 48 % ( duration * 2 / 3 ) == 0 ) {
225 if ( duration % 2 ) {
228 stream << 4 * 48 / ( duration * 2 / 3 ) <<
".";
232 for (
int pow = 3; pow >= 0; --pow ) {
233 if ( 3 * ( 1 << pow ) < duration ) {
234 stream << 8 * ( 3 - pow ) <<
" r";
244 const std::vector<int> &whiteList )
const {
246 const notes_t &measure = m_Measures[ nMeasure ];
247 for (
unsigned nStart = 0; nStart < measure.size(); nStart += 48 ) {
248 unsigned lastNote = nStart;
249 for (
unsigned nTime = nStart; nTime < nStart + 48; nTime++ ) {
251 std::vector<int> notes;
252 const std::vector<std::pair<int, float> > &input = measure[ nTime ];
253 for (
unsigned nNote = 0; nNote < input.size(); nNote++ ) {
254 if ( std::find( whiteList.begin(),
256 input[ nNote ].first ) != whiteList.end() ) {
257 notes.push_back( input[ nNote ].first );
262 if ( !notes.empty() || nTime == nStart ) {
264 if ( nTime != nStart ) {
static void writeNote(std::ofstream &stream, const std::vector< int > ¬es)
Write duration in LilyPond format, from number of 1/48th of a beat.
static void writeDuration(std::ofstream &stream, unsigned duration)
static const char *const sNames[]
Write group of note (may also be a rest or a single note)
static const char * sHeader
#define FOREACH_NOTE_CST_IT_BOUND_LENGTH(_notes, _it, _bound, _pattern)
Iterate over all notes in column _bound in an immutable way if it is contained in _pattern.
std::vector< std::vector< std::pair< int, float > > > notes_t
void extractData(const Song &song)
static void addPattern(const Pattern &pattern, notes_t ¬es)
static void addPatternList(const PatternList &list, notes_t ¬es)
void writeUpper(std::ofstream &stream, unsigned nMeasure) const
Write upper voice of given measure to stream.
void writeLower(std::ofstream &stream, unsigned nMeasure) const
Write lower voice of given measure to stream.
void writeVoice(std::ofstream &stream, unsigned nMeasure, const std::vector< int > &whiteList) const
void writeMeasures(std::ofstream &stream) const
Write measures in LilyPond format to stream.
void write(const QString &sFilename) const
A note plays an associated instrument with a velocity left and right pan.
PatternList is a collection of patterns.
int size() const
returns the numbers of patterns
Pattern * get(int idx)
get a pattern from the list
Pattern class is a Note container.
int get_length() const
set the denominator of the pattern
const notes_t * get_notes() const
get the virtual pattern set
std::multimap< int, Note * > notes_t
< multimap note type
std::vector< PatternList * > * getPatternGroupVector()
Return a pointer to a vector storing all Pattern present in the Song.
const QString & getName() const
const QString & getAuthor() const
#define H2CORE_VERSION
A concatenation of H2CORE_VERSION_MAJOR, H2CORE_VERSION_MINOR, H2CORE_VERSION_PATCH,...