Exemplo n.º 1
0
        /*
         * private static string[] gsInstName = new string[]
         * {
         *  "Piano 1",
         *  "Piano 2",
         *  "Piano 3",
         *  "Honky-tonk",
         *  "E.Piano 1",
         *  "E.Piano 2",
         *  "Harpsichord",
         *  "Clav.",
         *  "Celesta",
         *  "Glockenspiel",
         *  "Music Box",
         *  "Vibraphone",
         *  "Marimba",
         *  "Xylophone",
         *  "Tubular-bell",
         *  "Santur",
         *  "Organ 1",
         *  "Organ 2",
         *  "Organ 3",
         *  "Church Org.1",
         *  "Reed Organ",
         *  "Accordion Fr",
         *  "Harmonica",
         *  "Bandneon",
         *  "Nylon-str.Gt",
         *  "Steel-str.Gt",
         *  "Jazz Gt.",
         *  "Clean Gt.",
         *  "Muted Gt.",
         *  "Overdrive Gt",
         *  "DistortionGt",
         *  "Gt.Harmonics",
         *  "Acoustic Bs.",
         *  "Fingered Bs.",
         *  "Picked Bs.",
         *  "Fretless Bs.",
         *  "Slap Bass 1",
         *  "Slap Bass 2",
         *  "Synth Bass 1",
         *  "Synth Bass 2",
         *  "Violin",
         *  "Viola",
         *  "Cello",
         *  "Contrabass",
         *  "Tremolo Str",
         *  "PizzicatoStr",
         *  "Harp",
         *  "Timpani",
         *  "Strings",
         *  "Slow Strings",
         *  "Syn.Strings1",
         *  "Syn.Strings2",
         *  "Choir Aahs",
         *  "Voice Oohs",
         *  "SynVox",
         *  "OrchestraHit",
         *  "Trumpet",
         *  "Trombone",
         *  "Tuba",
         *  "MutedTrumpet",
         *  "French Horn",
         *  "Brass 1",
         *  "Synth Brass1",
         *  "Synth Brass2",
         *  "Soprano Sax",
         *  "Alto Sax",
         *  "Tenor Sax",
         *  "Baritone Sax",
         *  "Oboe",
         *  "English Horn",
         *  "Bassoon",
         *  "Clarinet",
         *  "Piccolo",
         *  "Flute",
         *  "Recorder",
         *  "Pan Flute",
         *  "Bottle Blow",
         *  "Shakuhachi",
         *  "Whistle",
         *  "Ocarina",
         *  "Square Wave",
         *  "Saw Wave",
         *  "Syn.Calliope",
         *  "Chiffer Lead",
         *  "Charang",
         *  "Solo Vox",
         *  "5th Saw Wave",
         *  "Bass & Lead",
         *  "Fantasia",
         *  "Warm Pad",
         *  "Polysynth",
         *  "Space Voice",
         *  "Bowed Glass",
         *  "Metal Pad",
         *  "Halo Pad",
         *  "Sweep Pad",
         *  "Ice Rain",
         *  "Soundtrack",
         *  "Crystal",
         *  "Atmosphere",
         *  "Brightness",
         *  "Goblin",
         *  "Echo Drops",
         *  "Star Theme",
         *  "Sitar",
         *  "Banjo",
         *  "Shamisen",
         *  "Koto",
         *  "Kalimba",
         *  "Bag Pipe",
         *  "Fiddle",
         *  "Shanai",
         *  "Tinkle Bell",
         *  "Agogo",
         *  "Steel Drums",
         *  "Woodblock",
         *  "Taiko",
         *  "Melo. Tom 1",
         *  "Synth Drum",
         *  "Reverse Cym.",
         *  "Gt.FretNoise",
         *  "Breath Noise",
         *  "Seashore",
         *  "Bird",
         *  "Telephone 1",
         *  "Helicopter",
         *  "Applause",
         *  "Gun Shot"
         * };
         *
         * private static object[] drumNames = new object[]
         * {
         *  "Acou BD", 35,
         *  "Bass Drum", 36,
         *  "Rim Shot", 37,
         *  "Acou SD", 38,
         *  "Hand Clap", 39,
         *  "Elec SD", 40,
         *  "AcouLowTom", 41,
         *  "Clsd HiHat", 42,
         *  "HighFloorTom", 43,
         *  "OpenHiHat2", 44,
         *  "AcouMidTom", 45,
         *  "OpenHiHat1", 46,
         *  "LowMidTom", 47,
         *  "Acou HiTom", 48,
         *  "Crash Sym", 49,
         *  "HiTom", 50,
         *  "Ride sym", 51,
         *  "Chinese Sym", 52,
         *  "Ride Bell", 53,
         *  "Tambourine", 54,
         *  "Splash Sym", 55,
         *  "Cowbell", 56,
         *  "Crash Sym2", 57,
         *  "Vibraslap", 58,
         *  "Ride sym2", 59,
         *  "High Bongo", 60,
         *  "Low Bongo", 61,
         *  "Mt HiConga", 62,
         *  "High Conga", 63,
         *  "Low Conga", 64,
         *  "Hi Timbale", 65,
         *  "LowTimbale", 66,
         *  "High Agogo", 67,
         *  "Low Agogo", 68,
         *  "Cabasa", 69,
         *  "Maracas", 70,
         *  "SmbaWhis S", 71,
         *  "SmbaWhis L", 72,
         *  "ShortQuijada", 73,
         *  "LongQuijada", 74,
         *  "Claves", 75,
         *  "HWoodBlock", 76,
         *  "LWoodBlock", 77,
         *  "Close Cuica", 78,
         *  "Open Cuica", 79,
         * };
         */

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="midiEvent"></param>
        private static void MidiManager_MidiEventReceivedB(object sender, MidiEvent e)
        {
            if (e is ActiveSensingEvent)
            {
                return;
            }

            try
            {
                //InstrumentManager.ExclusiveLockObject.EnterUpgradeableReadLock();

                FormMain.OutputDebugLog(null, "B: " + e.ToString());

                ProcessSysEx(MidiPort.PortB, e);

                //lock (ExclusiveLockObject)
                ProcessCC(MidiPort.PortB, e);

                foreach (var i in instruments)
                {
                    i.ForEach((dev) =>
                    {
                        if (dev.MidiPort == Midi.MidiPort.PortAB ||
                            dev.MidiPort == Midi.MidiPort.PortB)
                        {
                            dev.NotifyMidiEvent(e);
                        }
                    });
                }
            }
            finally
            {
                //InstrumentManager.ExclusiveLockObject.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 2
0
    private string ToMBT(long eventTime, int ticksPerQuarterNote, NAudio.Midi.TimeSignatureEvent timeSignature)
    {
        int   beatsPerBar  = timeSignature == null ? 4 : timeSignature.Numerator;
        int   ticksPerBar  = timeSignature == null ? ticksPerQuarterNote * 4 : (timeSignature.Numerator * ticksPerQuarterNote * 4) / (1 << timeSignature.Denominator);
        int   ticksPerBeat = ticksPerBar / beatsPerBar;
        long  bar          = (eventTime / ticksPerBar);
        long  beat         = ((eventTime % ticksPerBar) / ticksPerBeat);
        long  tick         = eventTime % ticksPerBeat;
        float milsPerTick  = milliSecondsPerQuartNote / ticksPerBeat;

        String initialMidiString = currentMidiEvent.ToString();

        int currentChannel = getChannelNumber(initialMidiString);
        int noteLength     = getMidiNoteLength(initialMidiString);

        if (noteLength != 0 && currentChannel > -1)
        {
            //START TIME AND DURATION TIME ARE CALCULATED HERE!!!!
            Note newNote = new Note();
            //Double theStartTime = (bar * milliSecondsPerQuartNote * 4) + (milliSecondsPerQuartNote * (beat));
            Double theStartTime = eventTime * milsPerTick;
            newNote.startTime = theStartTime;             //Start time Measured in milliseconds
            String midiInfo   = currentMidiEvent.ToString();
            String typeOfNote = getTypeOfNote(midiInfo, currentChannel);
            newNote.notePitch       = typeOfNote;
            newNote.noteVelocity    = getVelocity(midiInfo);
            newNote.notePitchNumber = GDMethods.getPitchNumber(newNote.notePitch);
            //Debug.Log("Converted " + typeOfNote + " to -> " + newNote.notePitchNumber);
            Double timeOfNote = noteLength;
            //newNote.durationTime = ((((double)(timeOfNote))/(double)ticksPerBeat)* milliSecondsPerQuartNote);//Duration slso meseaured in milliseconds
            //TODO - check this
            newNote.durationTime = noteLength * milsPerTick;
            Channels[currentChannel].Notes.Add(newNote);

            if (!Channels[currentChannel].TypesOfNotes.Contains(typeOfNote))
            {
                Channels[currentChannel].TypesOfNotes.Add(typeOfNote);
            }
        }


        string finalReturn = String.Format("{0}:{1}:{2}", bar + 1, beat + 1, tick);

        Console.WriteLine(finalReturn);
        return(finalReturn);
        //Print out this string to see full output
    }
Exemplo n.º 3
0
        private MidiEventParameter AnalysisEvent(MidiEvent midiEvent, string instrument)
        {
            MidiEventParameter para = new MidiEventParameter();

            if (instrument == "")
            {
                instrument = "Default";
            }
            para.Instrument = instrument; //default instrument
            if (new Regex("(?<=^\\d+ )NoteOn(?= Ch:)").Match(midiEvent.ToString()).Success)
            {
                //Get StartTick
                if (new Regex("^\\d+(?= NoteOn )").Match(midiEvent.ToString()).Success)
                {
                    para.StartTick = long.Parse(new Regex("^\\d+(?= NoteOn )").Match(midiEvent.ToString()).Value);
                }
                //Get Channel
                if (new Regex("(?<=Ch: )\\d+(?=\\s|$)").Match(midiEvent.ToString()).Success)
                {
                    para.Channel = long.Parse(new Regex("(?<=Ch: )\\d+(?=\\s|$)").Match(midiEvent.ToString()).Value);
                }
                //Get Velocity
                if (new Regex("(?<=Vel:)\\d+(?=\\s|$)").Match(midiEvent.ToString()).Success)
                {
                    para.Velocity = long.Parse(new Regex("(?<=Vel:)\\d+(?=\\s|$)").Match(midiEvent.ToString()).Value);
                }
                //Get Length
                if (new Regex("(?<=Len: )\\d+(?=\\s|$)").Match(midiEvent.ToString()).Success)
                {
                    para.Length = long.Parse(new Regex("(?<=Len: )\\d+(?=\\s|$)").Match(midiEvent.ToString()).Value);
                }
                //Get Pitch & Change Instrument
                if (new Regex("(?<=Ch: \\d+ ).*(?= Vel:\\d+)").Match(midiEvent.ToString()).Success)
                {
                    var Change = new Regex("(?<=Ch: \\d+ ).*(?= Vel:\\d+)").Match(midiEvent.ToString()).Value;
                    var pitch  = returnPitch(Change);
                    if (pitch == -1)
                    {
                        para.Instrument = Change;
                    }
                    else
                    {
                        para.Pitch = pitch;
                    }
                }
                return(para);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public void ToStringTest(EventType type, int channel, int data1)
        {
            var midiEvent = new MidiEvent(type, channel, data1, 0);
            var str       = midiEvent.ToString();

            Assert.IsNotNull(str);
            Assert.IsFalse(string.IsNullOrWhiteSpace(str));

            StringAssert.Contains(type.ToString(), str);
            StringAssert.Contains(channel.ToString(), str);
            StringAssert.Contains(data1.ToString(), str);

            // data2 is not contained in MidiEvent#ToString
        }
Exemplo n.º 5
0
        private void SendPlaySoundEvents(MarkablePlaybackEvent playbackEvent, MidiEvent midiEvent)
        {
            // deal with notes our user is supposed to play
            MarkablePlaybackEvent currentNote = null;

            var inSelectedNotes = false;

            foreach (var selectedNote in this.selectedNotes)
            {
                // This playback event describes a note our user is supposed to play.
                if (selectedNote == playbackEvent)
                {
                    inSelectedNotes = true;
                }

                // This playback event describes a note our user was supposed to play but didn't.
                if (selectedNote == playbackEvent &&
                    ((selectedNote.IsMarked && selectedNote.Event.EventType == MidiEventType.NoteOn) ||
                     (!selectedNote.IsMarked && selectedNote.Event.EventType != MidiEventType.NoteOn) ||
                     selectedNote.Event.EventType == MidiEventType.NoteOff))
                {
                    currentNote = selectedNote;
                }
            }

            if (inSelectedNotes)
            {
                // user was supposed to play this
                if (currentNote != null)
                {
                    // The user actually played this.
                    this.SendEvent(midiEvent);
                    this.SelectedTrackNotification?.Invoke(
                        this,
                        new TrackNotificationEventArgs(true, midiEvent.ToString()));
                }
                else
                {
                    // The user did not mark the note.
                    this.SelectedTrackNotification?.Invoke(
                        this,
                        new TrackNotificationEventArgs(false, midiEvent.ToString()));
                }
            }
            else if ((UserData.GameMode != UserData.Mode.Solo && UserData.IsMultiplayerConductor) || UserData.GameMode == UserData.Mode.Solo || UserData.GameMode == UserData.Mode.Offline)
            {
                // play notes for instruments that are not played by current user
                this.SendEvent(midiEvent);
            }

            // Following logic deals with pausing when a noteOn event has been sent but the note off event has not yet
            // been sent, so that we can restart those notes when we unpause.
            var noteMetadata = playbackEvent.Metadata;

            if (noteMetadata == null)
            {
                return;
            }

            if (midiEvent.EventType == MidiEventType.NoteOn)
            {
                this.activeNotes[noteMetadata.RawNote.GetNoteId()] = noteMetadata.RawNote;
                this.OnNotesPlaybackStarted(noteMetadata.RawNote);
            }
            else
            {
                _ = this.activeNotes.Remove(noteMetadata.RawNote.GetNoteId());
                this.OnNotesPlaybackFinished(noteMetadata.RawNote);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="midiEvent"></param>
        private static void MidiManager_MidiEventReceivedA(object sender, MidiEvent e)
        {
            if (e is ActiveSensingEvent)
            {
                return;
            }

            try
            {
                //InstrumentManager.ExclusiveLockObject.EnterUpgradeableReadLock();

                FormMain.OutputDebugLog(null, "A: " + e.ToString());

                ProcessSysEx(MidiPort.PortA, e);

                //lock (ExclusiveLockObject)
                ProcessCC(MidiPort.PortA, e);

                /* set GM inst name
                 *
                 * Dictionary<int, string> dnames = new Dictionary<int, string>();
                 * for (int idx = 0; idx < drumNames.Length; idx++)
                 * {
                 *  dnames.Add((int)drumNames[idx + 1], (string)drumNames[idx]);
                 *  idx++;
                 * }
                 */

                foreach (var i in instruments)
                {
                    i.ForEach((dev) =>
                    {
                        if (dev.MidiPort == Midi.MidiPort.PortAB ||
                            dev.MidiPort == Midi.MidiPort.PortA)
                        {
                            dev.NotifyMidiEvent(e);
                        }

                        /*
                         * foreach (var ti in i)
                         * {
                         *  for (int idx = 0; idx < 128; idx++)
                         *  {
                         *      ti.BaseTimbres[idx].TimbreName = gsInstName[idx];
                         *
                         *      //ti.BaseTimbres[idx].TimbreName = gsInstName[idx] + " A";
                         *      //ti.BaseTimbres[idx + 128].TimbreName = gsInstName[idx] + " B";
                         *  }
                         *  for (int idx = 0; idx < 128; idx++)
                         *  {
                         *      if (ti.DrumTimbres[idx].TimbreNumber != null)
                         *      {
                         *          if (dnames.ContainsKey(idx))
                         *              ti.DrumTimbres[idx].TimbreName = dnames[idx];
                         *      }
                         *  }
                         * }*/
                    });
                }
            }
            finally
            {
                //InstrumentManager.ExclusiveLockObject.ExitUpgradeableReadLock();
            }
        }