<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: note code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 00:21:17 GMT</pubDate>
    <description>DZone Snippets: note code</description>
    <item>
      <title>Showing message on status bar</title>
      <link>http://snippets.dzone.com/posts/show/1642</link>
      <description>There's an empty space below app.title that we can&lt;br /&gt;use as a status bar. So, I modify this &lt;a href=http://bigbold.com/snippets/posts/show/839&gt;recipe&lt;/a&gt; and &lt;br /&gt;make it into a module. (need fgimage.pyd from &lt;a href=http://pymbian.sourceforge.net/misc/fgimage-v0.20051022.zip&gt;here&lt;/a&gt;)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# status.py&lt;br /&gt;from graphics import *&lt;br /&gt;import fgimage&lt;br /&gt;__all__ = ["status_on", "status_off"]&lt;br /&gt;&lt;br /&gt;bar = Image.new((119,13))&lt;br /&gt;bgcolor = screenshot().getpixel((0,0))[0]&lt;br /&gt;fg = fgimage.FGImage()&lt;br /&gt;&lt;br /&gt;def status_on(message=None):&lt;br /&gt;    if message is not None:&lt;br /&gt;        bar.clear(bgcolor)&lt;br /&gt;        bar.text((0,11), unicode(message), 0xffffff)&lt;br /&gt;    fg.set(57,30, bar._bitmapapi())&lt;br /&gt;&lt;br /&gt;def status_off():&lt;br /&gt;    fg.unset()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;You can use it easily this way&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; from status import *&lt;br /&gt;&gt;&gt;&gt; status_on('Hello world')  # show it&lt;br /&gt;&gt;&gt;&gt; status_off()              # hide it&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See a &lt;a href=http://www.frappr.com/pys60/photo/1501182&gt;screenshot&lt;/a&gt;.</description>
      <pubDate>Mon, 06 Mar 2006 20:58:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1642</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>MIDI Note number and frequency</title>
      <link>http://snippets.dzone.com/posts/show/1450</link>
      <description>&lt;a href=http://www.harmony-central.com/MIDI/Doc/table2.html&gt;Summary of MIDI Note Numbers&lt;/a&gt;&lt;br /&gt;&lt;a href=http://www.borg.com/~jglatt/tutr/notefreq.htm&gt;MIDI Note to Frequency&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I can use them with my &lt;a href=http://bigbold.com/snippets/posts/show/572&gt;midi snippet&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# from http://logic-users.org/forums/L-OT/295&lt;br /&gt;# Each note's frequency is 2^(1/12) times of the previous note.&lt;br /&gt;&lt;br /&gt;freq = 440 * 2^((n-69)/12)&lt;br /&gt;n = 69 + 12*log(freq/440)/log(2)&lt;br /&gt;&lt;br /&gt;# Doe, ray, me, fa, sol, la, tee, doe&lt;br /&gt;&gt;&gt;&gt; play([(i, 100) for i in [60, 62, 64,65, 67, 69, 71,72]])&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 10 Feb 2006 08:27:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1450</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>appuifw.note allow global note in pys60 1.3.1</title>
      <link>http://snippets.dzone.com/posts/show/1356</link>
      <description>&lt;code&gt;&lt;br /&gt;# note in 1.2 &lt;br /&gt;note(text, type)&lt;br /&gt;# note in 1.3.1&lt;br /&gt;note(text[, type[, global]])&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;type = 'info' (default) or 'error', 'conf'&lt;br /&gt;global = 1    # display even if app is in background&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import appuifw&lt;br /&gt;appuifw.note(u'Hello World')             # simplest case&lt;br /&gt;appuifw.note(u'Cannot connect', 'error') # show error&lt;br /&gt;appuifw.note(u'New message', 'info', 1)  # alert from background&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 05 Feb 2006 20:42:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1356</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Using foreground image</title>
      <link>http://snippets.dzone.com/posts/show/839</link>
      <description>You can draw directly to the phone screen.&lt;br /&gt;It is useful for a notification from a background program.&lt;br /&gt;You need to install fgimage.pyd from &lt;a href=http://pymbian.sourceforge.net/misc/fgimage-v0.20051022.zip&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import fgimage, e32&lt;br /&gt;&lt;br /&gt;img = Image.new((100, 16))  # create a notification text&lt;br /&gt;img.text((0, 14), u'Hello world', 0)&lt;br /&gt;&lt;br /&gt;fg = fgimage.FGImage()&lt;br /&gt;x, y = 0, 40           # position to draw&lt;br /&gt;fg.set(x, y, img._bitmapapi())  # send it&lt;br /&gt;&lt;br /&gt;e32.ao_sleep(1)&lt;br /&gt;fg.unset()                # then clear it&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;See (a bit) more discussion &lt;a href=http://discussion.forum.nokia.com/forum/showthread.php?t=68866&gt;here&lt;/a&gt;.</description>
      <pubDate>Mon, 31 Oct 2005 00:26:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/839</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Generate and play midi on mobile phone</title>
      <link>http://snippets.dzone.com/posts/show/572</link>
      <description>From a previous snippet, you can play any sound file&lt;br /&gt;(including midi) with pys60. &lt;br /&gt;http://bigbold.com/snippets/posts/show/400&lt;br /&gt;&lt;br /&gt;Now, what if you can generate a midi file as well?&lt;br /&gt;I found a pure python midi file library.&lt;br /&gt;http://www.mxm.dk/products/public/pythonmidi&lt;br /&gt;&lt;br /&gt;I modify it a bit, just to make a single file for easy download.&lt;br /&gt;http://larndham.net/service/pys60/smidi.py&lt;br /&gt;With it, you can play a single note with the following code.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; import smidi&lt;br /&gt;&gt;&gt;&gt; m = smidi.MidiOutFile('C:\\out.mid')&lt;br /&gt;&gt;&gt;&gt; m.header()&lt;br /&gt;&gt;&gt;&gt; m.start_of_track()&lt;br /&gt;&gt;&gt;&gt; m.update_time(0)&lt;br /&gt;&gt;&gt;&gt; m.note_on(note=0x40)  # single note&lt;br /&gt;&gt;&gt;&gt; m.update_time(192)&lt;br /&gt;&gt;&gt;&gt; m.note_off(note=0x40) # stop it after 192&lt;br /&gt;&gt;&gt;&gt; m.update_time(0)&lt;br /&gt;&gt;&gt;&gt; m.end_of_track()&lt;br /&gt;&gt;&gt;&gt; m.eof()&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; from audio import Sound&lt;br /&gt;&gt;&gt;&gt; s = Sound.open('C:\\out.mid')&lt;br /&gt;&gt;&gt;&gt; s.play()&lt;br /&gt;&gt;&gt;&gt; s.close()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;These 10 lines can be made into a simple function.&lt;br /&gt;Then, you can just type a line and play any note you like&lt;br /&gt;on you mobile phone.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; from smidi import play&lt;br /&gt;&gt;&gt;&gt; play([(64,192), (32, 192)])&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Ah... so pythonic. ^_^</description>
      <pubDate>Wed, 10 Aug 2005 00:37:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/572</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
