mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
Add ConsoleBeepDemo
This commit is contained in:
parent
5e6d3bad8b
commit
ab9ebc058a
5 changed files with 182 additions and 0 deletions
Binary file not shown.
25
Demos/ConsoleBeepDemo/ConsoleBeepDemo.sln
Normal file
25
Demos/ConsoleBeepDemo/ConsoleBeepDemo.sln
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.27428.2037
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBeepDemo", "ConsoleBeepDemo\ConsoleBeepDemo.csproj", "{0AD02943-D563-43E4-A41F-D4FC1870C42A}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0AD02943-D563-43E4-A41F-D4FC1870C42A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0AD02943-D563-43E4-A41F-D4FC1870C42A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0AD02943-D563-43E4-A41F-D4FC1870C42A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0AD02943-D563-43E4-A41F-D4FC1870C42A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {2315A3B8-08D1-4EED-8629-E83991A77E46}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
25
Demos/ConsoleBeepDemo/ConsoleBeepDemo/ConsoleBeepDemo.csproj
Normal file
25
Demos/ConsoleBeepDemo/ConsoleBeepDemo/ConsoleBeepDemo.csproj
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
|
<RuntimeIdentifier>cosmos</RuntimeIdentifier>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<EnableGDB>False</EnableGDB>
|
||||||
|
<StartCosmosGDB>False</StartCosmosGDB>
|
||||||
|
<VisualStudioDebugPort>Pipe: Cosmos\Serial</VisualStudioDebugPort>
|
||||||
|
<CosmosDebugPort>Serial: COM1</CosmosDebugPort>
|
||||||
|
<Launch>VMware</Launch>
|
||||||
|
<Profile>VMware</Profile>
|
||||||
|
<Description>Use VMware Player or Workstation to deploy and debug.</Description>
|
||||||
|
<PxeInterface>192.168.0.8</PxeInterface>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Cosmos.Build" Version="*" NoWarn="NU1604" />
|
||||||
|
<PackageReference Include="Cosmos.Debug.Kernel" Version="*" NoWarn="NU1604" />
|
||||||
|
<PackageReference Include="Cosmos.System2" Version="*" NoWarn="NU1604" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
32
Demos/ConsoleBeepDemo/ConsoleBeepDemo/Kernel.cs
Normal file
32
Demos/ConsoleBeepDemo/ConsoleBeepDemo/Kernel.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Sys = Cosmos.System;
|
||||||
|
|
||||||
|
namespace ConsoleBeepDemo
|
||||||
|
{
|
||||||
|
public class Kernel: Sys.Kernel
|
||||||
|
{
|
||||||
|
protected override void BeforeRun()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Run()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Run Mary Had a Little Lamb?");
|
||||||
|
string ans = Console.ReadLine();
|
||||||
|
if (ans.ToLower() == "y" || ans.ToLower() == "yes")
|
||||||
|
{
|
||||||
|
Test.Main();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Default beep:");
|
||||||
|
Console.Beep();
|
||||||
|
// Does the follwing: Console.Beep((int)Sys.Notes.Default (800 hertz), (int)Sys.Durations.Default (200 milliseconds) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
100
Demos/ConsoleBeepDemo/ConsoleBeepDemo/Test.cs
Normal file
100
Demos/ConsoleBeepDemo/ConsoleBeepDemo/Test.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace ConsoleBeepDemo
|
||||||
|
{
|
||||||
|
class Test
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
// Declare the first few notes of the song, "Mary Had A Little Lamb".
|
||||||
|
Note[] Mary =
|
||||||
|
{
|
||||||
|
new Note(Tone.B, Duration.QUARTER),
|
||||||
|
new Note(Tone.A, Duration.QUARTER),
|
||||||
|
new Note(Tone.GbelowC, Duration.QUARTER),
|
||||||
|
new Note(Tone.A, Duration.QUARTER),
|
||||||
|
new Note(Tone.B, Duration.QUARTER),
|
||||||
|
new Note(Tone.B, Duration.QUARTER),
|
||||||
|
new Note(Tone.B, Duration.HALF),
|
||||||
|
new Note(Tone.A, Duration.QUARTER),
|
||||||
|
new Note(Tone.A, Duration.QUARTER),
|
||||||
|
new Note(Tone.A, Duration.HALF),
|
||||||
|
new Note(Tone.B, Duration.QUARTER),
|
||||||
|
new Note(Tone.D, Duration.QUARTER),
|
||||||
|
new Note(Tone.D, Duration.HALF)
|
||||||
|
};
|
||||||
|
// Play the song
|
||||||
|
Play(Mary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Play the notes in a song.
|
||||||
|
protected static void Play(Note[] tune)
|
||||||
|
{
|
||||||
|
foreach (Note n in tune)
|
||||||
|
{
|
||||||
|
if (n.NoteTone == Tone.REST)
|
||||||
|
Thread.Sleep((int)n.NoteDuration);
|
||||||
|
else
|
||||||
|
Console.Beep((int)n.NoteTone, (int)n.NoteDuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the frequencies of notes in an octave, as well as
|
||||||
|
// silence (rest).
|
||||||
|
protected enum Tone
|
||||||
|
{
|
||||||
|
REST = 0,
|
||||||
|
GbelowC = 196,
|
||||||
|
A = 220,
|
||||||
|
Asharp = 233,
|
||||||
|
B = 247,
|
||||||
|
C = 262,
|
||||||
|
Csharp = 277,
|
||||||
|
D = 294,
|
||||||
|
Dsharp = 311,
|
||||||
|
E = 330,
|
||||||
|
F = 349,
|
||||||
|
Fsharp = 370,
|
||||||
|
G = 392,
|
||||||
|
Gsharp = 415,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the duration of a note in units of milliseconds.
|
||||||
|
protected enum Duration
|
||||||
|
{
|
||||||
|
WHOLE = 1600,
|
||||||
|
HALF = WHOLE / 2,
|
||||||
|
QUARTER = HALF / 2,
|
||||||
|
EIGHTH = QUARTER / 2,
|
||||||
|
SIXTEENTH = EIGHTH / 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define a note as a frequency (tone) and the amount of
|
||||||
|
// time (duration) the note plays.
|
||||||
|
protected struct Note
|
||||||
|
{
|
||||||
|
Tone toneVal;
|
||||||
|
Duration durVal;
|
||||||
|
|
||||||
|
// Define a constructor to create a specific note.
|
||||||
|
public Note(Tone frequency, Duration time)
|
||||||
|
{
|
||||||
|
toneVal = frequency;
|
||||||
|
durVal = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define properties to return the note's tone and duration.
|
||||||
|
public Tone NoteTone { get { return toneVal; } }
|
||||||
|
public Duration NoteDuration { get { return durVal; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
This example produces the following results:
|
||||||
|
|
||||||
|
This example plays the first few notes of "Mary Had A Little Lamb"
|
||||||
|
through the console speaker.
|
||||||
|
*/
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue