コード例 #1
0
ファイル: Game1.cs プロジェクト: InfinitySamurai/MidiDoge
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            graphics.PreferredBackBufferWidth  = this.windowWidth;
            graphics.PreferredBackBufferHeight = this.windowHeight;
            graphics.ApplyChanges();


            base.Initialize();

            player = new Player(playerTexture, new Vector2(widthMiddle, windowHeight - 50), new Rectangle(0, (int)(windowHeight * 0.66f), windowWidth, (int)(windowHeight - windowHeight * 0.66f)));

            var access = MidiAccessManager.Default;
            var output = access.OpenOutputAsync(access.Outputs.Last().Id).Result;

            midiMusic = MidiMusic.Read(System.IO.File.OpenRead("midiFiles/something_doin'_(nc)smythe.mid"));
            MidiAnalyser midiAnalyser = new MidiAnalyser();

            midiAnalyser.analyseMidi(midiMusic);

            noteManager = new NoteManager(new GameObject(ballTexture, new Vector2(this.widthMiddle, 0)), spawnArc, midiAnalyser, widthMiddle, 200, 800);

            midiPlayer = new MidiPlayer(midiMusic, output);
            midiPlayer.EventReceived += (MidiEvent midiEvent) => {
                if (midiEvent.EventType == MidiEvent.NoteOn)
                {
                    noteManager.addNote(midiEvent);
                }
            };
            midiPlayer.PlayAsync();
        }
コード例 #2
0
        public NoteManager(GameObject defaultNote, float spawnArc, MidiAnalyser analyser, float middleX, float xSpread, float ySpread)
        {
            noteObjects     = new List <GameObject>();
            bufferedObjects = new List <GameObject>();
            baseNote        = defaultNote;
            this.spawnArc   = spawnArc;
            this.analyser   = analyser;

            minX = middleX - xSpread;
            maxX = middleX + xSpread;
            maxY = ySpread;
        }