Saturday, July 22, 2017

Delphi XE5, dxgettext, Windows 10 : How To Make it all work together


Well I've returned to Delphi, once more. How could I not? Best tool of choice for desktop development (and then some! Mac, Mobile, and more)

Thing is, a few years ago I got used to developing my applications in English (my native language is Spanish), in order to have a multilingual solution from the very start. For that I've always used dxgettext, a free solution, quite efficient and relatively simple to implement.

Enter, Windows 10. Oh that beast.

It seems that something in the most recent Windows 10 releases has broken the implementation of dxgettext. I won't go too deep (I wouldn't know how!) but dxgettext seems to depend on Cygwin, and the Cygwin files in its distribution are way old (same as the package itself, but those are Delphi programs and they do work and work!) and when trying to do things like merging, or decompiling, you might get "bash.exe" running over and over in a loop, until eventually your Windows will hog and you'll have to use the POWER button. Ugly. 

This has been reported by others in here and here and also in the Yahoo Newsgroup.

Tried some of these solutions, involving changes in some DLLs but bash.exe kept coming up with its ugly head once and again.

So, after much testing, I came up with these steps below:
(Also for XE5, or any new Delphi, notice that you might need to use a different .pas unit for gnugettext.pas. See this Link for an updated version)


  1.  Download and fresh install dxgettext-1.2.2.exe from http://dxgettext.po.dk/download as admin. Restart.
  2.  Download Cygwin 32bit from https://cygwin.com/install.html  in a different folder from dxgettext (I took the default, c:\cygwin)
  3. Run setup-x86.exe and select  "Base" Package (Install).  Next, Select Required packages just in case.
  4. Move the following files from dxgettext folder to a backup folder (we'll use some DLL later): cyg*.dll and bash.exe
  5. Copy from c:\cygwin to the dxgettext folder the following files:

    • bash.exe  (set to run as admin)
    • cygwin1.dll
    • cygiconv-2.dll
    • cygintl-8.dll
    • cygreadline7.dll
    • cyggcc_s-1.dll
    • cygncursesw-10.dll


    1. Recover the file(s) below from the backup folder (See #4) and copy to the dxgettext folder.
        cyggettextsrc-0-14-1.dll,  cyggettextlib-0-14-1.dll and  cygintl-3.dll
    2. Running like this, you might get error 740 (requires elevation). So:   Set ggmerge.exe,ggfmt.exe to run as admin

    So far so good; I've tested Merging, Decompiling, Compiling and of course Extraction to Template (this one did work before) and it seems to run ok in my Windows 10 Version 1607 (Anniversary Update I think).

    Hope this can somehow be included in the distribution package; this is an awesome tool and I'm happy if it continues working with this small workaround. 


    Thursday, May 19, 2016

    Spotify connect in Volumio!


    All the previous difficulties I've been through to setup spotify connect in a raspberry PI with a Hifiberry DAC, seem to be highly minimized by using Volumio and some extra tweaks.

    I set up another RPI (ain't they fun?), this time with a Hifiberry Amp+ (a 25w little marvel). Also I made a little DIY cabinet.. More on that later.


    • To make it easier, I set up Volumio, which gave me Airplay out of the box, and also automatic support of the Hifiberry amp+
    • Volumio lets you handle the amp's volume thru software! This fix is necessary, however:


    By default, hardware colume control won’t work. Do enable this, edit /etc/mpd.conf and replace the “audio_output” section with the following configuration:
    audio_output {
                     type           "alsa"
                     name           "Output"
                     device         "hw:0,0"
                     mixer_type     "hardware"      
                     mixer_device   "default"
                     mixer_control  "Master"
                     dop    "no"
    }
    • To handle the library thru my phone, I installed Mupeace in Android. AWESOME.

    SPOTIFY CONNECT
    • But I wanted spotify connect.. I followed the instructions from my previous posts:
      • See "CONFIGURING SOUND & SPOTIFY CONNECT"  in  http://charlysaenz.blogspot.com.ar/2016/01/raspberry-pi-b-as-spotify-connect.html
    • Modify console_callbacks.py according to: 
    https://github.com/JozoVilcek/spotify-connect-web/blob/855b92b49555cdcc11d0ab4c71866475cd7c9499/console_callbacks.py
    • Problem with volumio is that I had to install the above stuff as root.. (sudo -i). Couldn't get it done in a different way.
    • So, basically the whole installation will run under /root folder.
    • In that folder I'll create a spconnect.sh script with this content:

    /root/spotify-connect-web.sh --name volConnect1 --username myuser --password mypwd --bitrate 320 &

    • Then the tricky part to run this on the startup. See the last part of the link below ("/etc/init.d")
      • Create a script in /etc/init.d named spconnect, to handle the service, use the skeleton provided.
      • sudo chmod +x /etc/init.d/spconnect
      • cd /etc/init.d
      • sudo update-rc.d spconnect defaults 
      • Reboot and ready!! Volume handling from the spotify client will work!

    http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html#disqus_thread

    Wednesday, February 17, 2016

    Raspberry PI Spotify and Airplay, continued (DAC!)


    This is the time where I finally was able to get a Hifiberry DAC+ and install it in the RPI.
    Things to do to enable it? After an update, I'm on 4.1.17 kernel; so I went for the 3.1.18+ guide (honestly I started with the 3.12 guide by mistake.. and I had to revert quite a few things)

    Hifiberry configuration guide

    Notes:
    1) You won't find the blacklist file, I just skipped that part (at least I didn´t find it)
    2) etc/modules was empty too. (Maybe because this was Raspbian Jessy Lite?)
    3) Adding the hifiberry dac in the config.txt file did the job, so aplay -l shows it
    4) The configuration should be changed as indicated in /etc/asound.conf 
    5) Success!

    pi@raspberrypi:~ $ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
      Subdevices: 0/1
      Subdevice #0: subdevice #0

    I need to check if anything is wrong with the previous article's configuration.. will spotify connect and airplay still work? Answer: apparently yes. The only thing I changed was the command below in the startup script (spserver.sh). Not sure yet if it's necessary or not.

    # set sound output to analog:
    sudo amixer -c 0 cset numid=3 0

    Additional notes:
    - Trying to play some test wav won't work as (I believe) spotify connect is "taking over" the sound card (DAC) and then, you got a device busy error.


    IMPORTANT:
    Shairport seems to be having issues to work together with Spotify Connect Web (Did it work before? I think it did!). Now trying with Shairport-sync.

    UPDATE to make both services work together:

    * previously create a spkill.sh in /home/pi:

    #!/bin/bash
    sudo pkill -f main.py
    sudo pkill spotify-connect


    * add in /etc/shairport-sync.conf this line,
    // Advanced parameters for controlling how a Shairport Sync runs
    sessioncontrol =
    {
    run_this_before_play_begins="/home/pi/spkill.sh";
    run_this_after_play_ends="/home/pi/spstart.sh";



    Links:

    (Also revisited soft volume stuff)
    https://github.com/Fornoth/spotify-connect-web/issues/11
    http://www.redsilico.com/multiroom-audio-raspberry-pi

    Monday, January 18, 2016

    Raspberry PI (B+) as Spotify Connect device (Work in progress)


    Well I've been buying these little Rapsberry Pis since they started so I keep some of them around and to be honest I end up changing them for something else, as my primary interest is music (then video) and for there is always something that's more powerful (Intel NUC) or smaller, or easier to handle (Windows, doh).

    In the end as application I use my dear Kodi, whenever possible with a bootable Openelec image (both great pieces of software).

    With the Rpi2 (1GB RAM!) I found that Openelec runs so much better and there is little excuse not to use as a Kodi player.  But given I've had the other boxes around I went for something that's quite interesting: a music headless server that can manage Spotify Connect and maybe Airplay (but anyway that's something available on Kodi). For that I will use the next best thing to the Rpi2, the Raspberry Pi B+.

    As of today, Spotify ain't granting rights to everyone out there to write apps to get Spotify Connect built into devices (Chromecast does now; Gramophon too).

    So what can we do? There's a little development ("Spotify Connect Web") to allow the rPi to act as a Spotify Connect target and that will be the start of the project.

    So what am I using?

    REQUIREMENTS
    - Rapsberry PI B+: Accesories/peripherals
        * Wireless K400R Logitech Keyboard/Mouse
        * Connected via Ethernet, HDMI monitor (then SSH)
        * External usb power source.
        * Kingston Micro SD Card 8GB Class 10.

    - An external amplifier/(amplified) speakers: as I plan to use it hooked to my stereo amp, there you go, stereo amp + speakers (or active/amplified speakers, I used that for the test)

    - Raspbian Jessie LITE, latest from the site. As I won't need a GUI I figured the Lite version will do fine (and my internet speed sucks, a smaller size is better!)

    - Spotify Connect Web:  Available at https://github.com/Fornoth/spotify-connect-web
      There are quite a numerous forks out there.. For now I'll stick to this one, the original.

    - A Spotify Premium Account

    PREPARING THE RPI:
    - SD Formatter 4 on the card, with size adjustment
    - WIN32DiskImager; pick the .img from Jessie and burn it to the SD Card.
    - Start the Rpi with the card and the peripherals.

    CONFIGURING THE RPI:
    - Login as pi/raspberry
    - First thing, run sudo raspi-config and expand the filesystem to use the 8gb, you're gonna need them.
    - Reboot to apply the change

    CONFIGURING SOUND & SPOTIFY CONNECT:

    - These are mostly the instructions found in the github site aforementioned.
    - First, follow the instructions in the github site to get the developer key from Spotify. YOU'LL NEED A PREMIUM ACCOUNT.
    - I added the "-- name" option to have your output named as you like. I used "rpiConnect1". That name will appear in the devices list in Spotify.
    curl -O http://spotify-connect-web.s3-website.eu-central-1.amazonaws.com/spotify-connect-web.sh
    chmod u+x spotify-connect-web.sh
    # Download the current chroot (~ 180 MB)
    ./spotify-connect-web.sh install
    # Copy your `spotify_appkey.key` into the app directory. (See below for information on how to get that file.)
    sudo cp spotify_appkey.key spotify-connect-web-chroot/usr/src/app/
    # Run using normal cmdline options
    ./spotify-connect-web.sh --username 12345678 --password xyz123 --bitrate 320 --name Devicename

    - That should work if you test the output to this device.


    FURTHER CONFIGURATION, AUTOSTART & TROUBLESHOOTING

    AUTOSTART:
    To have the service start with our rpi, what I did (after extensive googling of course) is:
    - Create a script in your pi home directory, called spserver.sh. Contents should be:

    # set sound output to analog:
    sudo amixer -c 0 cset numid=3 1

    # run the spotify connect server in the background
    /home/pi/spotify-connect-web.sh --name rpiConnect1 --username my_spotify_user --password my_spotify_pwd --bitrate 320


    - Add in etc/rc.local, the lines below. Put them above the exit 0 command (leave it there). The ampersand (&) will get the process running in the background.

    #start spotify connect
    su pi -c /home/pi/spserver.sh &

    FURTHER CONFIGURATION

    In the link below I got some nice information on how to change a line to provide a default volume of 1. For that change line 74 in the file below (commenting out the math, and fixing "1" as volume)
    /spotify-connect-web-chroot/usr/src/app/connect.py


    ref. link:
    http://support.hifiberry.com/hc/en-us/community/posts/201863051-hifiberry-digi-spotify-connect#community_comment_206970525
    mixer_volume = 1 #int(mixer.getvolume()[0] * 655.35)

    That together with the amixer setting solved the "no volume" situation I had at first.

    TROUBLESHOOTING/NOTES
    -  The analog output setting was necessary in my case as I (believe) I couldn't hear anything because I had an HDMI monitor connected (and so there goes my sound). The amixer setting (sudo amixer -c 0 cset numid=3 n) is selecting analog (where n is 0=auto, 1=headphones/analog, 2=hdmi). Probably it's a one time setting, but I couldn't check that yet.

    ref. links:     
    http://raspberrypi.stackexchange.com/questions/44/why-is-my-audio-sound-# output-not-working
    http://elinux.org/R-Pi_Troubleshooting#Sound_does_not_work_at_all.2C_or_in_some_applications

    - There can be static on the Rpi analog output; that's something to consider, there may be some solutions out there, the best is to change over to a better sound device for the rPi.

    TODO:
    - A wifi dongle (I have a TPLink device but it's attached for now to the Openelec rPI, also it's not anything with fancy speed)
    - A better sound device for the Rpi:  either a HifiBerry DACor similar, or a USB inexpensive sound dongle. That will require more investigation for sure.
    - Installing an Airplay solution too; how would it work together with spotify connect web? Trying now:
    http://raspberrypihq.com/how-to-turn-your-raspberry-pi-into-a-airplay-receiver-to-stream-music-from-your-iphone/
    - hardware volume handling: see at
    https://github.com/Fornoth/spotify-connect-web/issues/11




    Tuesday, January 05, 2016

    Intel Compute Stick / Windows 10 issues and troubleshooting


    This is a draft entry to record my issues with the Intel Compute Stick.

    I started on Win 8.1 with Bing as it was provided, but managed to upgrade to Windows 10 (Only 32bit, Home is allowed by license) without major issues.

    I used the stick primarily as an HTPC device; installed Kodi on it, and little more. Kinda slow, but did work, as Kodi is cool enough to manage a good performance on any platform.

    One day, suddenly, Win10 presented an error - honestly I am not sure which error it was, but after reading some forums about this problem, I guess it was a Windows 10 Update Pack (November update? 10586 version?) that couldn't finish and left the machine in a "limbo" state.

    Thing is, after that, I couldn't even reset the PC to a bare Windows 10 install (it stuck on some percentage after a long time working) even when choosing to lose all my stuff.

    What seems to be working now is the following:

    - Created (with the help of Rufus: select MBR Partition with UEFI!) a bootable USB thumb drive in other Windows machine, with the latest Windows 10 Home 32bit ISO from Microsoft. Note that the Sandisk Extreme thumb drive seems to work, while a Kingston G4 seems to have failed.

    - I was using a crappy USB Hub 2.0 to connect wireless keyboard and the thumb drive.... It was obviously giving me a headache. I moved over to a wired USB keyboard (as per other users' recommendations) and a wired USB mouse, changed the USB Hub to one with external power supply.

    - Also, I was able to do go for the 3 second power button menu (apparently the wireless keyboard was preventing me from getting there) and updated the BIOS version from 18 to 31 (lots of versions in between!)

    - Then I was able to select F10 boot menu, chose the Sandisk thumb with bootable Win10 iso and then started the installation.

    - On the license key prompt I selected "Skip" (with the other hub/keyboard I got an error that there was no storage available or something, asking me to enter a driver for that; it might have been the issue with the wireless combo USB dongle?)

    - I chose to delete the Windows partition and installed over there (about 21gb can't recall exactly). I didn't touch the "images" and other partitions. Not sure what I'll do about that in the future. Don't think they're any worth.

    - Bummer! I chose the wrong ISO (not the first time I do that), and I ended up with Windows 10 Pro installed on the Stick - well, we know it works BUT.. Thing is that Windows appeared as "not activated" and with an error that surely would prevent to activate it even on the phone:

    - After all, that was not the license I was entitled to; Windows 8.1 Bing is freely updated to Windows 10 Home 32BIT ONLY. So, patience, and did it all over again, this time with a thumb drive with the correct Windows 10 Home ISO on it. I did run the setup from inside Windows 10 Pro this time, then deleted the main partition again... And did the whole process...

    - And when finally I reached the desktop and checked on This PC's properties... SUCCESS!! Windows 10 Home, (self) activated!!

    SO - It seems to be working fine! Tomorrow I'll check if it does power up ok, will try to tidy up things a little ( more free space, improve performance etc) *and* try to get an image of this thing in case of more trouble.

    DAY 2
    - The machine booted up without issues; did some performance tweaking, uninstalled some apps and I'm trying to download kodi for Windows.

    - I also followed the instructions in this link to set Wifi as a "metered" connection to avoid the automatic download of updates.. Version 10586 seems to cause trouble. Now I'm on 10240.

    - Pending is to use File History or anything else to create an image of the system in case of trouble. Which seems to be something very likely to happen again.

    - Next thing is to install the Stick drivers from Intel!