Exemplo n.º 1
0
        public static void RequestNote(Hardware.Timers.PIT.MusicalNote note, Hardware.Timers.PIT.MusicalNoteValue duration, uint bpm)
        {
            NoteRequest next = (NoteRequest)DeadNoteRequests.Pop();

            if (next == null)
            {
                BasicConsole.WriteLine("Cannot set note request because a null object was returned from the circular buffer. Buffer may be full.");
                BasicConsole.DelayOutput(10);
            }
            else
            {
                next.note     = note;
                next.duration = duration;
                next.bpm      = (int)bpm;

                LiveNoteRequests.Push(next);

                if (OwnerThread != null)
                {
                    OwnerThread._Wake();
                }
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            OwnerThread = ProcessManager.CurrentThread;

            Thread.Sleep_Indefinitely();

            while (!Terminate)
            {
                //Scheduler.Disable();
                Awake = false;

                //BasicConsole.WriteLine("Playing notes...");

                while (LiveNoteRequests.Count > 0)
                {
                    //BasicConsole.WriteLine("Playing note...");

                    NoteRequest theReq = (NoteRequest)LiveNoteRequests.Pop();

                    try
                    {
                        Hardware.Timers.PIT.MusicalNote      note     = theReq.note;
                        Hardware.Timers.PIT.MusicalNoteValue duration = theReq.duration;
                        int bpm = theReq.bpm;

                        int  dur_ms = (int)duration * 60 * 1000 / (bpm * 16);
                        long do_ms  = dur_ms;
                        if (dur_ms >= 2000)
                        {
                            dur_ms -= 2000;
                            do_ms   = 2000;
                        }
                        else
                        {
                            dur_ms = 0;
                        }
                        NoteState state = new NoteState()
                        {
                            dur_ms = dur_ms
                        };

                        if (note != Timers.PIT.MusicalNote.Silent)
                        {
                            Hardware.Timers.PIT.ThePIT.PlaySound((int)note);
                        }

                        Playing = true;

                        state.handlerId = Hardware.Timers.PIT.ThePIT.RegisterHandler(new Hardware.Timers.PITHandler(SysCall_StopNoteHandler, state, 1000000L * do_ms, true));

                        while (Playing)
                        {
                            Thread.Sleep(50);
                        }
                    }
                    catch
                    {
                        BasicConsole.Write("Error processing note request! ");
                        if (ExceptionMethods.CurrentException != null)
                        {
                            BasicConsole.Write(ExceptionMethods.CurrentException.Message);
                        }
                        BasicConsole.WriteLine();
                        Playing = false;
                        Hardware.Timers.PIT.ThePIT.MuteSound();
                        BasicConsole.DelayOutput(15);
                    }
                    finally
                    {
                        DeadNoteRequests.Push(theReq);
                    }
                }

                //BasicConsole.WriteLine("Finished playing notes.");

                if (!Awake)
                {
                    //BasicConsole.WriteLine("Sleeping non-critical interrupts thread...");

                    //Scheduler.Enable();
                    if (!Thread.Sleep_Indefinitely())
                    {
                        BasicConsole.SetTextColour(BasicConsole.error_colour);
                        BasicConsole.WriteLine("Failed to sleep play notes thread!");
                        BasicConsole.SetTextColour(BasicConsole.default_colour);
                    }
                }
            }
        }