Skip to content

Commit

Permalink
Merge pull request #26833 from mathesoncalum/450-porting-3
Browse files Browse the repository at this point in the history
Porting PRs to 4.5
  • Loading branch information
RomanPudashkin authored Feb 28, 2025
2 parents ac620c2 + dbeaefa commit 01f6338
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 55 deletions.
4 changes: 3 additions & 1 deletion src/appshell/view/notationpagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ void NotationPageModel::updatePercussionPanelVisibility()
{
TRACEFUNC;

//! NOTE: If the user is entering percussion notes with the piano keyboard, we can assume that they
//! don't want the percussion panel to auto-show...
const muse::dock::IDockWindow* window = dockWindowProvider()->window();
if (!window) {
if (!window || window->isDockOpenAndCurrentInFrame(PIANO_KEYBOARD_PANEL_NAME)) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/engraving/dom/masterscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ class MasterScore : public Score
void reorderMidiMapping();
void rebuildExcerptsMidiMapping();
void removeDeletedMidiMapping();

int updateMidiMapping();
void doUpdateMidiMapping(int& maxport, std::set<int>& occupiedMidiChannels, unsigned int& searchMidiMappingFrom, Part* part,
InstrChannel* channel, bool useDrumset);

friend class EngravingProject;
friend class compat::ScoreAccess;
Expand Down
121 changes: 68 additions & 53 deletions src/engraving/dom/midimapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,17 @@ void MasterScore::reorderMidiMapping()
for (const auto& pair : part->instruments()) {
const Instrument* instr = pair.second;
for (InstrChannel* channel : instr->channel()) {
if (!(m_midiMapping[sequenceNumber].part() == part
&& m_midiMapping[sequenceNumber].m_masterChannel == channel)) {
int shouldBe = channel->channel();
swap(m_midiMapping[sequenceNumber], m_midiMapping[shouldBe]);
m_midiMapping[sequenceNumber].articulation()->setChannel(sequenceNumber);
channel->setChannel(sequenceNumber);
m_midiMapping[shouldBe].articulation()->setChannel(shouldBe);
if (m_midiMapping[sequenceNumber].part() == part && m_midiMapping[sequenceNumber].m_masterChannel == channel) {
sequenceNumber++;
continue;
}

const int shouldBe = channel->channel();
swap(m_midiMapping[sequenceNumber], m_midiMapping[shouldBe]);
m_midiMapping[sequenceNumber].articulation()->setChannel(sequenceNumber);
channel->setChannel(sequenceNumber);
m_midiMapping[shouldBe].articulation()->setChannel(shouldBe);

sequenceNumber++;
}
}
Expand Down Expand Up @@ -256,8 +259,8 @@ void MasterScore::removeDeletedMidiMapping()
int MasterScore::updateMidiMapping()
{
int maxport = 0;
std::set<int> occupiedMidiChannels;// each entry is port*16+channel, port range: 0-inf, channel: 0-15
unsigned int searchMidiMappingFrom = 0; // makes getting next free MIDI mapping faster
std::set<int> occupiedMidiChannels; // each entry is port*16+channel, port range: 0-inf, channel: 0-15
unsigned int searchMidiMappingFrom = 0; // makes getting next free MIDI mapping faster

for (const MidiMapping& mm :m_midiMapping) {
if (mm.port() == -1 || mm.channel() == -1) {
Expand All @@ -272,56 +275,68 @@ int MasterScore::updateMidiMapping()
for (Part* part : parts()) {
for (const auto& pair : part->instruments()) {
const Instrument* instr = pair.second;
bool drum = instr->useDrumset();
const bool useDrumset = instr->useDrumset();
for (InstrChannel* channel : instr->channel()) {
bool channelExists = false;
for (const MidiMapping& mapping: m_midiMapping) {
if (channel == mapping.m_masterChannel && channel->channel() != -1) {
channelExists = true;
break;
}
}
// Channel could already exist, but have unassigned port or channel. Repair and continue
if (channelExists) {
if (m_midiMapping[channel->channel()].port() == -1) {
const int nm
= getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom, -1,
m_midiMapping[channel->channel()].channel());
m_midiMapping[channel->channel()].m_port = nm / 16;
} else if (m_midiMapping[channel->channel()].channel() == -1) {
if (drum) {
m_midiMapping[channel->channel()].m_port = getNextFreeDrumMidiMapping(occupiedMidiChannels) / 16;
m_midiMapping[channel->channel()].m_channel = 9;
continue;
}
int nm = getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom,
m_midiMapping[channel->channel()].port());
m_midiMapping[channel->channel()].m_port = nm / 16;
m_midiMapping[channel->channel()].m_channel = nm % 16;
}
continue;
}
doUpdateMidiMapping(maxport, occupiedMidiChannels, searchMidiMappingFrom, part, channel, useDrumset);
}
}
}

int midiPort;
int midiChannel;
if (drum) {
midiPort = getNextFreeDrumMidiMapping(occupiedMidiChannels) / 16;
midiChannel = 9;
} else {
int nm = getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom);
midiPort = nm / 16;
midiChannel = nm % 16;
}
return maxport;
}

if (midiPort > maxport) {
maxport = midiPort;
}
void MasterScore::doUpdateMidiMapping(int& maxport, std::set<int>& occupiedMidiChannels, unsigned int& searchMidiMappingFrom,
Part* part, InstrChannel* channel, bool useDrumset)
{
bool channelExists = false;
for (const MidiMapping& mapping : m_midiMapping) {
const bool validChannelIndex = channel->channel() >= 0 && channel->channel() < static_cast<int>(m_midiMapping.size());
if (channel == mapping.m_masterChannel && validChannelIndex) {
channelExists = true;
break;
}
}

addMidiMapping(channel, part, midiPort, midiChannel);
}
if (!channelExists) {
int midiPort;
int midiChannel;

if (useDrumset) {
midiPort = getNextFreeDrumMidiMapping(occupiedMidiChannels) / 16;
midiChannel = 9;
} else {
const int nm = getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom);
midiPort = nm / 16;
midiChannel = nm % 16;
}

if (midiPort > maxport) {
maxport = midiPort;
}

addMidiMapping(channel, part, midiPort, midiChannel);
return;
}

// Channel could already exist, but have unassigned port or channel...
MidiMapping& mapping = m_midiMapping.at(channel->channel());

if (mapping.port() == -1) {
const int nm = getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom, -1, mapping.channel());
mapping.m_port = nm / 16;
return;
}

if (m_midiMapping[channel->channel()].channel() == -1) {
if (useDrumset) {
mapping.m_port = getNextFreeDrumMidiMapping(occupiedMidiChannels) / 16;
mapping.m_channel = 9;
return;
}
const int nm = getNextFreeMidiMapping(occupiedMidiChannels, searchMidiMappingFrom, mapping.port());
mapping.m_port = nm / 16;
mapping.m_channel = nm % 16;
}
return maxport;
}

//---------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ bool NotationInteraction::showShadowNote(ShadowNote& shadowNote, ShadowNoteParam

const mu::engraving::InputState& inputState = score()->inputState();
const Staff* staff = score()->staff(position.staffIdx);
const mu::engraving::Instrument* instr = staff->part()->instrument();

mu::engraving::Segment* segment = position.segment;
qreal segmentSkylineTopY = 0;
Expand All @@ -433,6 +432,8 @@ bool NotationInteraction::showShadowNote(ShadowNote& shadowNote, ShadowNoteParam
Fraction tick = segment->tick();
qreal mag = staff->staffMag(tick);

const mu::engraving::Instrument* instr = staff->part()->instrument(tick);

// in any empty measure, pos will be right next to barline
// so pad this by barNoteDistance
qreal relX = position.pos.x() - position.segment->measure()->canvasPos().x();
Expand Down

0 comments on commit 01f6338

Please sign in to comment.