예제 #1
0
        private string ProcessText(string oldValue, EventRuleArgs args)
        {
            string processed = OutValue.Replace(existingValue, oldValue);

            processed = processed.Replace(fileName, args.OutFileName);
            return(processed);
        }
예제 #2
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool match = false;

            if ((inEvent.CommandCode == MidiCommandCode.ChannelAfterTouch) &&
                (type == AfterTouchType.Channel))
            {
                if (inChannels.IsValueIncluded(inEvent.Channel))
                {
                    ChannelAfterTouchEvent afterTouchEvent = (ChannelAfterTouchEvent)inEvent;
                    afterTouchEvent.Channel            = outChannel.ProcessValue(inEvent.Channel);
                    afterTouchEvent.AfterTouchPressure = outValue.ProcessValue(afterTouchEvent.AfterTouchPressure);
                    match = true;
                }
            }
            else if ((inEvent.CommandCode == MidiCommandCode.KeyAfterTouch) && (type == AfterTouchType.Key))
            {
                if (inChannels.IsValueIncluded(inEvent.Channel))
                {
                    NoteEvent afterTouchEvent = (NoteEvent)inEvent;
                    afterTouchEvent.Channel  = outChannel.ProcessValue(inEvent.Channel);
                    afterTouchEvent.Velocity = outValue.ProcessValue(afterTouchEvent.Velocity);
                    match = true;
                }
            }

            return(match);
        }
예제 #3
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool match = false;

            TextEvent textEvent = inEvent as TextEvent;

            if (textEvent != null && textEvent.MetaEventType == EventType)
            {
                switch (MatchType)
                {
                case TextMatchType.ExactMatch:
                    match = (textEvent.Text == InValue);
                    break;

                case TextMatchType.Substring:
                    match = textEvent.Text.Contains(InValue);
                    break;

                case TextMatchType.Regex:
                    match = inRegex.Match(textEvent.Text).Success;
                    break;
                }
            }
            if (match)
            {
                textEvent.Text = ProcessText(textEvent.Text, args);
            }
            return(match);
        }
예제 #4
0
        public bool ConvertFile(string sourceFile, string destFile, int fileType)
        {
            MidiFile midiFile = new MidiFile(sourceFile, false);

            if (fileType == -1)
            {
                fileType = midiFile.FileFormat;
            }
            EventRuleArgs eventRuleArgs = new EventRuleArgs(Path.GetFileNameWithoutExtension(sourceFile));

            MidiEventCollection outputFileEvents = new MidiEventCollection(fileType, midiFile.DeltaTicksPerQuarterNote);
            bool hasNotes = false;

            for (int track = 0; track < midiFile.Tracks; track++)
            {
                IList <MidiEvent> trackEvents = midiFile.Events[track];
                IList <MidiEvent> outputEvents;
                if (fileType == 1 || track == 0)
                {
                    outputEvents = new List <MidiEvent>();
                }
                else
                {
                    outputEvents = outputFileEvents[0];
                }
                foreach (MidiEvent midiEvent in InsertEvents)
                {
                    outputEvents.Add(midiEvent);
                }
                foreach (MidiEvent midiEvent in trackEvents)
                {
                    if (Process(midiEvent, eventRuleArgs))
                    {
                        outputEvents.Add(midiEvent);
                        NoteOnEvent noteOnEvent = midiEvent as NoteOnEvent;
                        if (noteOnEvent != null)
                        {
                            System.Diagnostics.Debug.Assert(noteOnEvent.OffEvent != null);
                            hasNotes = true;
                            outputEvents.Add(noteOnEvent.OffEvent);
                        }
                    }
                }
                if (fileType == 1 || track == 0)
                {
                    outputFileEvents.AddTrack(outputEvents);
                }
            }
            if (hasNotes)
            {
                MidiFile.Export(destFile, outputFileEvents);
            }

            return(hasNotes);
        }
예제 #5
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool match = false;

            if (inEvent.CommandCode == MidiCommandCode.PitchWheelChange)
            {
                PitchWheelChangeEvent pitchWheelEvent = (PitchWheelChangeEvent)inEvent;
                if (inChannels.IsValueIncluded(pitchWheelEvent.Channel))
                {
                    pitchWheelEvent.Pitch   = outValue.ProcessValue(pitchWheelEvent.Pitch);
                    pitchWheelEvent.Channel = outChannel.ProcessValue(pitchWheelEvent.Channel);
                    match = true;
                }
            }
            return(match);
        }
예제 #6
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool match = false;

            if (inEvent.CommandCode == MidiCommandCode.ControlChange)
            {
                ControlChangeEvent controlEvent = (ControlChangeEvent)inEvent;
                if (inControllers.IsValueIncluded((int)controlEvent.Controller) &&
                    inChannels.IsValueIncluded(controlEvent.Channel) &&
                    inValues.IsValueIncluded(controlEvent.ControllerValue))
                {
                    controlEvent.ControllerValue = outValue.ProcessValue(controlEvent.ControllerValue);
                    controlEvent.Controller      = (MidiController)outController.ProcessValue((int)controlEvent.Controller);
                    controlEvent.Channel         = outChannel.ProcessValue(controlEvent.Channel);
                    match = true;
                }
            }
            return(match);
        }
예제 #7
0
        public bool Process(MidiEvent inEvent, EventRuleArgs args)
        {
            NoteOnEvent noteEvent = inEvent as NoteOnEvent;

            // filter note offs - they will be added by their note-on
            if (MidiEvent.IsNoteOff(inEvent))
            {
                return(false);
            }

            // if it is a note event, special processing
            if (noteEvent != null)
            {
                foreach (IEventRule rule in noteRules)
                {
                    if (rule.Apply(inEvent, args))
                    {
                        return(true);
                    }
                }
                // an unmatched note event
                // TODO: configure to have an option to retain these
                return(false);
            }

            // now see if we need to exclude this event
            foreach (IEventRule rule in excludeRules)
            {
                if (rule.Apply(inEvent, args))
                {
                    return(false);
                }
            }

            bool updatedEvent = false;

            foreach (IEventRule rule in eventRules)
            {
                updatedEvent |= rule.Apply(inEvent, args);
            }
            return(true); // updatedEvent;
        }
예제 #8
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool        match       = false;
            NoteOnEvent noteOnEvent = inEvent as NoteOnEvent;

            if (noteOnEvent != null && noteOnEvent.Velocity > 0)
            {
                if (inChannels.IsValueIncluded(inEvent.Channel) &&
                    inNotes.IsValueIncluded(noteOnEvent.NoteNumber) &&
                    inVelocity.IsValueIncluded(noteOnEvent.Velocity)
                    )
                {
                    noteOnEvent.Channel    = outChannel.ProcessValue(noteOnEvent.Channel);
                    noteOnEvent.Velocity   = outVelocity.ProcessValue(noteOnEvent.Velocity);
                    noteOnEvent.NoteNumber = outNote.ProcessValue(noteOnEvent.NoteNumber);
                    //noteOnEvent.AbsoluteTime = outStartTime.ProcessValue(noteOnEvent.AbsoluteTime);
                    noteOnEvent.NoteLength = outDuration.ProcessValue(noteOnEvent.NoteLength);
                    match = true;
                }
            }

            return(match);
        }
예제 #9
0
        public bool Apply(MidiEvent inEvent, EventRuleArgs args)
        {
            bool      exclude   = false;
            MetaEvent metaEvent = inEvent as MetaEvent;

            switch (eventType)
            {
            case ExcludeEventType.Controller:
                exclude = inEvent.CommandCode == MidiCommandCode.ControlChange;
                break;

            case ExcludeEventType.PitchWheel:
                exclude = inEvent.CommandCode == MidiCommandCode.PitchWheelChange;
                break;

            case ExcludeEventType.PatchChange:
                exclude = inEvent.CommandCode == MidiCommandCode.PatchChange;
                break;

            case ExcludeEventType.ChannelAfterTouch:
                exclude = inEvent.CommandCode == MidiCommandCode.ChannelAfterTouch;
                break;

            case ExcludeEventType.KeyAfterTouch:
                exclude = inEvent.CommandCode == MidiCommandCode.KeyAfterTouch;
                break;

            case ExcludeEventType.Sysex:
                exclude = inEvent.CommandCode == MidiCommandCode.Sysex;
                break;

            case ExcludeEventType.ContinueSequence:
                exclude = inEvent.CommandCode == MidiCommandCode.ContinueSequence;
                break;

            case ExcludeEventType.StopSequence:
                exclude = inEvent.CommandCode == MidiCommandCode.StopSequence;
                break;

            case ExcludeEventType.StartSequence:
                exclude = inEvent.CommandCode == MidiCommandCode.StartSequence;
                break;

            case ExcludeEventType.TimingClock:
                exclude = inEvent.CommandCode == MidiCommandCode.TimingClock;
                break;

            case ExcludeEventType.Copyright:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.Copyright);
                break;

            case ExcludeEventType.Text:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.TextEvent);
                break;

            case ExcludeEventType.Marker:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.Marker);
                break;

            case ExcludeEventType.SequencerSpecific:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.SequencerSpecific);
                break;

            case ExcludeEventType.SmpteOffset:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.SmpteOffset);
                break;

            case ExcludeEventType.CuePoint:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.CuePoint);
                break;

            case ExcludeEventType.Lyric:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.Lyric);
                break;

            case ExcludeEventType.DeviceName:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.DeviceName);
                break;

            case ExcludeEventType.ProgramName:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.ProgramName);
                break;

            case ExcludeEventType.TrackInstrumentName:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.TrackInstrumentName);
                break;

            case ExcludeEventType.TrackName:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.SequenceTrackName);
                break;

            case ExcludeEventType.TrackSequenceNumber:
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.TrackSequenceNumber);
                break;

            case ExcludeEventType.KeySignature:
                // undocumented feature - key signature can be removed (not recommended)
                exclude = (metaEvent != null) && (metaEvent.MetaEventType == MetaEventType.KeySignature);
                break;

            case ExcludeEventType.NonStandard:
                if (metaEvent != null)
                {
                    exclude = !Enum.IsDefined(typeof(MetaEventType), metaEvent.MetaEventType);
                }
                else
                {
                    exclude = !Enum.IsDefined(typeof(MidiCommandCode), inEvent.CommandCode);
                }
                break;

            case ExcludeEventType.All:
                // End track and notes already excluded
                if (metaEvent != null)
                {
                    if ((metaEvent.MetaEventType != MetaEventType.SetTempo) &&
                        (metaEvent.MetaEventType != MetaEventType.KeySignature) &&
                        (metaEvent.MetaEventType != MetaEventType.TimeSignature))
                    {
                    }
                    else
                    {
                        exclude = true;
                    }
                }
                else
                {
                    exclude = true;
                }
                // TODO: support exclude all
                break;
            }
            if (exclude && metaEvent == null)
            {
                exclude = inChannels.IsValueIncluded(inEvent.Channel);
            }
            return(exclude);
        }