hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Exploring Python-Timidity

Thu Aug 09, 2018 6:07 pm

Terminal left open:

Code: Select all

Timidity -iA
In terminal #2:

Code: Select all

sudo modprobe snd-virmidi
aconnect 20:00 128:00
Using Thonny (shell as display)

Code: Select all

ptch=["Grand Piano","Bright Grand","Electric Grand","Honky Tonk",
      "Rhodes","Chorus Piano","Harpsichord","Clavichord",
      "Celesta","Glockenspiel","Music Box","Vibraphone",
      "Marimba","Xylophone","Tubular Bells","Dulcimer",
      "Hammond Organ","Percussion Organ","Rock Organ",
      "Church Organ","Reed Organ","Accordian","Harmonica",
      "Tango Accordian","Acoustic Nylon Guitar",
      "Acoustic Steel Guitar","Electric Jazz Guitar",
      "Electric Clean Guitar","Electric Mute Guitar",
      "Overdrive Guitar","Distorted Guitar","Guitar Harmonic",
      "Acoustic Bass","Electric Bass Finger","Electric Bass Pick",
      "Fretless Bass","Slap Bass One","Slap Bass Two",
      "Synth Bass One","Synth Bass Two","Violin","Viola","Cello",
      "Contrabass","Tremolo Strings","Pizzicato Strings",
      "Orchestra Harp","Timpani","String Ensemble One",
      "String Ensemble Two","Synth Strings One","Synth Strings Two",
      "Choir Ahhs","Voice Oohs","Synth Voice","Orchestra Hit",
      "Trumpet","Trombone","Tuba","Mute Trumpet","French Horn",
      "Brass Section","Synth Brass One","Synth Brass Two",
      "Soprano Sax","Alto Sax","Tenor Sax","Baritone Sax","Oboe",
      "English Horn","Bassoon","Clarinet","Piccolo","Flute",
      "Recorder","Pan Flute","Bottle Blow","Shakuhachi","Whistle",
      "Ocarina","Square Wave","Sawtooth","Calliope","Chiff Lead",
      "Charang","Solo Synth VX","Brite Saw","Brass and Lead",
      "Fantasia Pad","Warm Pad","Poly Synth Pad","Space Vox Pad",
      "Bowed Glass Pad","Metal Pad","Halo Pad","Sweep Pad",
      "Ice Rain","Sound Track","Crystal","Atmosphere","Brightness",
      "Goblin","Echo Drops","Star Theme","Sitar","Banjo","Shamisen",
      "Koto","Kalimba","Bagpipe","Fiddle","Shanai",
      "Tinkle Bell","Agogo","Steel Drums","Wood Block","Taiko Drum",
      "Melodic Tom","Synth Drum","Rev Cymbal",
      "Guitar Fret Noise","Breath Noise","Sea Shore","Bird Tweet"] 

import pygame; pygame.init()
pygame.display.set_mode([1,1])
fo=open("/dev/snd/midiC1D0","wb",0)
note=60; patch=0
print("Any arrow key to start")
while True:
  for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_UP:
        note=note+7
      if event.key == pygame.K_DOWN:
        note=note-7
      if event.key== pygame.K_RIGHT:
        patch=patch+1
      if event.key==pygame.K_LEFT:
        patch=patch-1
      for off in range(note-2,note+2): 
        mmsg=[144,off,0];fo.write(bytes(mmsg))    
      mmsg=[192,patch];fo.write(bytes(mmsg))  
      mmsg=[144,note,127];fo.write(bytes(mmsg))   
      print()
      print()
      print("  Up - Down  arrows for note  =", note)
      print("Left - Right arrows for patch =", patch, ptch[patch])
      print("                    Frequency ~", round(2**((note-69)/12)*440),"Hz")          

DirkS
Posts: 8841
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Exploring Python-Timidity

Thu Aug 09, 2018 6:36 pm

And the point of this is... ?
You should make it clear what the purpose of a post is (question, how-to, just showing something off).

hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

As the title suggests ...

Thu Aug 09, 2018 7:00 pm

> And the point of this is... ?

DirkS
Posts: 8841
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: As the title suggests ...

Thu Aug 09, 2018 7:14 pm

hitsware wrote:
Thu Aug 09, 2018 7:00 pm
> And the point of this is... ?
Not clear what I'm asking?
Re-read the second line.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20253
Joined: Sat Jul 30, 2011 7:41 pm

Re: Exploring Python-Timidity

Fri Aug 10, 2018 12:18 pm

To the OP, can you improve your post by creating a more descriptive title, and also putting some more information in the post itself - its difficult to know what you are asking.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Exploring Python-Timidity

Fri Aug 10, 2018 1:36 pm

I'm not asking anything.
I thought I was presenting something
that might be of interest or use.
My mistake.

DirkS
Posts: 8841
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Exploring Python-Timidity

Fri Aug 10, 2018 1:39 pm

hitsware wrote:
Fri Aug 10, 2018 1:36 pm
I thought I was presenting something
that might be of interest or use.
My mistake.
Although I'm not really interested I don't think it's a mistake as such.
The only mistake is that you're not explaining what the idea behind the post is.

B.Goode
Posts: 6345
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Exploring Python-Timidity

Fri Aug 10, 2018 2:09 pm

hitsware wrote:
Fri Aug 10, 2018 1:36 pm
I'm not asking anything.
I thought I was presenting something
that might be of interest or use.
My mistake.

Maybe the mistake was assuming we were already on your wavelength and knew what you were taking about...

Can I constructively suggest that a reworded contribution (it's not too late to improve it) might have structure a bit like this...





Timidity is an application that enables....


Timidity and its python bindings can be installed on a Raspbian Stretch Operating System by ....


The following gives an example of how Timidity can be used from a python script.



< Then continue with your original contribution >

hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Exploring Python-Timidity

Fri Aug 10, 2018 5:58 pm

> Maybe the mistake was assuming we were already on your
> wavelength and knew what you were taking about...

My thought was that anyone interested in that type thing,
would, yes, be somewhat on my wavelength.
They would read the code, run it if curious enough, and
get back to this discussion with any comments.

User avatar
scruss
Posts: 1768
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Exploring Python-Timidity for virtual MIDI music

Fri Aug 10, 2018 6:59 pm

Here's the thing: you never once mentioned MIDI in your post. A more descriptive title might be something like "Adding MIDI sound to Pygame projects with Python-Timidity". Timidity is cool and been around forever (as in, I remember when playing midi files as music before MP3s were a thing/usably decoded in real-time) but it's not clear to most users what it is or what it does.

An intro/tutorial would be welcome, but you've got to give folks a bit of a hook to get them interested.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Exploring Python-Timidity

Sat Aug 11, 2018 12:26 am

https://www.pygame.org/docs/ref/midi.html

I tried the above also ...... But I like the least # of 'modules' possible (for the task)

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 8 guests