Metronome: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(Add C# implementation) |
||
Line 265: | Line 265: | ||
return 0; |
return 0; |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
=={{header|C#}}== |
|||
{{trans|Java}} |
|||
<syntaxhighlight lang="C#"> |
|||
using System; |
|||
using System.Threading; |
|||
public class Program |
|||
{ |
|||
public static void Main(string[] args) |
|||
{ |
|||
Metronome metronome1 = new Metronome(120, 4); |
|||
metronome1.Start(); |
|||
} |
|||
} |
|||
public class Metronome |
|||
{ |
|||
private double bpm; |
|||
private int measure; |
|||
private int counter; |
|||
public Metronome(double bpm, int measure) |
|||
{ |
|||
this.bpm = bpm; |
|||
this.measure = measure; |
|||
} |
|||
public void Start() |
|||
{ |
|||
Thread thread = new Thread(() => |
|||
{ |
|||
while (true) |
|||
{ |
|||
try |
|||
{ |
|||
Thread.Sleep((int)(1000 * (60.0 / bpm))); |
|||
} |
|||
catch (ThreadInterruptedException e) |
|||
{ |
|||
Console.WriteLine(e.StackTrace); |
|||
} |
|||
counter++; |
|||
if (counter % measure == 0) |
|||
{ |
|||
Console.WriteLine("TICK"); |
|||
} |
|||
else |
|||
{ |
|||
Console.WriteLine("TOCK"); |
|||
} |
|||
} |
|||
}); |
|||
thread.Start(); |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|C++}}== |
=={{header|C++}}== |