Tuesday 18 November 2014

Adventures in Sonic Pi

Well what a fun few weeks this has been getting to this point. I had been aware of Sonic Pi for quite a while, but not having a Mac or easy access to my Raspberry Pi I hadn't been able to play much. This all changed with the release of the PC edition. With easy access to desktop PC's and laptops around the house I could play to my hearts content.

Like everyone else I started by looking at examples and what others had already done, there was so much creativity out there. One of the first things I came across was Robin Newman's blog and his posts about using a limited set of samples of a Grand Piano to create an instrument that could play a much wider range of notes (here). I liked the technical aspect of this but wondered if the concept could be made more accessible.

I set about attempting to create a Ruby class that would provide the same functionality. After plenty of reading up on Ruby (its not a language I usually develop in) and a few coding dead ends, I ended up with a couple of Ruby classes that did the job. Of course just releasing this code would have been no fun at all, people want to hear Sonic Pi playing music. So I set about putting what I had just created to use and coded a version of "The Entertainer".

If you want to jump direct to the code then I've dropped it on a Gist here and the required Grand Piano and Clarinet samples taken from the fantastic Sonatina Symphony Orchestra resource are in a zip file here (Google Drive has a download link at the top of the page). Once downloaded remember to change the use_sample_pack (line 143) to point at the location you have extracted the samples to.

If you just want to enjoy this rendition of  "The Entertainer" then the mp3 file can be found here (again Google Drive has a download link at the top of the page if required).


So you want a bit more of a breakdown of what I created?

First I created a class that all it does is play a specific note from a given sample (line 5). Each instance of the class contains the name of the sample to be played and amp, attack, rate, release and sustain settings. When the play method is called a duration is passed and is combined with the attack, release and sustain settings. These three settings are more reflecting how much of the duration should be spent doing each and in total should add up to 1. If they don't this will shorten or lengthen the requested duration. This feature can be turned to our advantage by allowing the note to carry on longer than the requested duration. This is done by the three settings totalling up to a number greater than 1. This would allowing, for example, piano strings to ring for slightly longer.

Next I created a class that contained all the samples for an instrument (line 55). Each of the 128 midi notes is mapped to their nearest sample and appropriate playback rate calculated. Every time a new sample is added it first inserts itself at the correct position before making sure that neighbouring notes use the nearest sample. For each of the notes an instance of the note playing class is created and held in an array.

Now how are these two classes put to use. Well everything is done through the second, instrument bank class. First a new instance of the class is created (line 146) passing in a reference to Sonic Pi itself. Next all the samples are loaded (line 147 - 153) each defining which base note the sample is for (in either midi number or note symbol) and what sample to use (either as file name in the sample pack folder or by sample symbol). Finally you can amend any required settings (line 154) from the internal defaults provided. At this point your new instrument bank is ready to go. All you have to do to play a note is call the play method passing in a note (again in either midi number of note symbol) and a duration. Also if you want to play a chord just pass in an array of notes.

The Entertainer (line 140) is played by creating three arrays of notes and durations (one for clarinet, one for grand piano right hand and one for grand piano left hand). A synchronisation thread is started whose only task is to provide the cues for the threads playing each of the arrays. As these threads receive the cues they count them and play the appropriate note for the required duration.

This is my first Sonic Pi project and I'm not even sure I've finished it yet. But as I thought that it was at a good point I thought it was worth sharing. It would be great to hear what you think of it or if you have any questions then please ask away.

Saturday 21 June 2014

Playing in a Dome

I love going out and creating spherical panoramas of the places I visit, its a fantastic way to capture some amazing sights. But after I've created them I'm left with the same ways to visualize them, either using some sort of interactive viewer or a flat static view which sort of removes the immersive 360° experience. Well luckily for me I've recently had the offer of a third way of viewing my work, in a 180° dome.

Last October (2013) I visited an Art event in Birmingham called Illuminate and as the name suggests it was all to do with light. The bit that I was interested in experiencing was the 360° Panoramic Cinema, not a full dome projection but a cylindrical slice all around the walls. It was here I met Toby Norman-Wright and Mario Di Maggio and got discussing my panoramas with them. I was told by Mario about another event he runs in Birmingham on a regular basis called Dome Club and I was invited to bring along some of my content to be shown.

Now we fast forward to today. After some initial experiments with preparing content for a dome, only showing an 180° view meant that you would only experience the world from the horizon up (or maybe slightly tilted forward). I started thinking about showing more, seeing a bit of the floor too. This presented it's own problem. The projection that the dome required was circular fisheye so expanding the view to 250° was not a problem. What was a problem is that the view would be distorted making buildings tower in above you and to correct this I would need to re-map my images. After a bit of scribbling ideas on paper, some Maths and a Python script to do the work my images were re-mapped and ready for projection.

I visited Dome Club being held at the Q Club Complex in Birmingham on Friday 13th June and there I was able to experience my work being projected in a 7 meter dome. I had given Mario both original and re-mapped 250° views so that comparisons could be made to judge if the re-mapping was a success and in my eyes it was. Vertical edges now appeared vertical (again) and the ceiling didn't seem so distant. It's truly a great way to re-live the immersive experience of the original panoramic image.

My static panoramas wasn't the only content that I took to Dome Club, I also took Giroptic's demo panoramic video from Times Square in New York shot on their amazing 360Cam. I converted the original 360° x 180° equirectangular projection to a re-mapped 250° fisheye. This was a bit of an experiment for me as I hadn't worked with panoramic video before and the 360Cam is still only a kickstarter project (over $1.1 million funded project at the time of writing!). The immersive experience was outstanding and from such a small handheld device. It really did show what will be possible for content creation that is then shared with a mass audience. Truly interesting times for spherical panoramic video and an area that I want to carry on experimenting with.

For anyone interested in seeing what a re-mapped 250° fisheye video looks like you can see the Time Square demo video over on my YouTube channel here http://youtu.be/VUZKKxP1DYA.

Tuesday 20 May 2014

An MP Came Visiting

23:04 Posted by Unknown , , No comments
Back at the end of March I was lucky enough to be invited by Code Club to attend Parliament and be part of a drop in session for MPs. I was 1 of 5 volunteers who got to talk to MPs about what a great thing Code Club was and what the children were learning from it. Along with the volunteers being invited, the volunteers local MPs were also invited to find out what was being taught in their constituencies, for me this was Harriett Baldwin MP. I had a fantastic meeting with her in Portcullis House where she showed interest in the whole subject area and could see the benefits the children were getting. Before she left she asked if it would be possible to visit my Code Club back in Malvern and meet the children herself. After checking with the school that it was ok a visit was scheduled for Friday 16th May.

On the day of the visit there was much excitement within the club with everyone waiting for our guest to arrive, some having stories to recall about them or another family member meeting Harriett. She arrived with her Senior Parliamentary Assistant Edward Davies and was soon being introduced to everyone. I quickly showed her the progression the children had made during this academic year, showing her examples projects first from scratch, then HTML & CSS before finishing on the Python project that they were working on that week. She was amazed by the creativity shown by the children, all starting on the same project but including their own interpretations by the end. She was also pleased to see girls learning to coding too and was eager to encourage more girls to learn theses skills. She talked to everyone and really engaged with the children finding out what each of them was doing and how they were finding the club.

All too quickly we were at the end of the club. She thanked the children for showing her their club and they thanked her for visiting too. Before Harriett had even arrived she had already got 2 more Malvern schools interested in running a Code Club and she asked me what else was needed. I replied with Code Club providing all the required projects and support for free all the was needed was more me's! Other volunteers with IT backgrounds that are enthusiastic about wanting to teach Computational Thinking and coding to the next generation of children. So to help towards this she said that she would talk to other IT companies on the Malvern Hills Science Park (where she has her constituency office) and also other companies that she came in contact with. In the days after the visit a press release was written to publicize the visit and the benefits the children were get from the club. Hopefully the local press will pick this up and even more people will hear about Code Club.

Additional links
HarriettBaldwin.com - MP meets new generation of Malvern’s brilliant brains

Friday 9 May 2014

Keeping the Code Club Projects With You

13:34 Posted by Unknown , , , No comments
Having a copy of the Code Club projects to hand can be really useful. Sometime you might want to look something up while another time you might want to show a potential volunteer how great the resources are. Originally I had a copy of all the project PDFs on my Nexus 7 and could access them via a shortcut on my home screen that would take me to the top folder. This method was ok but with all the projects getting refreshed and being hosted on GitHub I thought that there must be a better way.

With the ability to download a zip file containing the projects area of the Code Club website from GitHub (https://github.com/CodeClub/CodeClubUK-Projects) I decided that this was what I wanted loaded on my tablet. After expanding the zip file I place a shortcut to the top webpage page on my home screen using ES File Explorer (as I had done with my previous solution). Again this was ok but  but I wasn't quite happy with the result. While previously I was left with a folder structure to navigate through this time I was given a generic html icon that I thought could look better.

After a bit of investigation I came across an interesting feature that was released with build 31 of the Chrome browser for Android (https://developer.chrome.com/multidevice/android/installtohomescreen). When you view a webpage through Chrome you can choose to place a shortcut on your home page that when clicked takes you directly to that page. Even better than that was you could have the page opened in full screen (like an application) and have a personalised image used for the shortcut icon on your home screen. All this is controlled by three extra lines in the head section of the page your interested in linking to.

So I edited the top index.html file in projects zip file downloaded from GitHub. Just below the existing meta tags in the header section I added the following;

<meta name="mobile-web-app-capable" content="yes">

This would open the page in full screen. For the personalised icon I had to provide an image at two sizes (128x128 pixels and 196x196 pixels). This would allow the best icon to be used dependant on what the screen resolution of the device being used was. Copies of my images can be found at the following links;

ccuk_logo_128x128.png
ccuk_logo_196x196.png

I placed copies of these images in the img folder found along with the index.html file. Next I inserted references to the images in the index.html file. Just below the existing link tags in the header section I added the following;

<link rel="icon" size="128x128" href="./img/ccuk_logo_128x128.png">
<link rel="icon" size="196x196" href="./img/ccuk_logo_196x196.png">

Next I had to open the index.html file in Chrome, not as easy as it sounds. The method I used was to open ES File Explorer, select the file, chose to open as, when presented with a list of what to open it as to choose other and finally when presented with a list of applications to choose Chrome. Now this will open the page like normal, not full screen just yet. Next from the drop down menu I chose to Add to home screen and from the dialogue that appeared I named it UK Projects. After clicking add I got a Code Club logo on my home screen that when clicked launches like application. Unfortunately it is slightly spoilt by a line appearing at the top showing that page is being loaded directly from the internal memory. You can get rid of it but you have to load the pages through a local HTTP daemon and I'm not that bothered by the text.


Friday 25 April 2014

Code Club, between terms

07:27 Posted by Unknown , , No comments
Well one term finished and a new one not too far off at Malvern Wells Primary school. Looking back it's amazing to think what the children have covered at Code Club since the beginning of the year and how well they picked everything up. Not all the children learn at the same speed, but with a few nudges in the right direction everyone gets there. The Autumn term was all Scratch, and what a fantastic place to start. We covered everything from a cat chasing a mouse to fish chomping and racing across a desert to a simple drawing package. The children took everything in their stride, like giant knowledge sponges.

For the spring term, we changed direction a bit, looking at HTML & CSS. Gone was the wonderful drag and drop interface, replaced with a keyboard and commands to type. Would this put the children off? Would it not be as fun any more? I needn't have worried, they picked everything up at the same break neck speed and were soon coding HTML tags and CSS styles without an issue.

First they created their own "Lost Cat" web page, that definitely weren't identical pages. Each child brought their own creative skills to the task, interpreting it in their own way. For some colours and styles were important, expanding on what they had learnt while others brought their own flare to the text, expanding on their story of the lost cat. A real moment of achievement came when they found out that the pages they had created would be uploaded to the Internet using TeePee.io for the world to see. For such a small task the ability to have a URL they could take home to show their parents what they had created was a real reward for the children.

After this we moved onto hiding Ninjas around a town using positional CSS. This time there was different units of measure to get to grips with and after a bit of trial and error the concepts were grasped. Some of the children repeatedly tweaked their Ninjas positions to make sure that the smallest piece of hand or foot couldn't be seen while others placed all theirs in the same place resulting in a squash of Shinobis behind a skip!

Finally they got to use their creative skills to build their own website on any subject they wanted. Some took a topic areas that they had already covered in class while others embedded YouTube videos that they wanted to share. It really showed what they had learnt in such a short time.

I'm now looking forward to the Summer term and teaching the children Python, but this required a bit more planning. For the first term the school already had Scratch installed and for the second term we used notepad and the Chrome browser, but Python was something different. Luckily the school has a technician on rota and I got my request in for Python to be installed early enough so that by the end of the Spring term we were ready to go. It'll be an exciting time getting the children to put together what they have learnt in the first two terms. From Scratch they will be able to take all the programming concepts, loops, conditions and logic flow and combine that with the art of typing syntax (and making sure its right) that they learnt with HTML & CSS. Maybe even for the final lesson I might let them have play with Python and Minecraft on my Raspberry Pi, but this will be a surprise, so keep it under your hat.

Wednesday 23 April 2014

Playing with Google Map Views

If you just want to get straight to the tour, follow the following link:
https://www.google.co.uk/maps/place/Great+Malvern/@52.110278,-2.330287,3a,90y,240.55h,90.68t/data=!3m5!1e1!3m3!1s8VPHNkPUB-QAAAGuqllMng!2e0!3e11!4m2!3m1!1s0x4870f8ee8ec8d3fb:0xad5d1163a51c6fd


After reading about the launch of Google Map Views (http://maps.google.com/views) I thought that I would give it a go and add my own spherical panoramas to Google's Street View eco-system. There seemed to be plenty of people uploading single panoramas but I wanted to give their tour builder a try. Not wanting to start too big I chose Rose Bank Gardens in Malvern as a location to photograph. It's a small park in the centre of Malvern with a little network of paths and few entrance / exit points.

Now here is where I hit my first problem, Rose Bank Gardens wasn't mapped on Google Maps. Without this I would be dropping my panoramas into the middle of no-where. Luckily Google already had this covered with Map Maker (http://www.google.co.uk/mapmaker). It allows anyone to update Google's maps with new or corrected content. Unfortunately updates made to any of these systems aren't instantaneous and each application comes with its own learning curve. The major thing that slows down map updates is the fact that they are peer reviewed. Now in an area where there is lots of activity this might be quite a swift but here in the UK and more importantly the Malvern area it took a while. But after a few revisions I had completed the basic network of paths (I say basic because there are a few that at the time of writing I haven't yet created) and this then allowed me to move onto the next step, Google Map Views.

First I needed to shoot the panoramas. Luckily I had already shot a view by of Walenty Pytel's Buzzards sculpture so that was one down straight away. I picked a bright and sunny Sunday morning to visit Rose Bank Gardens, camera and tripod in hand. As I walked through the park I stopped at key points to shoot panoramas and by the end I had shot 23 new panoramic views. After a bit of processing at home I had 24 jpeg images ready to upload (I had to shrink my original images to meet Google's requirements). Now comes the convoluted bit, first I had to insert some metadata into my jpeg images to get Google to recognise them as panoramas. Luckily Google came to the rescue again providing a web application to do this (http://photo-sphere.appspot.com/).

Next I needed to upload my panoramas to somewhere. Now everything you do with Google is authorised through your Google account and this is no different. I had to upload my 24 panoramas to my Google Plus photo library from where I could finally add them to Google Map Views. Now all this might sound a bit long winded but some of it is being caused by the fact I shoot with my DSLR. Google's preferred route is to use an Android phone which would automatically do a lot of the steps for you.

With all 24 of my panoramas being shown on a map it was a process of placing each panorama in it's correct position, making sure north was pointing north and linking each panorama to each other. Now here is where the next delay came in, to make your panoramas visible to the public they have to be processed by Google. This time it's an automated system that looks at each panoramas to see if it is going to be accepted. Most of mine were accepted first time but a few were rejected due to my copyright notice being outside an acceptable area (not that I could find this area defined anywhere) and one which was rejected for an unknown reason that I had to take up with their support staff. Once they were all accepted the tour was visible for the world to see. To take a virtual wander around Rose Bank Gardens yourself you can follow the following link which will place you at the Belle Vue Terrace entrance:

https://www.google.co.uk/maps/place/Great+Malvern/@52.110278,-2.330287,3a,90y,240.55h,90.68t/data=!3m5!1e1!3m3!1s8VPHNkPUB-QAAAGuqllMng!2e0!3e11!4m2!3m1!1s0x4870f8ee8ec8d3fb:0xad5d1163a51c6fd

So what have I learnt through this process? Well with everything being for free don't expect things to happen at the drop of a hat and expect to have to jump through other peoples hoops not ones created by yourself. As for my tour, it uses a method of navigation that people are becoming more and more familiar with all the time which hopefully means less people being stuck on the first view not knowing what to do next. The only warning I give is that if you navigate from one of my panoramic views to a Street View view then currently there's no way back! Outside my tour I've done my small bit to improve the mapping of Malvern by defining Rose Bank Gardens.

Finally what next? Well I want to complete the Rose Bank Gardens tour but I'm going to wait until a fallen stone wall has been fixed (you can see it from the Wells Road entrance). After that who knows, there are plenty of other places to create tours for in Malvern that the Street View Car can't get to, maybe Priory Park?

Sunday 13 April 2014

10 years of panoramic imaging

Ten years of doing anything nowadays is an achievement and I can hardly believe it myself. I started created spherical panoramic images (that's the kind where you can look all the way round as well as up and down, just like Google Streetview) during the August bank holiday weekend 1999 but it wasn't until the beginning of 2004 that the World Wide Panorama project started. Up to this point there had been other panoramic photography events on the Internet but these were organised in a more ad-hoc style. This project brought a structure detailing 4 time periods each years (the solstices and equinoxes) and a clearly defined theme for each event.

During this time I have submitted 62 panoramas across a wide range of themes. From Bridges to Decade and Culture to Gardens. But the one thing I have tried to stick to is to stay local, to the extent that two thirds of my panoramas have been shot within 12 miles from home (and quite a few not too much over this either). Here in Malvern I am spoilt for choice for locations. There is everything from old and historic to new and modern and the Malvern hills form a fantastic divide between the more populated Worcestershire from rural Herefordshire.

Another thing that the event has provided me with is a fantastic snap shot of my last 10 years, with each panoramic image bringing back memories. Some I shot by myself, others with the family, but I remember them all. The winter solstice events always has a theme of best of the year which has allowed me to show views from further afield like the Eden Project at night, a small red phonebox being used as a gallery and the bomb bay of a Vulcan bomber.

The World Wide Panorama project is something I enjoy doing and I look forward to each theme being announced. Now I'm looking forward to the next event the Summer solstice on the theme of Work.

Wednesday 9 April 2014

Code Clubs 2nd Birthday Party

23:25 Posted by Unknown , , No comments
Just where have the 2 years gone. When the party was announced I knew I wanted to be there, but it was no simple hop across London for me. Trying to get there from Worcestershire means leaving early afternoon. Luckily I have relatives in Surrey so that gives me a place to stay overnight that isn't too far from London. So after a quick pit stop I was on a train London bound. An hour and a quarter later I was outside the Seven Dials Club, Earlham Street.

To chat with people I have met before and others I hadn't was great, such a wonderful melting pot of ideas. We all had experiences to share and some fantastic ideas were discussed. I know I chatted with loads of people but names have never been my strong point. It was also good to be reminded what Code Club had achieved in the last 12 months and see what they were planning for the next, it's definitely not going to be a year of standing still. With the new primary computing curriculum this autumn it's definitely going to be a very interesting time ahead.

But the evening wasn't all chat. There was some delicious large chocolate discs that contained popping candy sent over by Code Club Luxembourg, sandwiches, plenty of sweets, cupcakes and a free bar. Being projected on a screen there was a huge multi-ball game of pong written by a volunteer and controlled using a makey makey board and some playdough (I just love these boards, so many possibilities). Thanks go to Twilio who sponsored the event.

By the end of the evening I was darting back across London to get my train to Surrey, cupcake and sweets in hand, happy that I had been able to chat with so many people. A really enjoyable night.

Monday 7 April 2014

A Visit to Parliament!

All blogs have to start somewhere and mine starts here. Recently I was invited by Code Club to be part of a small group to visit Parliament, an honor in my eyes to be asked. On the 25th March I headed down to London and Portcullis house for a 2 hour drop in session where MPs could come along and find out more about Code Club and what the children are being taught in these after school clubs.

I arrived at my destination with plenty of time and was soon clear of the airport style security and armed police. The setting up of the room was frantic with laptops and flat panel TVs being unpacked and set-up. My job along with the other volunteers who were was to give the MPs a real hands on experience of the Scratch environment and the projects that we teach.

The whole event was being sponsored by Samsung and the shadow minister for employment, a Stephen Timms MP (someone who I wouldn't recognise, but more about that later). The order of things was that each MP would be greeted on arrival by representatives from Samsung and Code Code before being passed over to a volunteer. After we had finished being enthusiastic they would then be asked to nominate a local public venue where a Code Club could be run in their constituency. The reason for this was that Samsung were going to help set-up 5 clubs around the UK (from the suggestions provided) providing hardware and resources.

Well the 2 hours soon passed which during I spoke to at least 5 people at length. Each MP seemed interested in the subject and what we were trying to achieve and all providing me with a good level of questioning.

Out of these 2 MPs stuck in my mind. The first was a male MP who presented me with his business card on arrival. I gave him the full tour of Scratch and what we are doing and even challenged him to an game of desert race (of course I let him win) and he went away seeming happy with what he had learnt. Afterwards a Samsung representative asked me if I minded appearing press releases and I replied that I didn't (its good for my ego). It was only afterwards, when press releases appeared, that I realised that this was Stephen Timms MP!

The other MP was my local MP, Harriett Baldwin. All of the invited volunteers had their local MPs invited so that they could find out what was happening in their constituency. On top of this I had tweeted Harriett personally on the Sunday with a gentle reminder which she swiftly replied to confirming her attendance and the fact she was looking forward to finding out more.

On her arrival we recognised each other and I was soon showing her everything about Scratch, what we were teaching to the children and why what we were doing was so important for the children's futures. She could see the potential benefits and was interested in visiting my club and seeing the children at work herself. She hoped that her visit would help drum up some additional local interest too. After my time with her she moved on and nominated the Malvern Cube as a public venue that could run a Code Club in Malvern. It was real pleasure to meet Harriett.

So now I'm in discussion with Harrietts office arranging dates as to when she could visit. My school is on board too thinking it would be a great thing for the school. With Malvern containing such a hub of technology companies it would be great for more Malvern schools to have their own Code Clubs. This year holds some great possibilities for Malvern and Code Club.