Skip to content

Commit

Permalink
add instr support for MIDI param
Browse files Browse the repository at this point in the history
  • Loading branch information
dfober committed Sep 5, 2024
1 parent 29b93a1 commit 73e54a4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/engine/abstract/ARInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "ARInstrument.h"
#include "TagParameterStrings.h"
#include "TagParameterString.h"
#include "TagParameterInt.h"
#include "TimeUnwrap.h"

using namespace std;

Expand All @@ -36,6 +38,12 @@ void ARInstrument::setTagParameters (const TagParameterMap& params)
if (autopos)
fAutoPos = getParameter<TagParameterString>(kAutoposStr, true)->getBool();
fRepeat = getParameter<TagParameterString>(kRepeatStr, true)->getBool();
fMidiInstr = getParameter<TagParameterInt>(kMIDIInstrStr, true)->getValue();
}

void ARInstrument::browse(TimeUnwrap& mapper) const
{
mapper.AtPos (this, TimeUnwrap::kInstr);
}


6 changes: 6 additions & 0 deletions src/engine/abstract/ARInstrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
@param:name:string:the instrument name:*none*:false
@param:transp:string:a transposition string:*none*:true
@param:autopos:boolean:automatic position control:off:true
@param:repeat:boolean:allows to display on each system:off:true
@param:MIDI:int:MIDI instrument number:-1:true
@fontparams:
@paramdesc
- **name** is the instrument name (e.g. "Violin I")
- **transp** is provided for transposing instruments. For example, with a Trumpet in B flat, you should set **transp** to "B&". When *transp* is set, a transposing key is automatically inserted and the notes are automatically transposed to the corresponding interval.
- **autopos**: when "on", put the instrument string centered to the left of the corresponding staff. The default position if on top, left of the staff.
- **repeat**: when "on", the instrument string is repeated on each system.
See the [Articulations](@EXAMPLES/articulations/) example.<br />
See the [Mozart](@EXAMPLES/mozart581/) example.<br />
Expand All @@ -63,17 +66,20 @@ class ARInstrument : public ARFontAble
virtual const char* getTagName() const { return "ARInstrument"; };
virtual std::string getGMNName() const { return "\\instrument"; };
virtual bool IsStateTag() const { return true; }
virtual void browse(TimeUnwrap& mapper) const;

const std::string& getName() const { return fName; }
const std::string& getTransp() const { return fTransp; }
bool autoPos() const { return fAutoPos; }
bool repeat() const { return fRepeat; }
int midi() const { return fMidiInstr; }

private:
std::string fName;
std::string fTransp;
bool fAutoPos;
bool fRepeat = false; // to display the instrument every new system
int fMidiInstr = -1;
};

#endif
3 changes: 2 additions & 1 deletion src/engine/abstract/TagParameterStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const char* kARFooterParams = "S,text,,r;S,pageformat,c6,o;S,font,Times,o;U,fsi
const char* kARGlissandoParams = "U,dx1,0,o;U,dy1,0,o;U,dx2,0,o;U,dy2,0,o;S,fill,false,o;U,thickness,0.3,o";
const char* kARGraceParams = "I,i,,o";
const char* kARHarmonyParams = "S,text,,r;U,dy,-1,o;S,textformat,lt,o;S,font,Arial,o;U,fsize,18pt,o";
const char* kARInstrumentParams = "S,name,,r;S,transp,,o;S,autopos,off,o;S,repeat,off,o";
const char* kARInstrumentParams = "S,name,,r;S,transp,,o;S,autopos,off,o;S,repeat,off,o;I,MIDI,-1,o";
const char* kARIntensParams = "S,type,,r;S,before,,o;S,after,,o;S,font,Times,o;U,fsize,10pt,o;S,fattrib,i,o;S,autopos,off,o";
const char* kARJumpParams = "S,m,,o;I,id,0,o";
const char* kARKeyParams = "S,key,,r;S,hideNaturals,false,o;S,free,,o";
Expand Down Expand Up @@ -156,6 +156,7 @@ const char* kLineThicknesStr= "lineThickness";
const char* kLmStr = "lm";
const char* kMarkStr = "mark";
const char* kMeasNumStr = "measNum";
const char* kMIDIInstrStr = "MIDI";
const char* kModeStr = "mode";
const char* kMStr = "m";
const char* kNameStr = "name";
Expand Down
1 change: 1 addition & 0 deletions src/engine/abstract/TagParameterStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ extern const char* kLineThicknesStr;
extern const char* kLmStr;
extern const char* kMarkStr;
extern const char* kMeasNumStr;
extern const char* kMIDIInstrStr;
extern const char* kModeStr;
extern const char* kMStr;
extern const char* kNameStr;
Expand Down
16 changes: 16 additions & 0 deletions src/engine/lib/MIDIMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ARMusicalVoiceState.h"
#include "ARNote.h"
#include "ARIntens.h"
#include "ARInstrument.h"
#include "ARTempo.h"
#include "ARTie.h"

Expand Down Expand Up @@ -99,6 +100,19 @@ void MidiMapper::IntensChge(const ARMusicalObject * ev)
}
}

//------------------------------------------------------------------------------
void MidiMapper::Instr(const ARMusicalObject * ev)
{
const ARInstrument* instr = dynamic_cast<const ARInstrument*>(ev);
if (instr && instr->midi() >= 0) {
MidiEvPtr pc = fMidi->NewEv(typeProgChange);
Date(pc) = Ticks (fUPosition);
Data(pc)[0] = instr->midi();
Chan(pc) = fChan;
fMidi->AddSeq (fSeq, pc);
}
}

//------------------------------------------------------------------------------
void MidiMapper::Event(const ARMusicalObject * ev, EventType type)
{
Expand All @@ -124,6 +138,8 @@ void MidiMapper::Event(const ARMusicalObject * ev, EventType type)
break;
case kNoTie: fTiedNotes.clear();
break;
case kInstr: Instr(ev);
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/engine/lib/MIDIMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MidiMapper : public TimeUnwrap
void TempoChge (const ARMusicalObject * ev);
void IntensChge (const ARMusicalObject * ev);
void TiedNote (MidiEvPtr note);
void Instr (const ARMusicalObject * ev);

protected:
virtual void Event (const ARMusicalObject * ev, EventType type);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/lib/TimeUnwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TimeUnwrap
kDaCapo, kDaCapoAlFine, kDaCoda,
kDalSegno, kDalSegnoAlFine, kVolta, kTempo,
kFermata, kAccent, kSlur, kStaccato, kTenuto,
kMarcato, kIntens, kTie, kGlissando, kChordComma, kNoTie } EventType;
kMarcato, kIntens, kTie, kGlissando, kChordComma, kNoTie, kInstr } EventType;

TimeUnwrap(ARMusicalVoice* voice) : fVoice(voice),
fStartPos(0), fFinePos(0), fCodaPos(0),
Expand Down

0 comments on commit 73e54a4

Please sign in to comment.