Knowing which process produced a sound - process

My computer often produces a "ding" sound, and I can't associate it with anything. Is it possible to programmatically determine the source of the beeps? For example can I hook the sound driver? If so, can you point out some examples or references?

Omer, this isn't a programming question, despite your edit.
No programming is necessary. Close applications one by one over time until the ding stops.

What operating system is this? If you're on Linux, you can use the lsof(8) command to see what files every process has open. If a process is playing sound, it will have the sound device file open, so you can grep for it like so:
lsof | grep -E '/dev/(snd|dsp)'
Another option is to use fuser(1), which works similarly to lsof.

Related

Sizeable screenshot UI code

I am in need of someway to access the UI for the screenshot command in OSX (Cmd+Shft+4) and I would like to be able to activate the UI with a UI button that will screenshot the region selected and save it to a temp location.
Thanks in advance ;)
If there's a direct way to do this from Cocoa, maybe someone will chime in... but I doubt it exists. You can, however, get any behavior you want from the "screencapture" command line utility; it does exactly the same as Cmd-Shift-3 or 4 with a gazillion options. Just type "man screencapture" in Terminal to see all the flags.
But this would require you to run a bash script from your app. If you haven't done that before, well, google it, or check out the many threads here on SO... Opinions vary on how complicated it should be, from a one-liner call to system() to fully thread-safe error reporting NSTask and all kinds of answers in between.
I'd recommend using one of the NSTask answers which keep themselves to half a dozen lines, but YMMV.

How to pause, resume and stop a Sikuli program?

Suppose I am running a Sikuli program and I want to pause the program at a particular point and then after sometime I want to resume the program from that point where I paused, without affecting the process. And then I want to stop the process and exit from it. The point where I stopped till that it should be saved. Is it possible in Sikuli? If yes, then how?
Press Alt+Shift+c to kill a running Sikuli script.
No, Sikuli has no built-in capability to manage this for you. However, you can write all of these capabilities into your script or otherwise get them.
Pausing an resuming is most easily done on the Unix command-line, where you can use control-z to suspend a program and fg to resume it. Windows has similar capabilities. Look for "suspend and resume process " to find some ways of doing this (there are many).
Exiting from a program and then being able to re-start the program and have it resume (roughly) where it left off is called "checkpointing". The checkpointing packages I know of are intended for distributed computing and would probably be overkill for what you're doing, but you could take a look at the Wikipedia entry for suggestions. I suspect that implementing it yourself will be the easiest way to go.
For help with either of these topics, I recommend starting a new question specifying the language you're using (Jython or Java) and the operating system (Unix or Windows). The questions and answers to these aren't related to Sikuli.
For pause, you can use wait commands; if you want to resume, you need to have flags that you set at the beginning of the script, and change accordingly to what you want to wait for.
For closing the script; you can use the Type command wherever you want the script to quit; which is the equivalent of pressing CMD-Shift-C when using the IDE
type('c', KeyModifier.CMD + KeyModifier.SHIFT)
Hope this helps

Programmatically Controlling Playback in FCP

I ran the Unix "strings" command on the Final Cut Pro binary and it returns some stuff like this:
nextEdit:
previousEdit:
stepForward:
stepBackward:
playPause:
Is there any way that I can tell Final Cut to run these functions while it's running? Could this possibly have to do with NSNotifications? I can't find any Apple Documentation on it.
If I'm going about this the wrong way, is there any way I can programmatically control playback (play/pause/rewind/etc.) in Final Cut?
Take a look here: https://discussions.apple.com/thread/6430030
The arguably lame approach is to send keyboard short cuts. Works for me.

How to autostart a program from floppy disk on a Commodore c64

Good news, my c64 ist still running after lots of years spending time on my attic..
But what I always wanted to know is:
How can I automatically load & run a program from a floppy disk that is already inserted
when I switch on the c64?
Some auto-running command like load "*",8,1 would be adequate...
Regards
MoC
You write that a command that you type in, like LOAD"*",8,1 would be adequate. Can I assume, then, that the only problem with that particular command is that it only loads, but doesn't automatically run, the program? If so, you have a number of solutions:
If it's a machine language program, then you should type LOAD"<FILENAME>",8,1: and then (without pressing <RETURN>) press <SHIFT>+<RUN/STOP>.
If it's a BASIC program, type LOAD"<FILENAME>",8: and then (without pressing <RETURN>) press <SHIFT>+<RUN/STOP>.
It is possible to write a BASIC program such that it automatically runs when you load it with LOAD"<FILENAME>",8,1. To do so, first add the following line to the beginning of your program:
0 POKE770,131:POKE771,164
Then issue the following commands to save the program:
PRINT"{CLR}":POKE770,113:POKE771,168:POKE43,0;POKE44,3:POKE157,0:SAVE"<FILENAME>",8
This is not possible without some custom cartridge.
One way to fix this would be getting the Retro Replay cartridge and hacking your own code for it.
I doubt there is a way to do it; you would need a cartridge which handles this case and I don't think one like that exists.
A better and more suitable solution is EasyFlash actually. Retro Replay is commonly used with its own ROM. Since it is a very useful cartridge by default ROM, I would never flash another ROM to it. Also it is more expensive than EasyFlash if you don't have any of those cartridges.
At the moment, I have Prince Of Persia (!) ROM written to my EasyFlash and when I open my c64, it autoruns just like you asked for.
Not 100% relevant, but C128 can autoboot disks in C128 mode. For example Ultima V (which has musics on C128 but not on C64 or C128 in C64 mode) autoboots.
As for cartridges, I'd recommend 1541 Ultimate 2. It can also run games from module rom images (although Prince of Persia doesn't work for me for some reason, perhaps software issue?), but you also get rather good floppy emulator (which also makes it easier to transfer stuff to real disks), REU, tape interface (if you order it) etc.
If you are working with a ML program, there are several methods. If you aren't worried about ever returning to normal READY prompt without a RESET, you can have a small loader that loads into the stack ($0100-$01FF) The loader would just load the next section of code, then jump to it. It would start at $0102 and needs to be as small as possible. Many times, the next piece to load is only 2 characters, so the file name can be placed at $0100 & $0101. Then all you need to do is set LFS, SETNAM, LOAD, then JMP to it. Fill the rest of the stack area with $01. It is also rather safe to only save $0100-$010d so that the entire program will fit on a single disk block.
One issue with this, is that it clears out past stack entries (so, your program will need to reset the stack pointer back to the top.) If your program tries to do a normal RTS out of itself, random things can occur. If you want to exit the program, you'll need to jmp to the reset vector ($FFFC by default,) to do so.

Putting a 'terminal' in my application?

Are there any frameworks for say, putting a display like in Terminal.app in MY app, and then displaying text on it like usual output to STDOUT? Complete with scrollback and etc.?
You may want to look at iTerm, an open-source terminal emulator written in Cocoa. If you really want terminal emulation, you might be able to lift from that framework.
This thread has a couple suggestions. The first is very UNIX'y - you use pipe() to map stdout to a new location. Then you'd need another process or a thread that reads that pipe and displays it into an NSTextView. The other approach that I liked as it seems cleaner and less resource intensive is to replace the File_writer_t _write proc in the stdout() FILE pointer with the hook that you want, which write the output into an NSTextView.