Joe Codeswell – Notes to Myself and Others

August 14, 2012

How to manually update Google Chrome

Filed under: Uncategorized — Tags: , — Joe @ 2:11 pm

Background

I didn’t want to run the Google Chrome installer without downloading. After downloading the installer, a warning said that this method sometimes yielded an installation of Chrome that did not automatically check for updates and that it was wise to do that manually.

After searching for a solution for this problem without success, I broke the problem into two parts:

  1. How to Manually Check for Updates.
  2. How to Do the Update if Necessary.

How to Manually Check for Updates

  1. Go to http://googlechromereleases.blogspot.com/
  2. Look for Stable Channel Update
  3. Find the version number for your OS
  4. Click on the Chrome Wrench Icon
  5. Select About Google Chrome

How to Do the Update if Necessary

Selecting About Google Chrome from the Chrome Wrench Icon opens up a dialog that seemingly checked to see if chrome is up to date. In my case it performed the check, and did the update to 21.0.1180.77  from the previous version.

July 28, 2012

How to redirect Python’s sys.stdout to StringIO()

Filed under: Music21, python — Tags: , — Joe @ 10:25 pm

Redirect stdout to StringIO()

The following python code will use the capturePrint function to redirect stdio to StringIO() so you can capture info that would normally just be printed. I tested this using the Music21 .show(‘text’) method.

# capturePrint.py

def capturePrint(executableStrThatPrints):

    import sys, StringIO

    # redir sys.stdout
    stdout = sys.stdout
    sys.stdout = reportSIO = StringIO.StringIO()

    eval(executableStrThatPrints)
    reportStr = reportSIO.getvalue()

    # restore sys.stdout so we can print
    sys.stdout = stdout 

    return reportStr

def testCapturePrint():
    from music21 import *
    global sBach
    sBach = corpus.parse('bach/bwv7.7')
    x = capturePrint("""sBach.show('text')""")
    print x

if __name__ == '__main__':
    testCapturePrint()

July 21, 2012

Run Ipython magic functions from your profile startup python script

Filed under: Music21, python — Tags: , , — Joe @ 9:26 pm

This is the  setup I did for a Music21 project named “chordMe”.

On WIN XP the .ipython configuration dir is in C:Documents and SettingsAdministrator.ipython

Create a profile for your project.

Open a command line shell and type the following to create a new profile

> ipython profile create chordMe
[ProfileCreate] Generating default config file: u'C:Documents and SettingsAdministrator.ipythonprofile_chordMeipython_config.py'

Now add the following python file to:
C:Documents and SettingsAdministrator.ipythonprofile_chordMestartup

000-start.py  file content:
# 000-start.py
# usage:
#     $ ipython --profile=chordMe

import os
from IPython.core.interactiveshell import InteractiveShell 
os.chdir(r"C:/1d/PythonPjs/music21Pjs/chordMePj/chordMe")

# from http://ipython.org/ipython-doc/rel-0.13/api/generated/IPython.core.interactiveshell.html
# run_line_magic(magic_name, line)
# magic_name : str  "Name of the desired magic function, without ‘%’ prefix."
# line : str "The rest of the input line as a single string."

get_ipython().run_line_magic(u"logstart", u"-o ipython_log.py append")
from music21 import *

Running Ipython with the startup commands. 
To the command line say:
> ipython --profile=chordMe

June 30, 2012

Great Comments about my code from MIT’s Music21 creator, Michael Scott Cuthbert

Filed under: music, python — Tags: , , — Joe @ 4:21 pm

Big thanks to MIT’s Music21 creator, Dr. Michael Scott Cuthbert, for his encouraging comments about my code. It’s nice to know that I am staying current and being of service.

He left comments regarding the code that I published:

On Stack Overflow he said, “…your solution is so elegant that we’ve decided to include some code based on it in spirit in the next release (v1.1) of music21″.

On this blog he said, “Thanks for the great post and ideas! We’ll be incorporating something like this in a music21 midi.realtime module… Please feel free to post this to the music21list (Google Groups). People will be interested!” You can see the Google Group re-post here.

Lastly, let me again express my gratitude to Dr. Cuthbert for his encouragement.

Love and peace,

Joe

June 13, 2012

How to produce Python controlled audio output from music made with Music21

Filed under: music, python — Tags: , — Joe @ 7:15 pm

This post was generated from a question I asked and answered here on Stack Overflow.

# genPlayM21Score.py Generates and Plays 2 Music21 Scores "on the fly".
#
# see way below for source notes

from music21 import *

# we create the music21 Bottom Part, and do this explicitly, one object at a time.

n1 = note.Note('e4')
n1.duration.type = 'whole'
n2 = note.Note('d4')
n2.duration.type = 'whole'
m1 = stream.Measure()
m2 = stream.Measure()
m1.append(n1)
m2.append(n2)
partLower = stream.Part()
partLower.append(m1)
partLower.append(m2)

# For the music21 Upper Part, we automate the note creation procedure

data1 = [('g4', 'quarter'), ('a4', 'quarter'), ('b4', 'quarter'), ('c#5', 'quarter')]
data2 = [('d5', 'whole')]
data = [data1, data2]
partUpper = stream.Part()

def makeUpperPart(data):
    for mData in data:
        m = stream.Measure()
        for pitchName, durType in mData:
            n = note.Note(pitchName)
            n.duration.type = durType
            m.append(n)
        partUpper.append(m)
makeUpperPart(data)        

# Now, we can add both Part objects into a music21 Score object.  

sCadence = stream.Score()
sCadence.insert(0, partUpper)
sCadence.insert(0, partLower)

# Now, let's play the MIDI of the sCadence Score 
# [from memory, ie no file  write necessary] using pygame

import cStringIO

sCadence_mf = sCadence.midiFile
sCadence_mStr = sCadence_mf.writestr()
sCadence_mStrFile = cStringIO.StringIO(sCadence_mStr)

import pygame

freq = 44100    # audio CD quality
bitsize = -16   # unsigned 16 bit
channels = 2    # 1 is mono, 2 is stereo
buffer = 1024    # number of samples
pygame.mixer.init(freq, bitsize, channels, buffer)

# optional volume 0 to 1.0
pygame.mixer.music.set_volume(0.8)

def play_music(music_file):
    """
    stream music with mixer.music module in blocking manner
    this will stream the sound from disk while playing
    """
    clock = pygame.time.Clock()
    try:
        pygame.mixer.music.load(music_file)
        print "Music file %s loaded!" % music_file
    except pygame.error:
        print "File %s not found! (%s)" % (music_file, pygame.get_error())
        return
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        # check if playback has finished
        clock.tick(30)

# play the midi file we just saved
play_music(sCadence_mStrFile)

#============================

# now let's make a new music21 Score by reversing the upperPart notes
data1.reverse()
data2 = [('d5', 'whole')]
data = [data1, data2]
partUpper = stream.Part()
makeUpperPart(data)        
sCadence2 = stream.Score()
sCadence2.insert(0, partUpper)
sCadence2.insert(0, partLower)

# now let's play the new Score
sCadence2_mf = sCadence2.midiFile
sCadence2_mStr = sCadence2_mf.writestr()
sCadence2_mStrFile = cStringIO.StringIO(sCadence2_mStr)
play_music(sCadence2_mStrFile)



## SOURCE NOTES
## There are 3 sources for this mashup:

# 1. Source for the Music21 Score Creation http://web.mit.edu/music21/doc/html/quickStart.html#creating-notes-measures-parts-and-scores

# 2.  Source for the Music21 MidiFile Class Behaviour http://mit.edu/music21/doc/html/moduleMidiBase.html?highlight=midifile#music21.midi.base.MidiFile

# 3.  Source for the pygame player: http://www.daniweb.com/software-development/python/code/216979/embed-and-play-midi-music-in-your-code-python

October 22, 2011

GREAT Python lib for Internet Explorer Automation

Filed under: Uncategorized — Tags: , , — Joe @ 6:38 pm

Fabulous, tight, Internet Explorer Automation Python lib. Open in PythonWin to demo all capabilities – form fill, etc. http://www.mayukhbose.com/python/IEC/index.php

June 18, 2011

Post Blast From Windows Desktop by Post.ly to tw,fb,wp,ps

Filed under: python, remote post — Tags: , , , , , — Joe @ 4:15 am

Autopost

Checkout my “Posting From Windows Desktop” previous post on posterous.com It shows Python source code to post to posterous.com.

This post is being autoposted by Post.ly to:

June 9, 2011

Web2py URL Mapping

Filed under: web2py — Tags: , — Joe @ 9:32 pm

URL Mapping from the Book Chapter 4 – Dispatching. These are the basics there’s more detail in the book.

The URL    http://site.com/a/c/f    maps to:

The function f() in controller “c.py” in application “a“.

  • If f is not present, web2py defaults to the index controller function.
  • If c is not present, web2py defaults to the default.py controller.
  • If a is not present, web2py defaults to the init application.
  • If there is no init application, web2py tries to run the welcome application.
  • The extension .html is optional.
  • The extension .html is assumed as default.
  • The extension determines the extension of the view that renders the output of the controller function f().
  • The extension allows the same content to be served in multiple formats (html, xml, json, rss, etc.).

Web2py maps GET/POST requests of the form:

http://site.com/a/c/f.html/x/y/z?p=1&q=2

As before, to function f in controller “c.py” in application a

and it stores the URL parameters in the requestvariable as follows:

    request.args = ['x', 'y', 'z']
    request.vars = {'p':1, 'q':2}
    request.application = 'a'
    request.controller = 'c'
    request.function = 'f'

    request.url = url of request
    request.ajax = False  #by default
    if request.ajax == True and wasInitiatedByAWeb2pyComponent:
        request.cid = componentName

June 8, 2011

Great OAuth Presentation

Filed under: OAuth — Tags: — Joe @ 7:48 pm

This is  a great OAuth presentation by Leah Culver. It has just the right level of detail for me. Here’s the link.

OAuth UML Sequence Diagrams

Filed under: OAuth, UML — Tags: , , — Joe @ 6:34 pm

Here’s two diagrams i found describing the OAuth Workflow.

The first is from dev.twitter due to @idangazit. I found the second on a Japanese website, I believe it is sourced at a VERY COOL website that lets you create UML Sequence Diagrams online, WebSequenceDiagrams.com.

Here is the First from dev.twitter due to @idangazit.

dev.twitter OAuth Workflow

Here’s the second from WebSequenceDiagrams.com

Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.