MuseScore/libmscore/midimapping.cpp

365 lines
14 KiB
C++
Raw Normal View History

2016-03-11 12:18:46 +01:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "score.h"
#include "excerpt.h"
2016-03-11 12:18:46 +01:00
#include "instrument.h"
#include "part.h"
namespace Ms {
//---------------------------------------------------------
// rebuildMidiMapping
//---------------------------------------------------------
void MasterScore::rebuildMidiMapping()
{
Score* playbackScore = _playbackScore ? _playbackScore : this;
setPlaybackScore(nullptr);
2016-03-11 12:18:46 +01:00
removeDeletedMidiMapping();
int maxport = updateMidiMapping();
reorderMidiMapping();
rebuildExcerptsMidiMapping();
2016-03-11 12:18:46 +01:00
masterScore()->setMidiPortCount(maxport);
setPlaybackScore(playbackScore);
2016-03-11 12:18:46 +01:00
}
//---------------------------------------------------------
// checkMidiMapping
// midi mapping is simple if all ports and channels
// don't decrease and don't have 'holes' except drum tracks
//---------------------------------------------------------
void MasterScore::checkMidiMapping()
{
isSimpleMidiMaping = true;
rebuildMidiMapping();
QList<bool> drum;
drum.reserve(int(_midiMapping.size()));
2016-03-11 12:18:46 +01:00
for (Part* part : parts()) {
const InstrumentList* il = part->instruments();
for (auto i = il->begin(); i != il->end(); ++i) {
const Instrument* instr = i->second;
for (int j = 0; j < instr->channel().size(); ++j)
drum.append(instr->useDrumset());
}
}
int lastChannel = -1; // port*16+channel
int lastDrumPort = -1;
int index = 0;
for (const MidiMapping& m : _midiMapping) {
2016-03-11 12:18:46 +01:00
if (index >= drum.size())
break;
if (drum[index]) {
lastDrumPort++;
if (m.port() != lastDrumPort) {
2016-03-11 12:18:46 +01:00
isSimpleMidiMaping = false;
return;
}
}
else {
lastChannel++;
if (lastChannel % 16 == 9)
lastChannel++;
int p = lastChannel / 16;
int c = lastChannel % 16;
if (m.port() != p || m.channel() != c) {
2016-03-11 12:18:46 +01:00
isSimpleMidiMaping = false;
return;
}
}
index++;
}
}
//---------------------------------------------------------
// getNextFreeMidiMapping
//---------------------------------------------------------
int MasterScore::getNextFreeMidiMapping(int p, int ch)
{
if (ch != -1 && p != -1)
return p*16+ch;
else if (ch != -1 && p == -1) {
for (int port = 0;; port++) {
if (!occupiedMidiChannels.contains(port*16+ch)) {
occupiedMidiChannels.insert(port*16+ch);
return port*16+ch;
}
}
}
else if (ch == -1 && p != -1) {
for (int channel = 0; channel < 16; channel++) {
if (channel != 9 && !occupiedMidiChannels.contains(p*16+channel)) {
occupiedMidiChannels.insert(p*16+channel);
return p*16+channel;
}
}
}
for (;;searchMidiMappingFrom++) {
if (searchMidiMappingFrom % 16 != 9 && !occupiedMidiChannels.contains(searchMidiMappingFrom)) {
occupiedMidiChannels.insert(searchMidiMappingFrom);
return searchMidiMappingFrom;
}
}
}
//---------------------------------------------------------
// getNextFreeDrumMidiMapping
//---------------------------------------------------------
int MasterScore::getNextFreeDrumMidiMapping()
{
for (int i = 0;; i++) {
if (!occupiedMidiChannels.contains(i*16+9)) {
occupiedMidiChannels.insert(i*16+9);
return i*16+9;
}
}
}
//---------------------------------------------------------
// rebuildExcerptsMidiMapping
//---------------------------------------------------------
void MasterScore::rebuildExcerptsMidiMapping()
{
for (Excerpt* ex : excerpts()) {
for (Part* p : ex->partScore()->parts()) {
const Part* masterPart = p->masterPart();
if (!masterPart->score()->isMaster()) {
qWarning("reorderMidiMapping: no part in master score is linked");
continue;
}
Q_ASSERT(p->instruments()->size() == masterPart->instruments()->size());
for (const auto& item : *masterPart->instruments()) {
const Instrument* iMaster = item.second;
const int tick = item.first;
Instrument* iLocal = p->instrument(Fraction::fromTicks(tick));
const int nchannels = iMaster->channel().size();
if (iLocal->channel().size() != nchannels) {
// may happen, e.g., if user changes an instrument
(*iLocal) = (*iMaster);
continue;
}
for (int c = 0; c < nchannels; ++c) {
Channel* cLocal = iLocal->channel(c);
const Channel* cMaster = iMaster->channel(c);
cLocal->setChannel(cMaster->channel());
}
}
}
}
}
2016-03-11 12:18:46 +01:00
//---------------------------------------------------------
// reorderMidiMapping
// Set mappings in order you see in Add->Instruments
//---------------------------------------------------------
void MasterScore::reorderMidiMapping()
{
using std::swap;
2016-03-11 12:18:46 +01:00
int sequenceNumber = 0;
for (Part* part : parts()) {
const InstrumentList* il = part->instruments();
for (auto i = il->begin(); i != il->end(); ++i) {
const Instrument* instr = i->second;
for (Channel* channel : instr->channel()) {
if (!(_midiMapping[sequenceNumber].part() == part
&& _midiMapping[sequenceNumber].masterChannel == channel)) {
fix #275313: rework mixer ui 2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. fix #275313: rework-mixer-ui-2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. Restoring the volume, pan, chorus, reverb to original char data type & range. UI now shows different 'user friendly' ranges. Overwriting tests with versions from master. mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Restoring test files to original state. Restoring test files to original state. Restoring old values for importing files. Restoring part methods. mtest/importmidi/simplify_8th_dotted_no_staccato.mscx mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Rearranging UI components for better feel. Improving UI. Fixed crash when changing part name. Adding support for two lighting modes. Showing part name over channel expansion. Adding master gain control to mixer. Changing color of gain slider. Adapting to latest source in main. Changing master gain slider to use decibel calculation. CSS now set on tracks whenever a Paint event received. Restoring mixer slider values to refect MIDI ranges. Fixing crash when drumkit checked. Fixing crash when closing score. Fixing alignment in mixer details. Tweaking UI for better appearance.
2018-11-13 18:43:19 +01:00
int shouldBe = channel->channel();
swap(_midiMapping[sequenceNumber], _midiMapping[shouldBe]);
_midiMapping[sequenceNumber].articulation()->setChannel(sequenceNumber);
fix #275313: rework mixer ui 2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. fix #275313: rework-mixer-ui-2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. Restoring the volume, pan, chorus, reverb to original char data type & range. UI now shows different 'user friendly' ranges. Overwriting tests with versions from master. mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Restoring test files to original state. Restoring test files to original state. Restoring old values for importing files. Restoring part methods. mtest/importmidi/simplify_8th_dotted_no_staccato.mscx mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Rearranging UI components for better feel. Improving UI. Fixed crash when changing part name. Adding support for two lighting modes. Showing part name over channel expansion. Adding master gain control to mixer. Changing color of gain slider. Adapting to latest source in main. Changing master gain slider to use decibel calculation. CSS now set on tracks whenever a Paint event received. Restoring mixer slider values to refect MIDI ranges. Fixing crash when drumkit checked. Fixing crash when closing score. Fixing alignment in mixer details. Tweaking UI for better appearance.
2018-11-13 18:43:19 +01:00
channel->setChannel(sequenceNumber);
_midiMapping[shouldBe].articulation()->setChannel(shouldBe);
2016-03-11 12:18:46 +01:00
}
sequenceNumber++;
}
}
}
}
//---------------------------------------------------------
// removeDeletedMidiMapping
// Remove mappings to deleted instruments
//---------------------------------------------------------
void MasterScore::removeDeletedMidiMapping()
{
int removeOffset = 0;
int mappingSize = int(_midiMapping.size());
2016-03-11 12:18:46 +01:00
for (int index = 0; index < mappingSize; index++) {
Part* p = midiMapping(index)->part();
2016-03-11 12:18:46 +01:00
if (!parts().contains(p)) {
removeOffset++;
continue;
}
// Not all channels could exist
bool channelExists = false;
const InstrumentList* il = p->instruments();
for (auto i = il->begin(); i != il->end() && !channelExists; ++i) {
const Instrument* instr = i->second;
channelExists = (_midiMapping[index].articulation()->channel() != -1
&& instr->channel().contains(_midiMapping[index].masterChannel)
&& !(_midiMapping[index].port() == -1 && _midiMapping[index].channel() == -1));
2016-03-11 12:18:46 +01:00
if (channelExists)
break;
}
if (!channelExists) {
removeOffset++;
continue;
}
// Let's do a left shift by 'removeOffset' items if necessary
if (index != 0 && removeOffset != 0) {
_midiMapping[index-removeOffset] = std::move(_midiMapping[index]);
fix #275313: rework mixer ui 2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. fix #275313: rework-mixer-ui-2 Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Moving PartEditBase into separate file. Creating new files for building mixer. Creating art assets/UI design for new components. Styling the track control. Adding track area. Separating out score from update. Creating instances of mixer UI. Creating part per voice now. Can click on tracks to select them now. Can now switch bwtewwn tracks. Setting patch channel now. Setting enabled off when no track selected. Improving slider ui. Turning Channel into a class and adding listener to it. Somewhat stabalized sharing track objects between interfaces. Can now apply volume changes to both expanded and collapsed tracks. Pan knob is now working. Encapsulating the rest of the fields in Channel. Mute and solo now working. Reverb and chorus now working. Drumkit checkbox now working. Port and channel somewhat working. Adding support for colors per track. Part name change now working. Separating out MixerTrackItem Finishing moving MixerTrackItem to new file. Cleaning up code. Setting color in collapsed mode now affects all channels. Using shared_ptr to track MixerTrackItem. Part changes now affect all instruments. Creating new track UI object to handle parts. Using shard_ptr to track MixerTrackItem objects. setting port and channel data now. Changing to horizontal layout. Fixing knob display. Chaning track control appearance. Setting init slider window size. Switchong back to vertical orientation. Fixing a few UI bugs in the slider. Tracks now left aligned. Moving details panel above mixer. Now changing track selection when user clicks on sliders. Pan and volume controls now reflect track color. Showing volume and pan values in tooltips. Creating a new slider control for mixer. Switching Channel's volume, pan, reverb and chorus and chaning them to doubles with a decimal range. No longer writing out vol, pan, chor, reverb when at default values. Nolonger writing vol, pan, chorus, reverb as controler values in output file. Now testing against default values on write. More export fixes. Manually editing test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. Manually editing more test files to reflect new channel parameters. More test changes to make Travis happy. More test changes to make Travis happy. Importing MusicXML now matches new volume, pan ranges. Changing range of pan. Fixing a few bugs with calculating MIDI. Altering test files for Travis. Restoring the volume, pan, chorus, reverb to original char data type & range. UI now shows different 'user friendly' ranges. Overwriting tests with versions from master. mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Restoring test files to original state. Restoring test files to original state. Restoring old values for importing files. Restoring part methods. mtest/importmidi/simplify_8th_dotted_no_staccato.mscx mtest/libmscore/compat114/clef_missing_first-ref.mscx mtest/libmscore/compat114/hor_frame_and_mmrest-ref.mscx mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml mtest/musicxml/io/testUninitializedDivisions_ref.xml Rearranging UI components for better feel. Improving UI. Fixed crash when changing part name. Adding support for two lighting modes. Showing part name over channel expansion. Adding master gain control to mixer. Changing color of gain slider. Adapting to latest source in main. Changing master gain slider to use decibel calculation. CSS now set on tracks whenever a Paint event received. Restoring mixer slider values to refect MIDI ranges. Fixing crash when drumkit checked. Fixing crash when closing score. Fixing alignment in mixer details. Tweaking UI for better appearance.
2018-11-13 18:43:19 +01:00
const int chanVal = _midiMapping[index-removeOffset].articulation()->channel();
_midiMapping[index-removeOffset].articulation()->setChannel(chanVal - removeOffset);
2016-03-11 12:18:46 +01:00
}
}
// We have 'removeOffset' deleted instruments, let's remove their mappings
for (int index = 0; index < removeOffset; index++)
_midiMapping.pop_back();
2016-03-11 12:18:46 +01:00
}
//---------------------------------------------------------
// updateMidiMapping
// Add mappings to new instruments and repair existing ones
//---------------------------------------------------------
int MasterScore::updateMidiMapping()
{
int maxport = 0;
occupiedMidiChannels.clear();
searchMidiMappingFrom = 0;
occupiedMidiChannels.reserve(int(_midiMapping.size())); // Bringing down the complexity of insertion to amortized O(1)
2016-03-11 12:18:46 +01:00
for (const MidiMapping& mm :_midiMapping) {
if (mm.port() == -1 || mm.channel() == -1)
2016-03-11 12:18:46 +01:00
continue;
occupiedMidiChannels.insert((int)(mm.port())*16+(int)mm.channel());
if (maxport < mm.port())
maxport = mm.port();
2016-03-11 12:18:46 +01:00
}
for (Part* part : parts()) {
const InstrumentList* il = part->instruments();
for (auto i = il->begin(); i != il->end(); ++i) {
const Instrument* instr = i->second;
bool drum = instr->useDrumset();
for (Channel* channel : instr->channel()) {
bool channelExists = false;
for (const MidiMapping& mapping: _midiMapping) {
if (channel == mapping.masterChannel && channel->channel() != -1) {
2016-03-11 12:18:46 +01:00
channelExists = true;
break;
}
}
// Channel could already exist, but have unassigned port or channel. Repair and continue
if (channelExists) {
if (_midiMapping[channel->channel()].port() == -1) {
const int nm = getNextFreeMidiMapping(-1, _midiMapping[channel->channel()].channel());
_midiMapping[channel->channel()]._port = nm / 16;
2016-03-11 12:18:46 +01:00
}
else if (_midiMapping[channel->channel()].channel() == -1) {
2016-03-11 12:18:46 +01:00
if (drum) {
_midiMapping[channel->channel()]._port = getNextFreeDrumMidiMapping() / 16;
_midiMapping[channel->channel()]._channel = 9;
2016-03-11 12:18:46 +01:00
continue;
}
int nm = getNextFreeMidiMapping(_midiMapping[channel->channel()].port());
_midiMapping[channel->channel()]._port = nm / 16;
_midiMapping[channel->channel()]._channel = nm % 16;
2016-03-11 12:18:46 +01:00
}
continue;
}
int midiPort;
int midiChannel;
2016-03-11 12:18:46 +01:00
if (drum) {
midiPort = getNextFreeDrumMidiMapping() / 16;
midiChannel = 9;
2016-03-11 12:18:46 +01:00
}
else {
int nm = getNextFreeMidiMapping();
midiPort = nm / 16;
midiChannel = nm % 16;
2016-03-11 12:18:46 +01:00
}
if (midiPort > maxport)
maxport = midiPort;
2016-03-11 12:18:46 +01:00
addMidiMapping(channel, part, midiPort, midiChannel);
2016-03-11 12:18:46 +01:00
}
}
}
return maxport;
}
//---------------------------------------------------------
// addMidiMapping
//---------------------------------------------------------
void MasterScore::addMidiMapping(Channel* channel, Part* part, int midiPort, int midiChannel)
{
if (!part->score()->isMaster())
return;
MidiMapping mm;
mm._part = part;
mm.masterChannel = channel;
mm._articulation.reset(new Channel(*channel));
mm.link = PartChannelSettingsLink(mm.articulation(), mm.masterChannel, /* excerpt */ false);
mm._port = midiPort;
mm._channel = midiChannel;
const int mscoreChannel = int(_midiMapping.size());
mm._articulation->setChannel(mscoreChannel);
mm.masterChannel->setChannel(mscoreChannel);
_midiMapping.push_back(std::move(mm));
}
//---------------------------------------------------------
// updateMidiMapping
//---------------------------------------------------------
void MasterScore::updateMidiMapping(Channel* channel, Part* part, int midiPort, int midiChannel)
{
const int c = channel->channel();
if (c < 0)
return;
if (c >= int(masterScore()->midiMapping().size())) {
qDebug("Can't set midi channel: midiMapping is empty!");
return;
}
MidiMapping& mm = _midiMapping[c];
if (midiChannel != -1)
mm._channel = midiChannel;
if (midiPort != -1)
mm._port = midiPort;
if (part)
mm._part = part->masterPart();
}
2016-03-11 12:18:46 +01:00
} // namespace Ms