Exemple #1
0
 MappedNote FindMappedNote(MappedNote noteToRemove)
 {
     foreach (MappedNote note in m_mappedNotesList)
     {
         if (note.sourceDeviceName == noteToRemove.sourceDeviceName && note.sourceChannel == noteToRemove.sourceChannel && note.origNote == noteToRemove.origNote &&
             note.mappedDevice.Name == noteToRemove.mappedDevice.Name && note.mappedChannel == noteToRemove.mappedChannel && note.mappedNote == noteToRemove.mappedNote)
         {
             return(note);
         }
     }
     return(null);
 }
Exemple #2
0
 void RemoveMappedNote(MappedNote noteToRemove)
 {
     foreach (MappedNote note in m_mappedNotesList)
     {
         if (note.sourceDeviceName == noteToRemove.sourceDeviceName && note.sourceChannel == noteToRemove.sourceChannel && note.origNote == noteToRemove.origNote &&
             note.mappedDevice.Name == noteToRemove.mappedDevice.Name && note.mappedChannel == noteToRemove.mappedChannel && note.mappedNote == noteToRemove.mappedNote)
         {
             m_mappedNotesList.Remove(note);
             break;
         }
     }
 }
Exemple #3
0
        public void NoteOn(NoteOnMessage msg)
        {
            // Find the per-device/channel mappings for the message's Device/Channel.  If there's none, nothing to do.
            String deviceKey = Mapping.PerDeviceChannelMapping.createKey(msg.Device.Name, (int)msg.Channel);

            if (!m_perDeviceChannelMappings.ContainsKey(deviceKey))
            {
                return;
            }
            Mapping.PerDeviceChannelMapping perDeviceChannelMapping = m_perDeviceChannelMappings[deviceKey];

            // Iterate over the NoteMappings for this device/channel
            foreach (NoteMapping mapping in perDeviceChannelMapping.noteMappings)
            {
                // See if the note received is in range for the NoteMapping currently under consideration
                if (msg.Pitch >= (Pitch)mapping.lowestNote && msg.Pitch <= (Pitch)mapping.highestNote)
                {
                    // It is.
                    // Create mapped note record
                    MappedNote mappedNoteRecord = new MappedNote();
                    mappedNoteRecord.sourceDeviceName = msg.Device.Name;
                    mappedNoteRecord.sourceChannel    = msg.Channel;
                    mappedNoteRecord.origNote         = msg.Pitch;
                    SoundGenerator soundGenerator = mapping.soundGenerator;
                    mappedNoteRecord.mappedDevice  = soundGenerator.device;
                    mappedNoteRecord.mappedChannel = (Channel)mapping.soundGeneratorPhysicalChannel;
                    mappedNoteRecord.mappedNote    = msg.Pitch + mapping.pitchOffset + masterTranspose;

                    if (mappedNoteRecord.mappedNote < 0 || mappedNoteRecord.mappedNote > (Pitch)127)
                    {
                        continue;
                    }

                    // See if this note is already sounding.  Look it up based on it's unmapped device, channel and note#.
                    MappedNote matchingMappedNoteAlreadySounding = FindMappedNote(mappedNoteRecord);
                    if (matchingMappedNoteAlreadySounding != null)
                    {
                        matchingMappedNoteAlreadySounding.mappedDevice.SendNoteOff(matchingMappedNoteAlreadySounding.mappedChannel, matchingMappedNoteAlreadySounding.mappedNote, 127);
                        m_mappedNotesList.Remove(matchingMappedNoteAlreadySounding);
                    }

                    // Now, play the new mapping of the source note.
                    mappedNoteRecord.mappedDevice.SendNoteOn(mappedNoteRecord.mappedChannel, mappedNoteRecord.mappedNote, msg.Velocity);

                    // And add it to the dictionary of sounding notes.
                    m_mappedNotesList.Add(mappedNoteRecord);
                }
            }
        }