Metronome tick tick tick tick

Discuss Applications
Post Reply
Linux Frank
administrator
administrator
Posts: 239
Joined: Fri Jan 10, 2003 2:06 pm

Metronome tick tick tick tick

Post by Linux Frank » Tue Jan 21, 2003 4:16 pm

Does anyone have a prefered application for a metronome that can output tuning notes?

I have found several but would like some personal accounts, if any. Most of the ones out there seem to be in very early stages or require lots of strange sound packages made by other third parties.

If no-one has then I will just untar lots of files until I find one that satisfies. If there is interest I will post my *ahem* researches.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Jan 21, 2003 4:25 pm

I had an itch one day and just wrote a program for that. It really isn't hard. Problem is, it was quite some time ago and I can't seem to find it lying around on any of my machines.

I also was playing around with some electronics one day and put a bunch of LEDs on a breadboard that attaches to my parallel port. I wrote a graphical program in Perl/Tk to display the LEDs on screen and you could create a text file containing musical notes and durations to build a song and run it through the program. It would play the music and flash different colored LEDs/combinations for different notes. It could easily be converted into a metronome program if you don't mind the sound coming from a PC speaker. Can't guarantee accuracy of the notes. :)

I do happen to still have that program. If you could give me your requirements on what you are looking for (and don't mind using the PC speaker) I could hack it up to work like you want.

X11
guru
guru
Posts: 676
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia
Contact:

Post by X11 » Tue Jan 21, 2003 9:02 pm

I seen at a local electronics store, some serial port driven IO controllers which i thuink i will get for my PC.

VoidMain, would you be able to help me write a program to drive it?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Jan 21, 2003 9:14 pm

I can give you my parallel port code. I know the serial port stuff is slightly different but I think it should be fairly easy. With the parallel port you basically just send a byte of data to the I/O address of the parallel port. Depending on which data pins you want to turn on/off will be the value of the byte you send. Here is the actual C code that I call from my Perl script in my sound/LED program which I did not initially write. I did modify it though. Not much to it really:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

#define base 0x378           /* printer port base address */

int main(int argc, char **argv) {

  int value;

  if (argc!=2) {
    fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n");
    return 1;
  }

  if (sscanf(argv[1],"%i",&value)!=1) {
    fprintf(stderr, "Error: Parameter is not a number.\n");
    return 1;
  }

  if ((value<0) || (value>255)) {
    fprintf(stderr, "Error: Invalid numeric value. The parameter number must be
between 0 and 255\n");
    return 1;
  }

  if (ioperm(base,1,1)) {
    fprintf(stderr, "Error: Couldn't get the port at %x\n", base);
    return 1;
  }

  outb((unsigned char)value, base);
  return 0;
}

Linux Frank
administrator
administrator
Posts: 239
Joined: Fri Jan 10, 2003 2:06 pm

Post by Linux Frank » Tue Jan 21, 2003 10:04 pm

Actually I thought about it. I need to learn to use GCC, or some other compiler, and actually get into using the programing facilities in Linux. Maybe I will make one myself.

My requirement is for basic tick tick time. I need the basic 1 beat per second at this learner stage, and I will need to improve upon it. However sound will be important. I need to generate the right pitches so I can match. I am learning the trumpet so this is important. But any basic sound card would be capable of that...right?

So I might make this my first solo programming project, my own metronome. Oh hell I've got another project - never mind such things is life made of. One can never regret learning.

So I need to learn how to use the GCC compiler (that seems to be the best by general consensus of opinion) and then I need to start writing/learning code. I need to learn sound production and control, oh and I will have to consider stability of the timing. If I recall the timing clock in C is 1/100th of a second, and is not that stable (but the unstable time might be from OS/2 - so much stuff so little memory).

Well I must say it's been a long few years since I have been inspired enough to do anything with computers even approaching the stuff I am currently doing, guess I'll have to thank Linus when/if I meet him.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Jan 21, 2003 10:19 pm

Here's a sleep function that wait's in increments of microseconds here throttled up to 1/1000 of a second:

Code: Select all

#include <stdlib.h>

int main (int argc, char **argv){
   long long int i;
   if (argc < 2){
      printf("Usage: %s num, waits num 1000ths of a second\n",argv[0]);
      return 1;
   }else{
      i=atoll(argv[1]);
      i*=1000;
      usleep(i);
   }
   return(0);
}
I think I wrote that one. At least I found it in one of my work directories. The man page says it probably isn't accurate down to the microsecond but it should be more than accurate enough for a metronome. I don't think you can blow your trumpet that fast. :)

There is also a nanosleep which get's you down to the 1Hz level. See the man page for sleep, usleep, and nanosleep:

http://voidmain.kicks-ass.net/man/?parm ... ype=search
Last edited by Void Main on Tue Jan 21, 2003 10:21 pm, edited 1 time in total.

X11
guru
guru
Posts: 676
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia
Contact:

Post by X11 » Tue Jan 21, 2003 10:21 pm

Thanks, im sure that info will be useful.

Linux Frank
administrator
administrator
Posts: 239
Joined: Fri Jan 10, 2003 2:06 pm

Post by Linux Frank » Tue Jan 21, 2003 10:38 pm

Wow - that was a bit quick.

Thanks for that.

I was just reading the man pages and was caught up in the gcc section.

Post Reply