Exemple #1
0
        public void HandleChannelMessageKeys(int chnl, int NoteID, int Velocity, bool NoteOn = true)
        {
            //
            // Keyboard Key Pressed Channel Messages
            //
            if (NoteID < MinNote || NoteID > MaxNote)
            {
                return;
            }

            NoteMsg.SetText(NoteID.ToString());                     //display note value
            Entity CurrentKey;                                      //get the key entity

            CurrentKey = this.FindEntity("pkey" + NoteID.ToString());
            if (CurrentKey == null)
            {
                return;
            }

            SpriteRenderer sp = CurrentKey.GetComponent <SpriteRenderer>();

            //sp.renderLayer = -8;                    //same render layer for black or white key
            if (NoteOn)
            {
                outDevice.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, NoteID, Velocity));
                sp.Color = Color.Blue;                                          //current key turned blue
            }
            else
            {
                outDevice.Send(new ChannelMessage(ChannelCommand.NoteOff, 0, NoteID, Velocity));
                sp.Color = Color.Yellow;                                          //current key turned white
            }
        }
Exemple #2
0
        public override void Initialize()
        {
            base.Initialize();
            font = new NezSpriteFont(Content.Load <SpriteFont>("Arial"));
            //
            // MIDI sequencer must have processes
            //
            sequencer1                            = new Sanford.Multimedia.Midi.Sequencer();
            sequencer1.clock.Tick                += onTick;
            this.sequencer1.PlayingCompleted     += new System.EventHandler(this.HandlePlayingCompleted);
            this.sequencer1.ChannelMessagePlayed += new System.EventHandler <Sanford.Multimedia.Midi.ChannelMessageEventArgs>(this.HandleChannelMessagePlayed);
            this.sequencer1.SysExMessagePlayed   += new System.EventHandler <Sanford.Multimedia.Midi.SysExMessageEventArgs>(this.HandleSysExMessagePlayed);
            this.sequencer1.Chased               += new System.EventHandler <Sanford.Multimedia.Midi.ChasedEventArgs>(this.HandleChased);
            this.sequencer1.Stopped              += new System.EventHandler <Sanford.Multimedia.Midi.StoppedEventArgs>(this.HandleStopped);
            //
            // Default output device (usually 0)
            //
            outDevice = new OutputDevice(outDeviceID);

            //DialogBar db = new DialogBar(-1);

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // mouse entity (used for tracking of clicks)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            MouseCursor = CreateEntity("mouse");
            MouseCursor.AddComponent(new BoxCollider());
            MouseCursor.AddComponent(new MouseComponent());

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // keyboard entity (playing piano manually)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            MouseCursor = CreateEntity("keyboard");
            MouseCursor.AddComponent(new KeyComponent());

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Text entity with component (Game name label)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            TextEntity = CreateEntity("txt");
            TextEntity.Transform.Position = new Vector2(10, 20);
            TextEntity.Transform.Scale    = new Vector2(1, 1);
            txt = new TextComponent(Graphics.Instance.BitmapFont, "MIDI Player", new Vector2(0, 0), Color.White);
            txt.SetFont(font);
            TextEntity.AddComponent(txt);

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Background, with high value render layer
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            Background     = CreateEntity("background", new Vector2(0, 0));
            Background.Tag = 90;
            //SpriteRenderer comp = new SpriteRenderer(Content.Load<Texture2D>("Background")).SetRenderLayer(99);

            Background.AddComponent(new SpriteRenderer(Content.Load <Texture2D>("Slider/BackgroundMetal")).SetRenderLayer(99));
            Background.GetComponent <SpriteRenderer>().SetOrigin(new Vector2(0, 0));
            Background.SetPosition(new Vector2(310, 15));
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Canvas
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            //
            int    StartX = 10;
            Entity uiCan  = CreateEntity("ui");

            canvas = uiCan.AddComponent(new UICanvas());

            canvas.IsFullScreen = true;
            canvas.RenderLayer  = -10;//= SCREEN_SPACE_RENDER_LAYER;
            //
            // Display for track number
            //
            TrackMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Tracks"));
            TrackMsg.SetPosition(320, 310);
            TrackMsg.SetSize(100f, 50f);
            //
            // Display for channel number
            //
            ChnlMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Channels"));
            ChnlMsg.SetPosition(320, 330);
            ChnlMsg.SetSize(100f, 50f);
            AllChannels = -1;
            //
            // Display for instrument name
            //
            InstrumentMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Channels"));
            InstrumentMsg.SetPosition(320, 350);
            InstrumentMsg.SetSize(100f, 50f);
            //
            // Dispaly for note number being played
            //
            NoteMsg = canvas.Stage.AddElement(new Nez.UI.Label("Piano note played"));
            NoteMsg.SetPosition(320, 370);
            NoteMsg.SetSize(100f, 50f);

            //
            // Track buttons and channels
            //
            for (int i = 0; i < 16; i++)
            {
                TrackChanl[i]      = -1;
                TracksInMidi[i]    = false;             //is track number active in MIDI file
                TracksPlaying[i]   = false;             //individual tracks playing (buttons)
                ChannelsPlaying[i] = true;              //they all are playing
            }

            //
            // turn off all buttons
            //
            //SetTrackButtonOff();
            //
            // Progress bar
            //
            PgBar = canvas.Stage.AddElement(new Nez.UI.ProgressBar(0, 1000, 1, false, Nez.UI.ProgressBarStyle.Create(Color.Green, Color.White)));
            PgBar.SetPosition(10, StartPos);
            //
            // Play button
            //
            PlayImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/play_blk")));
            PlayImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/play_grn")));
            PlayBtn     = canvas.Stage.AddElement(new ImageButton(PlayImageUp, PlayImageDn));
            PlayBtn.SetPosition(StartX, StartPos + 30);
            PlayBtn.OnClicked += Play;

            //
            // Stop button
            //
            StopImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/stop_blk")));
            StopImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/stop_grn")));
            StopBtn     = canvas.Stage.AddElement(new ImageButton(StopImageUp, StopImageDn));
            StopBtn.SetPosition(StartX + 71, StartPos + 30);
            StopBtn.OnClicked += Stop;

            //
            // Load/Eject button (stop playing, look for another MIDI file)
            //
            LoadImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/eject_blk")));
            LoadImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/eject_grn")));
            LoadBtn     = canvas.Stage.AddElement(new ImageButton(LoadImageUp, LoadImageDn));
            LoadBtn.SetPosition(StartX + 110, StartPos + 30);
            LoadBtn.OnClicked += Load;
            //
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Systems to process our requests
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            //
            this.AddEntityProcessor(new MouseClickSystem(new Matcher().All(typeof(MouseComponent))));
            this.AddEntityProcessor(new KeyClickSystem(new Matcher().All(typeof(KeyComponent))));
            this.AddEntityProcessor(new PianoClickSystem(new Matcher().All(typeof(NoteComponent), typeof(PlayingComponent))));
            //
            // Start by loading a file
            //
            if (!LoadMidiFile())
            {
                return;
            }
            //
            // Create the Mixer image with buttons, sliders, etc
            //
            var Track = new TrackMixerEntity(this, new Vector2(310, 20), canvas, TracksInMidi);
            //
            // Create the piano keys on bottom of mixer
            //
            var pi00 = new PianoEntity(this, new Vector2(StartX + 245, StartPos + 420), 0);

            //
            // Octave 4 is the middle C (note 60), color the keys
            //
            HandleOctaveColor(60);
        }