-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved display of boxing characters using UTF8 box drawing characters #8
Comments
Thanks for taking the time and contributing this nice work, I will add it to the distribution and do some testing. I will initially add a command line flag (-bc) to give users control of the feature. John |
Yay! You're welcome. I'm glad you like it. I know it's not a big deal, but
I like the output better this way.
On an entirely different note, I'm still trying to get the audio library
working. I've had limited success so far. The SFML documentation suggests
that there are two "interfaces" to sounds in the library: "music" and
"sound".
The music interface, at least for playing, is simpler:
M := nsfml_music_from_file "name_of_sound_file.wav
nsfml_play M
plays the sound file, as expected.
The "sound" interface is similar, but a little more complicated.
You can create a sound buffer from a file:
Buffer := nsfml_soundbuffer_from_file "name_of_sound_file.wav
and write that buffer back to a file:
nsfml_soundbuffer_to_file "existing.wav "new.wav
You can create a "sound" object, assign a Buffer to it, and play it:
Sound := nsfml_create_sound 0
nsfml_sound_set_buffer Sound Buffer
nsfml_play Sound
The call to nsfml_create_sound wants an argument. I used '0' and it works,
but I don't know what it's for.
My major curiosity is understanding samples. The sound buffer objects
appear to be essentially opaque, except that you can get samples out.
Samples := nsfml_get_samples Buffer
AFAICT, the Samples array has the right number of values, but the values
print out as odd characters. I don't know how to interpret or use them.
That's where I'm at with the library.
Again, thanks so much for your work in getting QNial working, and I'm glad
you find my very minor contribution helpful.
…On Sun, Sep 12, 2021 at 12:35 AM gibbonsja ***@***.***> wrote:
Thanks for taking the time and contributing this nice work, I will add it
to the distribution and do some testing.
I will initially add a command line flag (-bc) to give users control of
the feature.
John
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHJLAMVQGFO65IN5EPXTWGDUBRCZNANCNFSM5DX7V5GA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi John,
Sorry to say, I previously didn't understand the value of the "V7 QNial
Dictionary.html" file!
Using it, I found the function 'charrep', and, continuing the earlier
discussion about the audio library, the expression
charrep Samples
returns something that looks sensible. So, while I don't understand
everything, the audio library looks more and more useful.
BTW, for other Mac users, the following may be helpful in installing
the audio library. You need to have the SFML library installed. You can
install that library using brew. brew provides both a 'C' and a 'C++'
interface to the library. QNial requires the 'C' interface. On my machine,
I used the following environment variables to access it:
export NIAL_SFML_INCLUDE=/usr/local/Cellar/csfml/2.5.1/include
export NIAL_SFML_LIB=/usr/local/Cellar/csfml/2.5.1/lib
You need to set these variables before running cmake.
…On Sun, Sep 12, 2021 at 12:35 AM gibbonsja ***@***.***> wrote:
Thanks for taking the time and contributing this nice work, I will add it
to the distribution and do some testing.
I will initially add a command line flag (-bc) to give users control of
the feature.
John
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHJLAMVQGFO65IN5EPXTWGDUBRCZNANCNFSM5DX7V5GA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi, Samples are really 16 bit integers, 2 bytes per sample. The sound buffer defines the number of channels, the sample rate for playing and the number of samples. The samples are packed into the sound buffer with the samples for each channel together. Ignore the 0 argument. I made it a function, which requires arguments, but it probably should have been and expressino John |
That makes sense.
…On Sun, Sep 12, 2021 at 4:49 PM gibbonsja ***@***.***> wrote:
Hi,
Samples are really 16 bit integers, 2 bytes per sample. The sound buffer
defines the number of channels, the sample rate for playing and the number
of samples. The samples are packed into the sound buffer with the samples
for each channel together.
Ignore the 0 argument. I made it a function, which requires arguments, but
it probably should have been and expressino
Hope this helps.
John
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHJLAMVEBJGY4ZOKEQUJFDLUBUU6DANCNFSM5DX7V5GA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
My last message was ambiguous. The order of samples for two channels is
Channel 1, sample1
Channel 2, sample1
Channel 1, sample2
Etc
…On Mon, Sep 13, 2021, 11:49 m-bob ***@***.***> wrote:
That makes sense.
On Sun, Sep 12, 2021 at 4:49 PM gibbonsja ***@***.***> wrote:
> Hi,
>
> Samples are really 16 bit integers, 2 bytes per sample. The sound buffer
> defines the number of channels, the sample rate for playing and the
number
> of samples. The samples are packed into the sound buffer with the samples
> for each channel together.
>
> Ignore the 0 argument. I made it a function, which requires arguments,
but
> it probably should have been and expressino
> Hope this helps.
>
> John
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#8 (comment)>, or
> unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AHJLAMVEBJGY4ZOKEQUJFDLUBUU6DANCNFSM5DX7V5GA
>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
>
> or Android
> <
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
>.
>
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNGE3NWWWLRZYA4Z3KHGRTUBVKCFANCNFSM5DX7V5GA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I have put the sound library created by Stu Smith up on Nial Libraries. |
Thanks so much! It'll be awhile before I can check it out, but I expect it'll be useful. And fun. |
Hi,
I apologize for the incomplete nature of this post, but I thought it might be helpful as-is and I don't know when I'll be able to improve it further.
I tried a number of ways to get QNial to use the UTF8 box drawing characters none of which worked. The "right" way to do it appears to involve a lot of effort to rewrite routines in the file picture.c .
But there's a very easy work-around that accomplishes the same thing with little effort. The key idea is simply for QNial to use the IBM box-drawing characters until "the last moment" and then replace them with the equivalent UTF8 characters just before output.
The changes needed are as follows. First, one needs to modify main_stu.c by adding the import
include <locale.h>
and then placing the line
setlocale (LC_ALL, "");
somewhere in main().
One should also tell QNial to use the IBM characters by changing the argument of the initboxchars () call to true:
initboxchars (true);
Next, one needs to modify the file unixif.c .
First, add the imports
include <wchar.h>
include "picture.h"
Second, before any executable code, insert
unsigned char ibm_boxing_chars [] = {ibm_luc, ibm_ruc, ibm_llc, ibm_rlc, ibm_ut, ibm_lt, ibm_rt, ibm_gt, ibm_cro, ibm_hor, ibm_ver};
short int u8_boxing_chars [] = {u'┌', u'┐', u'└', u'┘', u'┬', u'┴', u'┤', u'├', u'┼', u'─', u'│'};
The code looks for the characters in the array ibm_boxing_chars [] and replaces them with the corresponding characters in u8_boxing_chars [] .
Third, I used this simple function to find the characters to change:
int find_index (int c, unsigned char array [], int n)
{ for (int index = 0; index < n; ++index)
{ if (c == (int) array [index])
return index;
}
return -1;
}
Place that code wherever you like.
Fourth, and finally, change the routine writechars (). Here's my routine:
nialint
writechars(FILE * file, char buf, nialint n, int nlflag)
{
static int calls = 0; / internal counter used for breakchecking */
if (keeplog && (file == stdout))
writelog(buf, n, nlflag);
/* every 25 calls check for a signal (approx one screen full) */
if (++calls > 25) {
calls = 0;
checksignal(NC_CS_OUTPUT);
}
{
int i;
// for (i = 0; i < n; i++)
// putc (buf[i], file);
for (i = 0; i < n; i++)
{ int k = (int) (unsigned char) buf [i];
int index = find_index (k, ibm_boxing_chars, 11);
if (index == -1) putc (buf [i], file);
else putwc (u8_boxing_chars [index], file);
}
if (nlflag)
putc('\n', file);
fflush(file);
}
return (n);
}
The only change is that the single call to putc () in the body of the output for loop is replaced with four lines of code and the surrounding braces. Everything else remains the same.
I haven't extensively tested this code (and certainly not with file output set to anything other than STDOUT), but it works in the cases I tried.
I hope this helps someone!
A nice thing about this approach is that it doesn't constrain the choice of terminal font: any fixed-width font which contains the UTF8 drawing characters can be used. I'm using this code on a Mac and do not need an IBM-specific font.
I haven't tried to determine the level of QNial support for unicode. Certainly full unicode support would be nice, and would likely make this work-around irrelevant.
The text was updated successfully, but these errors were encountered: