REQ: R1 MF ("Blue box") Tone Generator

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by Annabelle3985 » Thu Oct 29, 2015 8:50 pm

steve wrote:There's still a few "#\K" and "#\S" characters that should be deleted, for example, line 28.


Is this thaepart you're talking about?

(if (member key '(#\K #\6 #\9))
1100

(if (member key '(#\S)) 1500 0))))))
(if (member key '(#\K #\S))
1700
(if (member key '(#\K #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\0 #\S))
Annabelle3985
 
Posts: 53
Joined: Sat Oct 24, 2015 1:17 am
Operating System: Windows 7

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by steve » Fri Oct 30, 2015 1:51 am

Annabelle3985 wrote:Is this thaepart you're talking about?

(if (member key '(#\K #\6 #\9))
1100

(if (member key '(#\S)) 1500 0))))))
(if (member key '(#\K #\S))
1700
(if (member key '(#\K #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\0 #\S))

Yes.
The first line is looking to see if the input character "key" is in the list '(#\K #\6 #\9), but we don't need to look for the character #\K because we are now dealing with "KP" and "ST" separately.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45316
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by Annabelle3985 » Fri Oct 30, 2015 4:19 am

Is this one better?
Attachments
R1MF Tones.ny
(2.54 KiB) Downloaded 57 times
Annabelle3985
 
Posts: 53
Joined: Sat Oct 24, 2015 1:17 am
Operating System: Windows 7

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by steve » Fri Oct 30, 2015 8:35 am

That's better, but you've missed a couple. The straightforward one is in line 51. The other is a bit more interesting, see lines 47 to 50. Do you understand what those lines do? What do you suggest doing there?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45316
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by Annabelle3985 » Fri Oct 30, 2015 11:43 am

steve wrote:That's better, but you've missed a couple. The straightforward one is in line 51. The other is a bit more interesting, see lines 47 to 50. Do you understand what those lines do? What do you suggest doing there?

To be totally honest with you, I'm confused on what those lines do. What would you suggest I do to fix them?
Annabelle3985
 
Posts: 53
Joined: Sat Oct 24, 2015 1:17 am
Operating System: Windows 7

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by steve » Fri Oct 30, 2015 12:27 pm

Do you understand how "IF" works?

The basic idea is that the code will do something "IF" a specified thing is true, and (optionally) can do something different if it's not true. This type of structure is called a "conditional" because it does something subject to a specified condition being met. A simple example would be:

Code: Select all
(if (= (+ 1 2) 3)
    (print "1 plus 2 equals 3")
    (print "1 plus 2 does not equal 3"))


Of course this silly example will always print "1 plus 2 equals 3".
There are more examples in the XLISP manual: http://www.audacity-forum.de/download/e ... ef-137.htm
It's worth reading that part of the manual before going further.

In your code there are a whole load of "IF" statements that are "nested" one inside another. The code says, "If this is true, then do something, else, if something else is true then do another thing, else if something else is true do another thing, else .... and so on. This is a rather inelegant way of writing the tests (there are better ways), but it works so let's stick with it for now.

The next thing to understand is what the "condition" is that we are testing for true or false.
Let's take one particular example:

Code: Select all
(if (member key '(#\1 #\2 #\4 #\7))


Here we have an "IF" statement that looks to see if "(member key '(#\1 #\2 #\4 #\7)" is true or false.
In plain English, it is looking to see if the value of "key" is in the list of character "1, 2, 4, 7". The "hash backslash" means "a character".
So if, for example, the value of "key" is character "2", then the value of "key" is a member of the list so the condition is "true", but if, for example, the value of "key" is character "3", then it is not a member of the list and the condition is "false".

Now if we look at this block of code:
Code: Select all
  (setf high
    (if (member key '(#\1))
        900
        (if (member key '(#\2 #\3))
            1100
            (if (member key '(#\4 #\5 #\6))
                1300
                (if (member key '(#\7 #\8 #\9 #\0))
                    1500
                    (if (member key '(#\K #\S))
                        1700
                        0))))))

We are setting the value of "high" conditionally.
If the value of "key" is in the first list (which contains only the character "1"), then high is set to 900, else (if it is not in that list), we look to see if the value of "key" is in the next list (containing the number 2 and 3). If it is in the second list then we set the value of "high" to 1100, else, if it is not in that list we ask if the value of "key" is in the list '(#\4 #\5 #\6), and so on until we get to the end of this block of code.

The final "IF" statement looks to see if the value of "key" is in the list containing the characters K and S. If it is, then we set "high" to 1700, otherwise we set "high" to zero.
We don't actually want this final test because we are no longer accepting the characters K or P as valid input, so, going back to the previous "IF" statement, the code asks if the value of "key" s in the list containing the characters 7, 8, 9 and 0. If it is in that list, set "high" to 1700, otherwise (and here we don't want to test the value of "key" any more because we have tested against all valid characters), we just want to set "high" to zero.

Does that make sense? Can you work out how to do that? Have a go and be careful to get the open and close parentheses to match up correctly.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45316
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by Annabelle3985 » Fri Oct 30, 2015 2:30 pm

steve wrote:Do you understand how "IF" works?

The basic idea is that the code will do something "IF" a specified thing is true, and (optionally) can do something different if it's not true. This type of structure is called a "conditional" because it does something subject to a specified condition being met. A simple example would be:

Code: Select all
(if (= (+ 1 2) 3)
    (print "1 plus 2 equals 3")
    (print "1 plus 2 does not equal 3"))


Of course this silly example will always print "1 plus 2 equals 3".
There are more examples in the XLISP manual: http://www.audacity-forum.de/download/e ... ef-137.htm
It's worth reading that part of the manual before going further.

In your code there are a whole load of "IF" statements that are "nested" one inside another. The code says, "If this is true, then do something, else, if something else is true then do another thing, else if something else is true do another thing, else .... and so on. This is a rather inelegant way of writing the tests (there are better ways), but it works so let's stick with it for now.

The next thing to understand is what the "condition" is that we are testing for true or false.
Let's take one particular example:

Code: Select all
(if (member key '(#\1 #\2 #\4 #\7))


Here we have an "IF" statement that looks to see if "(member key '(#\1 #\2 #\4 #\7)" is true or false.
In plain English, it is looking to see if the value of "key" is in the list of character "1, 2, 4, 7". The "hash backslash" means "a character".
So if, for example, the value of "key" is character "2", then the value of "key" is a member of the list so the condition is "true", but if, for example, the value of "key" is character "3", then it is not a member of the list and the condition is "false".

Now if we look at this block of code:
Code: Select all
  (setf high
    (if (member key '(#\1))
        900
        (if (member key '(#\2 #\3))
            1100
            (if (member key '(#\4 #\5 #\6))
                1300
                (if (member key '(#\7 #\8 #\9 #\0))
                    1500
                    (if (member key '(#\K #\S))
                        1700
                        0))))))

We are setting the value of "high" conditionally.
If the value of "key" is in the first list (which contains only the character "1"), then high is set to 900, else (if it is not in that list), we look to see if the value of "key" is in the next list (containing the number 2 and 3). If it is in the second list then we set the value of "high" to 1100, else, if it is not in that list we ask if the value of "key" is in the list '(#\4 #\5 #\6), and so on until we get to the end of this block of code.

The final "IF" statement looks to see if the value of "key" is in the list containing the characters K and S. If it is, then we set "high" to 1700, otherwise we set "high" to zero.
We don't actually want this final test because we are no longer accepting the characters K or P as valid input, so, going back to the previous "IF" statement, the code asks if the value of "key" s in the list containing the characters 7, 8, 9 and 0. If it is in that list, set "high" to 1700, otherwise (and here we don't want to test the value of "key" any more because we have tested against all valid characters), we just want to set "high" to zero.

Does that make sense? Can you work out how to do that? Have a go and be careful to get the open and close parentheses to match up correctly.


Now my mind is in a whirlpool! Interesting how I got all those "if" statements from the "DTMF" plugin, and loosely based my R1MF plugin on that one. Changing the number characters to fit the R1MF Tones, of course.
Annabelle3985
 
Posts: 53
Joined: Sat Oct 24, 2015 1:17 am
Operating System: Windows 7

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by mharriger » Mon Nov 20, 2017 3:14 pm

I created a fairly complete MF plugin. It can do 0-9, KP, KP2, ST, ST2 and ST3 tones. It represents KP2 as KP' and ST2, ST3 as ST', ST'' respectively. You can get it from my github repo. It was inspired by the techniques suggested in this thread, as well as some of my own research. This is my first time writing anything in LISP, so I hope it doesn't contain too much strange syntax.

I plan to do a little more work on it, mostly to make sure it handles invalid input in a sane way and to document it a little bit better.
mharriger
 
Posts: 2
Joined: Mon Nov 20, 2017 3:07 pm
Operating System: Windows 10

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by steve » Mon Nov 20, 2017 4:17 pm

Congratulations mharriger. I don't know much about MF, but the LISP / Nyquist code seems to work all right.

mharriger wrote:This is my first time writing anything in LISP, so I hope it doesn't contain too much strange syntax.

The syntax looks fine, though the formatting (indentation) looks a bit strange in places (not very LISP-like).
There's a good, short guide to formatting LISP code here: http://dept-info.labri.fr/~idurand/ense ... ation.html
Most experienced LISP programmers tend to follow that guide pretty closely, regardless of which dialect of LISP.

As additional guides to good indentation, there is the XLISP manual (http://www.audacity-forum.de/download/e ... -index.htm) and also the Nyquist .lsp files (https://github.com/audacity/audacity/tr ... er/nyquist)

Some of the old Nyquist plug-ins are formatted quite badly, so not a good guide.

I also came across this short "style guide" recently. It does not all apply to Nyquist, but there's some good general tips in it (like writing short functions that do one thing): http://people.ace.ed.ac.uk/staff/medwar ... style.html
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45316
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: REQ: R1 MF ("Blue box") Tone Generator

Permanent link to this post Posted by mharriger » Mon Nov 20, 2017 10:56 pm

Congratulations mharriger. I don't know much about MF, but the LISP / Nyquist code seems to work all right.


Thanks! And thank you for the guide to LISP formatting, I'll take a look at it and see about reformatting the code. It was a struggle to keep the parens matched up, good indentation seems like it would help.
mharriger
 
Posts: 2
Joined: Mon Nov 20, 2017 3:07 pm
Operating System: Windows 10

PreviousNext

Return to Nyquist



Who is online

Users browsing this forum: Exabot [Bot] and 4 guests