About this Blog

fGroove is a audio loop player that allows multiple people to select audio loops that will play in time and at the correct tempo. Think of it as a multitouch version of a groove matrix. Note, I'm just learning to program the surface. While code examples here should work, they may not be the "correct" or "official" way of doing things

Monday, December 21, 2009

Surface development on a macbook ?

I wanted to see if I could do some surface development on a macbook over the Christmas period. I have tried it before under VM Fusion with no look so I thought I'd try bootcamp. However it looks like it's no go on this 13inch Macbook because of the screen resolution. The windows surface simulator requires a resolution of 1280*900 but this little mac only offers 1280*800. Ho Hum.

Sunday, December 20, 2009

onHold Vs Sizechanged (and possibly rotate)

One thing I'm finding when programming for the Surface is that if you trap one Gesture it will upset the operation of another gesture. So for instance (in my program) the PreviewContactDown is trapped to start a trap operation, this was also used to start a drag and drop operation, which interfered with each other. So I decided to start a drag drop operation by trapping the PreviewContactHoldgesture for the Scatterview item.

This though has a side effect. If a user tries to resize (and probably rotate) a scatterviewitem then one finger has to placed on the item and held. This will fire the PreviewContactHoldgesture for that item. So inside the PreviewContactHoldgesture handler, once the item that is being operated on then you need to find the number of contacts on that item. if it's more than one then it's not a plain Hold gesture. Here's the code I used:

int ContactsCaptured=draggedElement.ContactsCaptured.Count;
if (ContactsCaptured > 1){
//We may be rotating or scaling so we don't want to drag and drop
return;
}

Friday, December 18, 2009

Solved: LibraryStack vs PreviewContactTapGesture

Possibly the easiest way to solve the problem of LibraryStack controls not responding to PreivewContactTapGestures is to embed them into a ScatterViewItem on the ScatterView

In the XAML






In the C# code create a new Libraryview:

LibraryStack lbs = new LibraryStack();
lbsItem.Content = lbs;
lbsItem.PreviewContactTapGesture += new ContactEventHandler(SurfaceWindow1_PreviewContactTapGesture);

Now the ScatterViewItem with a LibraryStack in it will react to the tapgesture.

Library Stack vs PreviewContactTapGesture

So now I've got scatterviewitems being added to the library stack the next task is to get a tap gesture on the librarystack to trigger all the loops held in the stack. This should just be as easy as:

lbs[0].PreviewContactTapGesture += new ContactEventHandler(SurfaceWindow1_PreviewContactTapGesture);

However that doesn't seem to work in my application. I suspect that it's because of the way I've added the LibraryStack. Here's the Xaml for the surface window.







Grid.Column="0"
x:Name="MainScatterView"

ItemTemplate="{StaticResource ScatterViewItemDataTemplate}"
ItemsSource="{Binding SourceItems}"

s:Contacts.PreviewContactTapGesture="onPreviewContactTapGesture"
s:Contacts.PreviewContactHoldGesture="MainScatterView_PreviewContactHoldGesture"
s:SurfaceDragDrop.DragCanceled="OnDragCanceled"
s:SurfaceDragDrop.DragCompleted="OnDragCompleted"
s:Contacts.ContactChanged="MainScatterView_ContactChanged"
/>
x:Name="LibraryScatterView"
Grid.Column="0"
>





The LibrarySyack is just added to the LibraryScatterView item, which I suspect is capturing the tap gestures. Lets see what a few experiments turn up.

Thursday, December 17, 2009

Adding a Library Stack

The next job was to add a library stack. The idea is that ScatterViewItem's (with the audio loop attached ) can be drag and dropped into a LibraryStack and will then be grouped together. Tappping on the Library stack will make all loops in the stack play together. This didn't sound too hard but I've found it harder than expected.

First job, get an example program working. In the Surface SDK help files there is a programmers guide, with a section "Using the Drag and Drop Framework" with a section "Dragging and Dropping Items from ScatterView Controls to SurfaceListBox Controls". Changing this to drag and drop to a Library Stack was quite easy. Integrating it with my current program was hard. First problem, the example program use ObservableCollections to bind to the Scatterview and LibraryStack in the XAML. The easiest thing to do was change my original program to follow this pattern.

Second problem is that Example program uses the PreviewContactDown event to begin the drag and drop operation. Thats the same event that the current program uses for tap handling. Look at this video and you'll see that the tap event only happens some of the time. The easy fix was to use a PreviewContactHoldgesture to begin the drag-drop action. It's a bit of usability scutter but seems to work.

The current problem is that although loops play in the LibraryStack, if you add a loop while the stack is playing, it plays when the stack is stopped. The solution hopefully is to add code that checks to see if the stack is playing when the drag is finished and add that loop to the playlist. This should be the SurfaceDragDrop Drop handler. Except it doesn't seem to get activated in the current program. Ho Hum.....

And a quick test with the original Drag Drop code seems to suggest that a LibraryStack does not generate a onDrop Event, but changing it to a PreviewDropHandler does trigger the event. Looks solved now.

Video of Second version

Here's a the second version of the program, this uses loops from the "Eat Static" sample disk "Around the world in 80 Raves" and vocal samples from old films (from archive.org). The video shows loops playing in time, altering volume and stopping and starting loops to join vocal samples together. (this seems to have lost it's sound, I'll need to fix that)


Initial Video

A video of the very first prototype is available here:

http://www.youtube.com/watch?v=KNT_reCqeak

This early version uses loops from :

http://www.soundstosample.com/info/Zenhiser/Late_Night_Techno_Grooves_2/398