Example #1
0
        public void onLoad(object sender, System.EventArgs e)
        {
            //window loaded, set window back to a normal state
            this.WindowState   = FormWindowState.Normal;
            this.Visible       = false;
            this.ShowInTaskbar = true;

            pthrough.Start();
            CreateMIDIDevList();
            if (inDevs.Count > 0)
            {
                int def = getInDev();
                if (def < -1 || def > inDevs.Count)
                {
                    def = -1;
                    setInDev(-1);
                }
                else if (def == -1)
                {
                    devInBox.SelectedIndex = inDevs.Count;
                }
                else
                {
                    lock (inLock)
                    {
                        inPort.Open(def);
                        inPort.Start();
                    }
                    devInBox.SelectedIndex = def;
                }
            }
            if (outDevs.Count > 0)
            {
                int def = getOutDev();
                if (def < -1 || def > outDevs.Count)
                {
                    def = -1;
                    setOutDev(-1);
                }
                else if (def == -1)
                {
                    devOutBox.SelectedIndex = outDevs.Count;
                }
                else
                {
                    lock (outLock)
                    {
                        outPort.Open(def);
                    }
                    devOutBox.SelectedIndex = def;
                }
            }
            devInBox.SelectedIndexChanged  += devInBox_SelectedIndexChanged;
            devOutBox.SelectedIndexChanged += devOutBox_SelectedIndexChanged;
            SetThreadStatus();
        }
Example #2
0
 public void Open(int portId)
 {
     if (!_outPort.IsOpen)
     {
         _outPort.Open(portId);
     }
 }
Example #3
0
        /// <summary>
        /// MIDIの初期化
        /// </summary>
        /// <param name="portnum"></param>
        public MidiManager()
        {
            int NumOfMode = ModeList.Length;

            //モードの数だけトラック配列の要素数を用意する
            tracks = new MidiTrack[NumOfMode];
            //モードの数だけコード進行配列の要素数を用意する
            chordProgList = new List <Chord> [NumOfMode];
            //コード進行配列の初期化
            for (int i = 0; i < NumOfMode; i++)
            {
                tracks[i]        = new MidiTrack();
                chordProgList[i] = new List <Chord>();
            }

            //Modeの数だけコード進行配列の初期化
            for (int mode = 0; mode < NumOfMode; mode++)
            {
                tracks[mode].Insert(new TempoEvent()
                {
                    Tempo = 120, Tick = 0
                });

                //コードの開始位置を0に初期化
                int ChordTickFromStart = 0;
                //入力コード進行(chordProgress)からコード進行リストを初期化する
                foreach (String chordName in inputedChord)
                {
                    //Chordの初期化
                    Chord chord = new Chord(chordName, ChordTickFromStart, mode); //Chordをインスタンス化
                    chordProgList[mode].Add(chord);                               //Modeに対応するインデックスのコード進行配列chordを追加
                    ChordTickFromStart += chord.Gate;                             //次のchordの開始タイミングにする

                    //Trackの初期化
                    tracks[mode].Insert(chord.Base); //ベース音の挿入
                    foreach (var note in chord.NoteList)
                    {
                        tracks[mode].Insert(note);                                  //伴奏音の挿入
                    }
                }
            }
            port = new MidiOutPort(0);
            try
            {
                port.Open();
            }
            catch
            {
                Console.WriteLine("no such port exists");
                return;
            }

            //midiDataにtrackを対応付け
            midiData = new MidiData();
            midiData.Tracks.Add(tracks[MODE_QUARTER]);

            // テンポマップを作成
            domain = new MidiFileDomain(midiData);
        }
Example #4
0
        public void Dispose_AccessDisposedPort_ThrowsException()
        {
            MidiOutPort port = null;

            using (port = CreateMidiOutPort())
            {
            } // Dispose

            port.Open(0);

            Assert.Fail();
        }
Example #5
0
 public MidiManager()
 {
     port = new MidiOutPort(0);
     try
     {
         port.Open();
     }
     catch
     {
         Console.WriteLine("no such port exists");
         return;
     }
 }
Example #6
0
        public static void InitMidi()
        {
            //InitDomain("../../../Resources/wood.mid");
            InitDomain();

            // MIDI ポートを作成
            port = new MidiOutPort(0);
            try
            {
                port.Open();
            }
            catch
            {
                Console.WriteLine("no such port exists");
                return;
            }


            // MIDI プレーヤーを作成
            player = new MidiPlayer(port);
        }
Example #7
0
        public void Start(int inPortId, int outPortId, MidiNoteMapIndex index)
        {
            _index = index;

            try
            {
                byte channel = (byte)((InChannel - 1) & 0x0F);
                _inNoteOn  = (byte)(NoteOn | channel);
                _inNoteOff = (byte)(NoteOff | channel);

                channel     = (byte)((OutChannel - 1) & 0x0F);
                _outNoteOn  = (byte)(NoteOn | channel);
                _outNoteOff = (byte)(NoteOff | channel);

                _diagnosticsReceiver.Reset();

                _outPort.Open(outPortId);

                _inPort.Open(inPortId);
                _inPort.Start();
            }
            catch
            {
                if (_outPort.HasStatus(MidiPortStatus.Open))
                {
                    _outPort.Close();
                }

                if (_inPort.HasStatus(MidiPortStatus.Open))
                {
                    _inPort.Close();
                }

                throw;
            }
            sendTest();
        }