Click here to Skip to main content
15,880,796 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Pull Request Pin
Jon McKee2-Jul-20 12:52
professionalJon McKee2-Jul-20 12:52 
PraiseWooo! I did it PinPopular
honey the codewitch1-Jul-20 9:45
mvahoney the codewitch1-Jul-20 9:45 
GeneralRe: Wooo! I did it Pin
David O'Neil1-Jul-20 10:41
professionalDavid O'Neil1-Jul-20 10:41 
GeneralRe: Wooo! I did it Pin
honey the codewitch1-Jul-20 14:28
mvahoney the codewitch1-Jul-20 14:28 
GeneralRe: Wooo! I did it Pin
David O'Neil1-Jul-20 14:36
professionalDavid O'Neil1-Jul-20 14:36 
GeneralRe: Wooo! I did it Pin
honey the codewitch1-Jul-20 15:01
mvahoney the codewitch1-Jul-20 15:01 
GeneralRe: Wooo! I did it Pin
David O'Neil1-Jul-20 15:58
professionalDavid O'Neil1-Jul-20 15:58 
GeneralRe: Wooo! I did it Pin
honey the codewitch1-Jul-20 17:05
mvahoney the codewitch1-Jul-20 17:05 
The tap tempo app (transmitter app) uses the console and I've checked the timing against MIDI-OX and found it reliable. the console window does not have to be real time. Here is the code. Note that _PreciseUtcNowTicks is just getting a high resolution value for the system ticks like you can get from stopwatch. i'd use stopwatch but i think it can drift on some machines, based on what i've read. Note how most of this is a tight loop.

C#
const int MIN_TEMPO = 50;
const int MAX_MSG_COUNT = 100;
Console.Error.WriteLine("Press escape to exit. Any other key to tap tempo");
using (var dev = MidiDevice.Outputs[1])
{
	dev.Open();
	long oldTicks = 0;
	var amnt = 0d;
	var next = 0L;
	var dif = 0L;
	var msgCount = 0;
	while (true)
	{
		if (0 != oldTicks)
		{
			var dif2 = (_PreciseUtcNowTicks - oldTicks);
			var tpm = TimeSpan.TicksPerMillisecond * 60000;
			var amnt2 = tpm / (double)dif2;
			if (amnt2 < MIN_TEMPO)
			{
				oldTicks = 0;
				Console.Error.WriteLine("Tap tempo timed out for tempo less than " + MIN_TEMPO + "bpm");
			}
		}
		if (Console.KeyAvailable)
		{
			if (ConsoleKey.Escape == Console.ReadKey(true).Key)
				return; // exit

			if (0 == oldTicks)
			{
				Console.Error.WriteLine("Tap Started");
				oldTicks = _PreciseUtcNowTicks;
			}
			else
			{
				dif = _PreciseUtcNowTicks - oldTicks;
				var ts = new TimeSpan(dif);
				var ms = ts.TotalMilliseconds;
				var tpm = TimeSpan.TicksPerMillisecond * 60000;
			
				amnt = tpm / (double)dif;
				oldTicks = _PreciseUtcNowTicks;
				Console.Error.WriteLine("Tapped @ " + amnt+"bpm "+ms+"ms");
				next = _PreciseUtcNowTicks + (dif/24);
				dev.Send(new MidiMessageRealTimeTimingClock());
				msgCount=0;
			}
						
		}
		else
		{
			if (MAX_MSG_COUNT > msgCount && 0 != next && _PreciseUtcNowTicks >= next)
			{
				next += dif / 24;
				dev.Send(new MidiMessageRealTimeTimingClock());
				++msgCount;
			}
		}
	}
}

Real programmers use butterflies


modified 1-Jul-20 23:11pm.

GeneralRe: Wooo! I did it Pin
David O'Neil1-Jul-20 20:40
professionalDavid O'Neil1-Jul-20 20:40 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 0:21
mvahoney the codewitch2-Jul-20 0:21 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 8:21
professionalDavid O'Neil2-Jul-20 8:21 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 8:48
mvahoney the codewitch2-Jul-20 8:48 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 8:54
professionalDavid O'Neil2-Jul-20 8:54 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 9:07
mvahoney the codewitch2-Jul-20 9:07 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 9:10
professionalDavid O'Neil2-Jul-20 9:10 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 9:38
mvahoney the codewitch2-Jul-20 9:38 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 9:12
professionalDavid O'Neil2-Jul-20 9:12 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 9:36
mvahoney the codewitch2-Jul-20 9:36 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 10:10
professionalDavid O'Neil2-Jul-20 10:10 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 12:25
mvahoney the codewitch2-Jul-20 12:25 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 13:03
professionalDavid O'Neil2-Jul-20 13:03 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 13:18
mvahoney the codewitch2-Jul-20 13:18 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 9:10
mvahoney the codewitch2-Jul-20 9:10 
GeneralRe: Wooo! I did it Pin
David O'Neil2-Jul-20 9:15
professionalDavid O'Neil2-Jul-20 9:15 
GeneralRe: Wooo! I did it Pin
honey the codewitch2-Jul-20 9:33
mvahoney the codewitch2-Jul-20 9:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.