316
320
fFits = (!is_lower_time(rTimeRemaining, rSegmentDuration)
317
321
&& !is_greater_time(rConsumedBeatTime, rSegmentAlignBeatTime));
320
//g_pLogger->LogTrace(_T("Composer"), _T("[GenerateScore] sMeasure=%s, pSegment=%s, tr=%.2f, ts=%.2f, tcb=%.2f, tab=%.2f, tc=%.2f, tb=%.2f, fits=%s"),
322
// (pSegment->GetSource()).c_str(), rTimeRemaining, rSegmentDuration,
323
// rConsumedBeatTime, rSegmentAlignBeatTime,
324
// rOccupiedDuration, rBeatDuration,
325
// (fFits ? _T("yes") : _T("no")) );
323
#if (TRACE_COMPOSER == 1)
324
wxLogMessage(_T("[Composer::GenerateScore] sMeasure=%s, pSegment=%s, tr=%.2f, ts=%.2f, tcb=%.2f, tab=%.2f, tc=%.2f, tb=%.2f, fits=%s"),
326
(pSegment->GetSource()).c_str(), rTimeRemaining, rSegmentDuration,
327
rConsumedBeatTime, rSegmentAlignBeatTime,
328
rOccupiedDuration, rBeatDuration,
329
(fFits ? _T("yes") : _T("no")) );
327
332
//if segment fits add it to current measure
455
468
//---------------------------------------------------------------------------------------
456
string Composer::CreateNoteRest(int nNoteRestDuration, bool fNote)
469
wxString Composer::CreateNoteRest(int nNoteRestDuration, bool fNote, bool fCompound,
458
472
//Returns a string with one or more LDP elements containing notes o rests up to a total
459
473
//duration nNoteDuration. They will be notes if fNote==true; otherwise they will be rests.
460
474
//For example, for nNoteDuration=64 it will return "(n * n)"
462
string sElement = "";
476
wxString sElement = _T("");
464
478
int nTimeNeeded = nNoteRestDuration;
466
while (nTimeNeeded > 0)
468
sElement += (fNote ? "(n * " : "(r " );
469
if (nTimeNeeded >= k_duration_whole_dotted)
472
nDuration = k_duration_whole_dotted;
474
else if (nTimeNeeded >= k_duration_whole)
477
nDuration = k_duration_whole;
479
else if (nTimeNeeded >= k_duration_half_dotted)
482
nDuration = k_duration_half_dotted;
484
else if (nTimeNeeded >= k_duration_half)
487
nDuration = k_duration_half;
489
else if (nTimeNeeded >= k_duration_quarter_dotted)
492
nDuration = k_duration_quarter_dotted;
494
else if (nTimeNeeded >= k_duration_quarter)
497
nDuration = k_duration_quarter;
499
else if (nTimeNeeded >= k_duration_eighth_dotted)
502
nDuration = k_duration_eighth_dotted;
504
else if (nTimeNeeded >= k_duration_eighth)
507
nDuration = k_duration_eighth;
509
else if (nTimeNeeded >= k_duration_16th_dotted)
512
nDuration = k_duration_16th_dotted;
514
else if (nTimeNeeded >= k_duration_16th)
517
nDuration = k_duration_16th;
519
else if (nTimeNeeded >= k_duration_32th_dotted)
522
nDuration = k_duration_32th_dotted;
524
else if (nTimeNeeded >= k_duration_32th)
527
nDuration = k_duration_32th;
529
else if (nTimeNeeded >= k_duration_64th_dotted)
532
nDuration = k_duration_64th_dotted;
534
else if (nTimeNeeded >= k_duration_64th)
537
nDuration = k_duration_64th;
539
else if (nTimeNeeded >= k_duration_128th_dotted)
542
nDuration = k_duration_128th_dotted;
544
else if (nTimeNeeded >= k_duration_128th)
547
nDuration = k_duration_128th;
552
nDuration = k_duration_256th;
555
nTimeNeeded -= nDuration;
559
//g_pLogger->LogTrace(_T("Composer"), _T("[CreateNoteRest] Needed duration= %d, added=%s"),
560
// nNoteRestDuration, sElement.c_str());
480
if (fCompound && fFinal)
482
while (nTimeNeeded > 0)
484
sElement += (fNote ? _T("(n * ") : _T("(r ") );
485
if (nTimeNeeded >= k_duration_whole_dotted)
487
sElement += _T("w.)");
488
nDuration = k_duration_whole_dotted;
490
else if (nTimeNeeded >= k_duration_half_dotted)
492
sElement += _T("h.)");
493
nDuration = k_duration_half_dotted;
495
else if (nTimeNeeded >= k_duration_quarter_dotted)
497
sElement += _T("q.)");
498
nDuration = k_duration_quarter_dotted;
500
else if (nTimeNeeded >= k_duration_eighth_dotted)
502
sElement += _T("e.)");
503
nDuration = k_duration_eighth_dotted;
505
else if (nTimeNeeded >= k_duration_16th_dotted)
507
sElement += _T("s.)");
508
nDuration = k_duration_16th_dotted;
510
else if (nTimeNeeded >= k_duration_32th_dotted)
512
sElement += _T("t.)");
513
nDuration = k_duration_32th_dotted;
515
else if (nTimeNeeded >= k_duration_64th_dotted)
517
sElement += _T("i.)");
518
nDuration = k_duration_64th_dotted;
520
else if (nTimeNeeded >= k_duration_128th_dotted)
522
sElement += _T("o.)");
523
nDuration = k_duration_128th_dotted;
527
sElement += _T("f)");
528
nDuration = k_duration_256th;
531
nTimeNeeded -= nDuration;
536
while (nTimeNeeded > 0)
538
sElement += (fNote ? _T("(n * ") : _T("(r ") );
539
if (nTimeNeeded >= k_duration_whole_dotted)
541
sElement += _T("w.)");
542
nDuration = k_duration_whole_dotted;
544
else if (nTimeNeeded >= k_duration_whole)
546
sElement += _T("w)");
547
nDuration = k_duration_whole;
549
else if (nTimeNeeded >= k_duration_half_dotted)
551
sElement += _T("h.)");
552
nDuration = k_duration_half_dotted;
554
else if (nTimeNeeded >= k_duration_half)
556
sElement += _T("h)");
557
nDuration = k_duration_half;
559
else if (nTimeNeeded >= k_duration_quarter_dotted)
561
sElement += _T("q.)");
562
nDuration = k_duration_quarter_dotted;
564
else if (nTimeNeeded >= k_duration_quarter)
566
sElement += _T("q)");
567
nDuration = k_duration_quarter;
569
else if (nTimeNeeded >= k_duration_eighth_dotted)
571
sElement += _T("e.)");
572
nDuration = k_duration_eighth_dotted;
574
else if (nTimeNeeded >= k_duration_eighth)
576
sElement += _T("e)");
577
nDuration = k_duration_eighth;
579
else if (nTimeNeeded >= k_duration_16th_dotted)
581
sElement += _T("s.)");
582
nDuration = k_duration_16th_dotted;
584
else if (nTimeNeeded >= k_duration_16th)
586
sElement += _T("s)");
587
nDuration = k_duration_16th;
589
else if (nTimeNeeded >= k_duration_32th_dotted)
591
sElement += _T("t.)");
592
nDuration = k_duration_32th_dotted;
594
else if (nTimeNeeded >= k_duration_32th)
596
sElement += _T("t)");
597
nDuration = k_duration_32th;
599
else if (nTimeNeeded >= k_duration_64th_dotted)
601
sElement += _T("i.)");
602
nDuration = k_duration_64th_dotted;
604
else if (nTimeNeeded >= k_duration_64th)
606
sElement += _T("i)");
607
nDuration = k_duration_64th;
609
else if (nTimeNeeded >= k_duration_128th_dotted)
611
sElement += _T("o.)");
612
nDuration = k_duration_128th_dotted;
614
else if (nTimeNeeded >= k_duration_128th)
616
sElement += _T("o)");
617
nDuration = k_duration_128th;
621
sElement += _T("f)");
622
nDuration = k_duration_256th;
625
nTimeNeeded -= nDuration;
629
#if (TRACE_COMPOSER == 1)
630
wxLogMessage(_T("[Composer::CreateNoteRest] Needed duration= %d, added=%s"),
631
nNoteRestDuration, sElement.c_str());
565
637
//---------------------------------------------------------------------------------------
566
string Composer::CreateLastMeasure(int nNumMeasure, ETimeSignature nTimeSign,
567
bool fOnlyQuarterNotes)
638
wxString Composer::CreateLastMeasure(int nNumMeasure, ETimeSignature nTimeSign,
639
bool fOnlyQuarterNotes)
569
641
// Returns a final meaure. This final measure has only a note, long enough, and
572
string sMeasure = "";
644
wxString sMeasure = _T("");
573
645
float rMeasureDuration = get_measure_duration_for(nTimeSign);
574
float rBeatDuration = get_beat_duration_for(nTimeSign);
575
float rNoteDuration = rBeatDuration;
576
if (!fOnlyQuarterNotes && rMeasureDuration / rBeatDuration >= 2.0)
646
float rPulseDuration = get_ref_note_duration_for(nTimeSign) *
647
get_num_ref_notes_per_pulse_for(nTimeSign);
648
float rNoteDuration = rPulseDuration;
649
bool fCompound = (get_num_ref_notes_per_pulse_for(nTimeSign) != 1);
650
if (!fOnlyQuarterNotes && rMeasureDuration / rPulseDuration >= 2.0)
578
652
//flip coin to randomly add a one-beat note or a two-beats note
579
653
if (RandomGenerator::flip_coin())
580
rNoteDuration += rBeatDuration;
654
rNoteDuration += rPulseDuration;
583
sMeasure += CreateNote((int)rNoteDuration);
657
sMeasure += CreateNote((int)rNoteDuration, fCompound, true /*final note*/);
584
658
rNoteDuration = rMeasureDuration - rNoteDuration;
585
if (rNoteDuration > 0.0f)
586
sMeasure += CreateRest((int)rNoteDuration);
659
if (rNoteDuration > 0.0f)
660
sMeasure += CreateRest((int)rNoteDuration, fCompound, true /*final rest*/);
588
sMeasure += "(barline end)";
662
sMeasure += _T("(barline end)");
699
773
// on beat note. Pitch must be on chord.
700
774
// Assign a pitch from nChords[iC].
702
//for(int k=0; k < (int)aOnChordPitch.size(); k++)
703
// g_pLogger->LogTrace(_T("Composer::InstantiateNotes"), _T("OnChord %d = %s"), k, aOnChordPitch[k].LDPName().c_str() );
775
#if (TRACE_PITCH == 1)
776
for(int k=0; k < (int)aOnChordPitch.size(); k++)
777
wxLogMessage(_T("[Composer::InstantiateNotes] OnChord %d = %s"), k, aOnChordPitch[k].to_abs_ldp_name().c_str() );
704
779
fpNew = NearestNoteOnChord(aContour[iPt++], pNotePrev, pNoteCur,
707
//for(int k=0; k < (int)aOnChordPitch.size(); k++)
708
// g_pLogger->LogTrace(_T("Composer::InstantiateNotes"), _T("OnChord %d = %s"), k, aOnChordPitch[k].LDPName().c_str() );
709
//wxString sNoteName = fpNew.LDPName();
710
//g_pLogger->LogTrace(_T("Composer::InstantiateNotes"), _T("on-chord note %d. Assigned pitch = %d (%s), chord=%d"),
711
// iPt, fpNew.to_diatonic_pitch(), sNoteName.c_str(),
712
// nChords[iC] & lmGRADE_MASK);
781
#if (TRACE_PITCH == 1)
782
for(int k=0; k < (int)aOnChordPitch.size(); k++)
783
wxLogMessage(_T("[Composer::InstantiateNotes] OnChord %d = %s"), k, aOnChordPitch[k].to_abs_ldp_name().c_str() );
784
string sNoteName = fpNew.to_abs_ldp_name();
785
wxLogMessage(_T("[Composer::InstantiateNotes] on-chord note %d. Assigned pitch = %d (%s), chord=%d"),
786
iPt, int(fpNew.to_diatonic_pitch()), sNoteName.c_str(),
787
nChords[iC] & lmGRADE_MASK);
714
790
set_pitch(pNoteCur, fpNew);
850
925
notes[1] = FPitch( scale[iF+2] );
851
926
notes[2] = FPitch( scale[iF+4] );
854
//g_pLogger->LogTrace(_T("Composer::FunctionToChordNotes"), _T("Function %d, Key=%d, note0 %d (%s), note1 %d (%s), note2 %d (%s)."),
856
// notes[0].to_diatonic_pitch(), notes[0].LDPName().c_str(),
857
// notes[1].to_diatonic_pitch(), notes[1].LDPName().c_str(),
858
// notes[2].to_diatonic_pitch(), notes[2].LDPName().c_str() );
928
// #if (TRACE_COMPOSER == 1)
929
// wxLogMessage(_T("[Composer::FunctionToChordNotes] Function %d, Key=%d, note0 %d (%s), note1 %d (%s), note2 %d (%s)."),
931
// notes[0].to_diatonic_pitch(), notes[0].to_abs_ldp_name().c_str(),
932
// notes[1].to_diatonic_pitch(), notes[1].to_abs_ldp_name().c_str(),
933
// notes[2].to_diatonic_pitch(), notes[2].to_abs_ldp_name().c_str() );
861
937
//---------------------------------------------------------------------------------------
862
938
FPitch Composer::MoveByStep(bool fUpStep, FPitch nPitch, FPitch scale[7])
864
// Generates a LENMUS_NEW note by moving up/down one step in the scale
865
// The LENMUS_NEW pitch must be on the key signature natural scale
940
// Generates a new note by moving up/down one step in the scale
941
// The new pitch must be on the key signature natural scale
867
943
// extract pitch components
868
944
int nStep = nPitch.step();
1745
1839
// Returns the required duration for a measure in the received time signature
1747
float rNumBeats = (float)get_beats_for(nTimeSign);
1748
return rNumBeats * get_beat_duration_for(nTimeSign);
1841
float rNumBeats = (float)get_top_number_for(nTimeSign);
1842
return rNumBeats * get_ref_note_duration_for(nTimeSign);
1751
1845
//---------------------------------------------------------------------------------------
1752
1846
void Composer::set_pitch(ImoNote* pNote, FPitch fp)
1754
EAccidentals acc = fp.notated_accidentals_for(m_nKey);
1755
pNote->set_notated_pitch(fp.step(), fp.octave(), acc);
1756
pNote->set_actual_accidentals(fp.num_accidentals());
1848
int nAccidentals[7];
1849
lomse::get_accidentals_for_key(m_nKey, nAccidentals);
1850
EAccidentals acc = EAccidentals( nAccidentals[fp.step()] );
1851
if (!pNote->is_pitch_defined())
1853
pNote->set_notated_pitch(fp.step(), fp.octave(), k_no_accidentals);
1854
pNote->set_actual_accidentals(acc);
1758
1857
if (pNote->is_tied_next())
1760
1859
ImoTie* pTie = pNote->get_tie_next();
1761
1860
pNote = pTie->get_end_note();
1762
pNote->set_notated_pitch(fp.step(), fp.octave(), acc);
1763
pNote->set_actual_accidentals(fp.num_accidentals());
1861
pNote->set_notated_pitch(fp.step(), fp.octave(), k_no_accidentals);
1862
pNote->set_actual_accidentals(acc);