Skip to content

Commit 1c4a40b

Browse files
committed
Added demo to solution
1 parent ab9ebc0 commit 1c4a40b

File tree

6 files changed

+142
-133
lines changed

6 files changed

+142
-133
lines changed

Demos/ConsoleBeepDemo/ConsoleBeepDemo.sln Demos/BeepDemo/BeepDemo.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.27428.2037
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBeepDemo", "ConsoleBeepDemo\ConsoleBeepDemo.csproj", "{0AD02943-D563-43E4-A41F-D4FC1870C42A}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeepDemo", "BeepDemo.csproj", "{0AD02943-D563-43E4-A41F-D4FC1870C42A}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Demos/BeepDemo/Kernel.cs

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Sys = Cosmos.System;
5+
using System.Threading;
6+
7+
namespace BeepDemo
8+
{
9+
public class Kernel: Sys.Kernel
10+
{
11+
protected override void BeforeRun()
12+
{
13+
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
14+
}
15+
protected override void Run()
16+
{
17+
Console.WriteLine("Run 'Mary Had a Little Lamb'? ");
18+
string ans = Console.ReadLine();
19+
if (ans.ToLower() == "y" || ans.ToLower() == "yes")
20+
{
21+
BeepTest.Main();
22+
}
23+
else
24+
{
25+
Console.WriteLine("Default beep:");
26+
Console.Beep();
27+
// Does the follwing: Console.Beep((int)Sys.Notes.Default (800 hertz), (int)Sys.Durations.Default (200 milliseconds) );
28+
}
29+
}
30+
}
31+
class BeepTest
32+
{
33+
public static void Main()
34+
{
35+
// Declare the first few notes of the song, "Mary Had A Little Lamb".
36+
Note[] Mary =
37+
{
38+
new Note(Tone.B, Duration.QUARTER),
39+
new Note(Tone.A, Duration.QUARTER),
40+
new Note(Tone.GbelowC, Duration.QUARTER),
41+
new Note(Tone.A, Duration.QUARTER),
42+
new Note(Tone.B, Duration.QUARTER),
43+
new Note(Tone.B, Duration.QUARTER),
44+
new Note(Tone.B, Duration.HALF),
45+
new Note(Tone.A, Duration.QUARTER),
46+
new Note(Tone.A, Duration.QUARTER),
47+
new Note(Tone.A, Duration.HALF),
48+
new Note(Tone.B, Duration.QUARTER),
49+
new Note(Tone.D, Duration.QUARTER),
50+
new Note(Tone.D, Duration.HALF)
51+
};
52+
// Play the song
53+
Play(Mary);
54+
}
55+
56+
// Play the notes in a song.
57+
protected static void Play(Note[] tune)
58+
{
59+
foreach (Note n in tune)
60+
{
61+
if (n.NoteTone == Tone.REST)
62+
{
63+
Thread.Sleep((int)n.NoteDuration);
64+
}
65+
else
66+
{
67+
Console.Beep((int)n.NoteTone, (int)n.NoteDuration);
68+
}
69+
}
70+
}
71+
72+
// Define the frequencies of notes in an octave, as well as
73+
// silence (rest).
74+
protected enum Tone
75+
{
76+
REST = 0,
77+
GbelowC = 196,
78+
A = 220,
79+
Asharp = 233,
80+
B = 247,
81+
C = 262,
82+
Csharp = 277,
83+
D = 294,
84+
Dsharp = 311,
85+
E = 330,
86+
F = 349,
87+
Fsharp = 370,
88+
G = 392,
89+
Gsharp = 415,
90+
}
91+
92+
// Define the duration of a note in units of milliseconds.
93+
protected enum Duration
94+
{
95+
WHOLE = 1600,
96+
HALF = WHOLE / 2,
97+
QUARTER = HALF / 2,
98+
EIGHTH = QUARTER / 2,
99+
SIXTEENTH = EIGHTH / 2,
100+
}
101+
102+
// Define a note as a frequency (tone) and the amount of
103+
// time (duration) the note plays.
104+
protected struct Note
105+
{
106+
Tone toneVal;
107+
Duration durVal;
108+
109+
// Define a constructor to create a specific note.
110+
public Note(Tone frequency, Duration time)
111+
{
112+
toneVal = frequency;
113+
durVal = time;
114+
}
115+
116+
// Define properties to return the note's tone and duration.
117+
public Tone NoteTone { get { return toneVal; } }
118+
public Duration NoteDuration { get { return durVal; } }
119+
}
120+
}
121+
/*
122+
This example produces the following results:
123+
124+
This example plays the first few notes of "Mary Had A Little Lamb"
125+
through the computer PC Speaker.
126+
*/
127+
}

Demos/ConsoleBeepDemo/ConsoleBeepDemo/Kernel.cs

-32
This file was deleted.

Demos/ConsoleBeepDemo/ConsoleBeepDemo/Test.cs

-100
This file was deleted.

Kernel.sln

+14
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spruce", "..\XSharp\source\
9494
EndProject
9595
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XSharp.x86", "..\XSharp\source\XSharp.x86\XSharp.x86.csproj", "{7370A62F-12DA-4181-BE3B-009D0926CA7E}"
9696
EndProject
97+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BeepDemo", "BeepDemo", "{83BA8293-9BC0-496E-A9D4-7F8365BEEFCE}"
98+
EndProject
99+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeepDemo", "Demos\BeepDemo\BeepDemo.csproj", "{5EF63907-CB93-4FA0-BA9C-B73EC7001365}"
100+
EndProject
97101
Global
98102
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99103
Debug|Any CPU = Debug|Any CPU
@@ -335,6 +339,14 @@ Global
335339
{7370A62F-12DA-4181-BE3B-009D0926CA7E}.Release|Any CPU.Build.0 = Release|Any CPU
336340
{7370A62F-12DA-4181-BE3B-009D0926CA7E}.Release|x86.ActiveCfg = Release|Any CPU
337341
{7370A62F-12DA-4181-BE3B-009D0926CA7E}.Release|x86.Build.0 = Release|Any CPU
342+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
343+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Debug|Any CPU.Build.0 = Debug|Any CPU
344+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Debug|x86.ActiveCfg = Debug|Any CPU
345+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Debug|x86.Build.0 = Debug|Any CPU
346+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Release|Any CPU.ActiveCfg = Release|Any CPU
347+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Release|Any CPU.Build.0 = Release|Any CPU
348+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Release|x86.ActiveCfg = Release|Any CPU
349+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365}.Release|x86.Build.0 = Release|Any CPU
338350
EndGlobalSection
339351
GlobalSection(SolutionProperties) = preSolution
340352
HideSolutionNode = FALSE
@@ -380,6 +392,8 @@ Global
380392
{E35E0DBF-555F-4D38-8F28-ACDFA9DC97BD} = {5FF9BF2A-5162-4F12-82B6-1693AD776636}
381393
{0812DD0A-4CEE-4376-B78A-02EBCBAA14C2} = {3CD3D9A5-9BC5-4FEB-8D63-4D535C0ABB78}
382394
{7370A62F-12DA-4181-BE3B-009D0926CA7E} = {3CD3D9A5-9BC5-4FEB-8D63-4D535C0ABB78}
395+
{83BA8293-9BC0-496E-A9D4-7F8365BEEFCE} = {B56A6119-1B8F-44E4-9446-291E52F47D4C}
396+
{5EF63907-CB93-4FA0-BA9C-B73EC7001365} = {83BA8293-9BC0-496E-A9D4-7F8365BEEFCE}
383397
EndGlobalSection
384398
GlobalSection(ExtensibilityGlobals) = postSolution
385399
SolutionGuid = {1A1E8F1D-82B3-471F-9B59-0350DEA9203D}

0 commit comments

Comments
 (0)