using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace music_consola
{
class Program
{
public static void Main()
{
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(Mary);
}
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);
}
}
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,
}
protected enum Duration
{
WHOLE = 1600,
HALF = WHOLE / 2,
QUARTER = HALF / 2,
EIGHTH = QUARTER / 2,
SIXTEENTH = EIGHTH / 2,
}
protected struct Note
{
Tone toneVal;
Duration durVal;
public Note(Tone frequency, Duration time)
{
toneVal = frequency;
durVal = time;
}
public Tone NoteTone { get { return toneVal; } }
public Duration NoteDuration { get { return durVal; } }
}
}
}
#4 C# Musica
App para tocar una pequeña tonada en modo consola C#
Suscribirse a:
Enviar comentarios (Atom)



No hay comentarios:
Publicar un comentario