Saturday, October 6, 2012

A Podcast Alarm Clock on Android (BeyondPod Smart Play)

[Instructions at end of post]

I have been wishing for a long time to wake up to podcasts instead of music in the morning. Hearing the news for an alarm instead of the same song everyday gives me something to think about, which usually gets me out of bed much quicker.

My first try was creating my own app to do this. But I quickly realized that I could neither create an alarm app that works as well or has as many features as others, or a podcast catcher that  works as well as something like my beloved BeyondPod. Plus, creating my own app would violate the unix philosophy of not creating duplicate solutions to a problem.

Instead, I decided the best approach would be to link apps designed to do each of these. I had discovered BeyondPod, and loved many features of it - especially smart play, which allows me to hit one button, hop on my bike, and enjoy good podcasts for the entire ride. Many alarm clock apps like alarm clock plus allow you to launch an app instead of playing music, but if you launch BeyondPod, it does not start playing automatically.

I checked out the AndroidManifest.xml for BeyondPod and noticed that there actually is a way to send an Intent to BeyondPod to instruct it to start playing - there is even one to start the smart play playlist! These intents are shown here: http://beyondpod.com/support/index.php?/Knowledgebase/Article/View/31/5/beyondpod-public-apis .

Needless to say, I was pretty excited about finding this. So I downloaded AppAlarm thinking that I could just plug one of these intents in, and immediately get it working. Sadly this is not the case. If you create a new alarm with a Custom Intent with the Action: "mobi.beyondpod.command.START_SMART_PLAY", it doesn't work. I am still not quite sure why this is the case, but I suspect that it is because AppAlarm uses startActivity() rather than broadcastIntent() when it sends the intent.

So, I still didn't have the solution. Finally, I stumbled upon this page: http://ig88.cwfk.net/?page_id=73, which specifically mentions sending one of the BeyondPod play intents. This app allowed me to finally string it all together - see the instructions below.

After all this, I really want to thank some people:
1. The architects of the android operating system, for making it easy to link apps together with concepts like Intents.
2. The programmers of BeyondPod, AppAlarm, and Manual Intent Shortcuts for making apps that solve their corresponding problems well.

These people didn't do a perfect job (i.e. imho BeyondPod should make itself launchable from AlarmClockPlus, AppAlarm should have support for broadcasting intents and a gentle volume increase, and Manual Intent Shortcuts should have a test button), but they did a good enough job designing their apps to solve individual problems that I was able to accomplish something with these tools that they probably didn't specifically intend. And that is programming goodness.


How to get it working:

1. Install AppAlarm ProManual Intent Shortcuts, and BeyondPod (I'm not sure if this will work with the free version of BeyondPod, but BeyondPod is one of my favorite apps, so I would recommend buying the unlock key)

2. Set up smart play in BeyondPod according to whatever you want to hear in the morning (I recommend some nice, soothing NPR news: NPR 7 am News Summary (podcast url: http://www.npr.org/rss/podcast.php?id=500001).

3. In AppAlarm, create a new alarm.
Click "App To Launch"
Select "Create Shortcut"
Scroll down and select "Manual Intent Shortcuts"

Fill in the  following fields (you should omit the quotes):
Shortcut Name:"BeyondPod Smart Play" (or whatever you want - doesn't matter)
Action:"mobi.beyondpod.command.START_SMART_PLAY"
Broadcast:<checked>

4. Set up the alarm however you want it. In the alarm Volume Options, make sure you check Set Media Volume, so that you don't miss the alarm.


If you want to wake up to something besides Smart Play:

In BeyondPod 3.0.20 and later, there is a feature called "Quick Play" which works with Android's voice search so that you can say "Listen to News" for example and hear all podcasts in your News category. We can also use quick play for an alarm, and with this configuration, we don't need Manual Intent Shortcuts. To do this, modify instruction 3 as follows:

3. In AppAlarm, create a new alarm.
Click "App To Launch"
Select "Create Shortcut"
Scroll down and select "BeyondPod Quick Play"

This will allow you to choose which category you would like to listen to when the alarm goes off. (Thanks to Daniel for pointing this out)



Thursday, April 26, 2012

A Solution for External Monitors on a Thinkpad W520 running Linux

Disclaimer: These are not detailed instructions. If you are new at using linux, you will almost certainly have to look up a few things outside this blog to be able to follow these instructions.

External display without restarting X !


If you use linux on your Thinkpad W520, you have undoubtedly been frustrated by the graphics situation. With a default install, it's impossible to enjoy both the battery life of the integrated intel graphics card and to have external monitors. The situation is documented in this earlier blog post, along with a partial solution to the problem. The biggest drawback to the solution presented in that post is that you must log out of your X-session to disconnect or connect an external display. Fortunately, with some hacking from Liskni_si , we now have a better option:

A dynamic external display in nVidia Optimus Mode without having to restart the X-Server!
 
Notes:
- As far as I know this should also work on some T420/520 models to get the display port output and/or tri-head display.
- You may use this with bumblebee installed, however, you MUST follow ALL the steps that Lekensteyn lays out here except instead of $ export DISPLAY=:8 , run $ screenclone -d :8
- There are some perhaps easier-to-follow instructions to do this with bumblebee and 3D support on the intel card here:  http://sagark.org/optimal-ubuntu-graphics-setup-for-thinkpads/


So, here is how the system works:


1. Use bbswitch to turn the nVidia card on and off when you need it.
2.  All of the rendering is done on the intel card. This requires an extra virtual screen inside the intel card which can be dynamically activated and configured via xrandr.
3. The content of the intel card's virtual screen is copied to the nvidia card via Liskni_si's screenclone for displaying on the external display.


Here's some basic instructions to get it to work:

1. Download bbswitch via your package manager (for ubuntu it is in the bumblebee ppa). Source and instructions on how to use it are here: https://github.com/Bumblebee-Project/bbswitch (you don't NEED to install all of bumblebee)

$ sudo apt-add-repository ppa:bumblebee/stable
$ sudo apt-get update
$ sudo apt-get install bbswitch-dkms

Learn how to use it. You may also have to manually insert the bbswitch module for it to work

$ sudo modprobe bbswitch

2. Patch your intel driver to give it an extra virtual display.

First download the source for the intel driver

$ apt-get build-dep xserver-xorg-video-intel
$ apt-get source xserver-xorg-video-intel

Then, download and apply the patch to create the extra virtual screen

$ cd <wherever you put the source>/xserver-xorg-...
$ wget https://raw.github.com/liskin/patches/master/hacks/xserver-xorg-video-intel-2.18.0_virtual_crtc.patch
$ patch -p1 < xserver-xorg-video-intel-2.18.0_virtual_crtc.patch

[EDIT - there is a newer update of the patch here: https://github.com/liskin/patches/blob/master/hacks/xserver-xorg-video-intel-2.20.14_virtual_crtc.patch. This new patch may be required for newer systems such as ubuntu 12.10. It also contains support for 2 virtual screens, although support for two external screens in screenclone may not be available yet]

Finally, build and install the new intel driver

$ dpkg-buildpackage -b
$ cd ..
$ sudo dpkg --install xserver-xorg-video-intel_2.17.0-1ubuntu4_amd64.deb

Now you probably have to restart X, but after you do, if you run xrandr, you should see an entry called "VIRTUAL", that's what we need.

3. Download and build the screenclone source

$ git clone git://github.com/liskin/hybrid-screenclone.git
$ cd hybrid-screenclone
$ make


Usage

To attach an external monitor, first start the x server on the nvidia device with the xorg.conf (xorg.conf.nvidia) included with the hybrid-screenclone source (the nvidia card must be on of course - you can check this with bbswitch).


$ /usr/bin/X -ac -audit 0 -config xorg.conf.nvidia -sharevts -modulepath /usr/lib/nvidia/current,/usr/lib/xorg/modules -nolisten tcp -noreset :1

(If you have bumblebee installed, skip the step above because bumblebee controls the nvidia X server. Instead just run $ optirun true to get the X server going)

Then turn on the virtual screen in the intel chip

$ xrandr --output LVDS1 --auto --output VIRTUAL --mode 1920x1080 --left-of LVDS1

And finally, send the intel output to the nvidia card (you'll need to put the screenclone binary in your path)

$ screenclone

(If you have bumblee installed use $ screenclone -d :8 instead)

If you don't see the right screen on your external monitor, try running screenclone with the argument -x n where n is 0, 1, or 2. 

Make some scripts out of this (you can see the scripts I have made for my use here), and enjoy your new-found freedom!

And maybe one day, Liskni_si will even extend his code so that we W520 users can have triple head without needing to restart X every time ; )

[If you are looking for a way to enable 3D acceleration on the Intel card, have a look at Christoph Gritschenberger's comment below]

Wednesday, January 11, 2012

Tri-head display on linux Thinkpad W520 (Graphics Adventures)

Note: while all the stuff in this post is still accurate and it is a useful reference, I think that most people will find the solution presented here more useful.

                                                                                                               

Since I got my Thinkpad W520 back in October, I have been in for an adventure in learning about the graphics. One of the reason's that I chose the W520 (and this is only one of many - it is an awesome machine) is that it was advertised to support two external monitors for a total of three including the Thinkpad display (now I know that some T-series can support four with the dock though). Earlier this week, I finally had two monitors in the same place to play with and had amassed the knowledge needed to get it all working right on Linux. I am a Linux noob, so this was a long journey that taught me a great deal about graphics hardware, the open-source world, and the insides of my beloved W520.



Here's what I know in hopes that it will help some other W520 users (and maybe some people using other similar systems):

The W520 uses a system called nvidia Optimus. You can find out more about it here, but basically it means that the Thinkpad Display is always controlled by the intel integrated card. When Windows 7 runs a program with demanding graphics, the nvidia card does the rendering and dumps the output to the intel card to display on the screen.

I am pretty happy with the Lenovo engineers because they give the user the option to disable nvidia Optimus in favor of either the nvidia discrete or intel integrated graphics. In the BIOS (Access by holding F12 when the "Thinkpad" splash screen is displaying at startup), there are three options for the display configuration (note: the OS detection option appears to make the setting go to "nvidia optimus" when linux is running. This is usually not the desired behavior, so I recommend disabling OS detection).

Here are descriptions of the three options:

Integrated - Runs only the intel integrated graphics chip. Here the integrated intel chip controls only the Thinkpad display on the W520. (It seems that on the T420 and T520, the integrated card is also connected to the VGA output, but I have no way of verifying this)

                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \____________
                                                   \
                                  -----------       \
                                 \  NVIDIA    \      \
                                  \ Card (off) \      \
      Display Port                   -----------       \
                                                        \
                                          _______________\
                                          \            
                                       ----------        
      VGA Output                      \  Intel    \     
                                       \ Card      \   
                                         ----------- 


Discrete - Runs only the nvidia discrete graphics chip. The nvidia chip is connected to all three outputs, but sadly :,( it can only run two at a time (hence the '2/3' connection markings).

                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \            
                                      2/3          
                                        \          
                                  -----------       
                                 \  NVIDIA    \      
                                  \ Card       \       
      Display Port --2/3---          -----------        
                           \                \           
                            \________________\            
                             \                           
                              \        ----------       
      VGA Output ----2/3-------       \  Intel    \    
                                       \ Card (off)\  
                                         ----------- 


Nvidia Optimus - In this mode, both graphics cards are running. The Nvidia chip is connected directly to the external display connections and the intel chip is connected to the Thinkpad Display. In Windows 7, there is native support for the cards to communicate over the motherboard, so everything works out of the box. In linux, the support must come from extenal tools (there may be native support in the future). Bumblebee can be used to render things on the Nvidia card and display them through the intel card, and a program called screenclone (see instructions here and here) can be used to display a desktop rendered on the Intel card through the Nvidia card to the external monitors.

 
                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \           
                                       \__________           
                                                  \
                                  -----------      \
                               __\  NVIDIA    \     \
                               \  \ Card       \     \ 
      Display Port --------     \    -----------      \ 
                           \     \        \            \
                            \_____\    Motherboard      \
                             \              \            \
                              \        ----------         \
      VGA Output --------------       \  Intel    \________\
                                       \ Card      \  
                                         ----------- 


So, how do you use this information? Well, here are my recommendations for 3 different types of users:

1. "I want the best battery life!" (and I don't use a projector often)
Use the "Integrated" BIOS display setting. This will only ever run the Intel graphics card. As far as I can tell, you will have to go into the BIOS and change the setting if you want to connect to a projector, but it is definitely possible to get decent graphics performance (compiz, 3d acceleration, etc) off of just the intel card.

2. "I just want everything to look nice and work!"
Use the "Discrete" BIOS display setting. Get the Nvidia proprietary drivers:

$ sudo apt-get install nvidia-current
$ jockey-text -e xorg:nvidia_current

or download from http://www.nvidia.com/object/unix.html and run the file

and have fun with awesome performance! I have never had any problems with these settings, and using disper in conjunction with nvidia-settings to control external displays is a dream! I just feel happy when I think about this configuration! Battery life is honestly not that bad either - the nvidia drivers automatically underclock the card when usage is low.

[tip: to adjust the display brightness when using the nvidia drivers, press Ctrl-Alt-F1 to jump to a tty screen, adjust the brightness, then return to graphical mode using Ctrl-Alt-F7 or add the line
Option  "RegistryDwords" "EnableBrightnessControl=1"
to the device section of xorg.conf] 

3. "I want to be able to use up to 3 displays and turn off the nvidia card when running on battery!" (and I don't mind some extra configuration work)
Ok, so you want to unleash the full power and flexibility of your machine - you're ready to get serious. You definitely must use the "Nvidia Optimus" BIOS mode, which starts both graphics cards. The only way that I have figured out to run all three displays is to use Xinerama to create a single X session with the two external monitors running on the Nvidia card and the Thinkpad display running on the intel card. Using info from these two sites (site 1, site 2), I was able to piece together an xorg.conf file to make it happen. You can download the file here:


To use it, you have to completely exit your gnome/unity/kde/xfce session, including the login screen, and type

startx -- -config xorg.conf.triple.txt

or, if you want to start it automatically every time you start your computer (not recommended), rename it xorg.conf and put it in the correct place (/etc/X11 in my setup). In this configuration (since xrandr is disabled by Xinerama), the only way to change the number of screens is to completely log out of X and use different xorg.conf files for whatever number of screens you have. With this configuration, you can only get 3D hardware acceleration on the external screens running on the nvidia card, and I don't think that it is possible to get desktop effects such as those that are part of compiz running.

In the "Nvidia Optimus" BIOS mode, you can also save power by turning off the nvidia card when you are not using it. This can be accomplished using the bbswitch utility which is part of the Bumblebee project. If you are using ubuntu, you can get bbswitch from the bumblebee repository at https://launchpad.net/~bumblebee/+archive/stable . Instructions for using bbswitch can be found here.

I hope that this post has helped you to understand your computer better, and I hope that you are enjoying your W520 as much as I am!


Notes about my current configuration:
OS: kubuntu 12.04 64 bit
Driver for Intel card: "intel" (DRI (hardware acceleration) is disabled on this (I think because I have the nvidia proprietary driver installed))
Driver for Nvidia card: "nvidia" (proprietary driver 280.13)
Thinkpad model number: W520 4270CTO (with Nvidia Quadro 1000M)
BIOS Display Setting: Nvidia Optimus