Re: Midi Visualizer

2018-04-29 Thread Eelke Johnson
I solved the problem of the two call of the printer function with a toggle 
function but now when I play an octave I got the same problem...
Have you any idea to separate the hit/release piano key event on the 
port.set_callback ?

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-04-29 Thread Eelke Johnson
I solved the self problem. When I call the instance of the window it work ! 
(obviously) #window.ring.notes[key_map[m]].played()


and for now

IT'S WORKING :D


merci for your help :D

any suggestions or improvements?

I uploaded the code on my  github repo ;)

https://github.com/way2key/Midi_Visualizer/

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-04-29 Thread Eelke Johnson
Hi,

1) I want to pass the self into the callback because self mean the ring. 
There are all sector in this ring and when I want to toggle a sector, I 
have to update it with a method contained into the self object.

self -> ring -> sectors -> method on//off

2) The keyboard key. The rt-midi port.setcallback() method is called two 
times: when you hit the piano keyboard and when you release it.

Basically, I want to play a note on the piano keyboard and then toggle it 
with my ring.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-04-21 Thread Eelke Johnson
Hi,
It's been a while since I didn't posted anything but I'm back!
I've got some problem with the python rt-midi package. I didn't find any 
useful and complete documentation. I built the sphinx documentation but 
except the installation, I didn't found something useful and I'm stuck!

What I want to do basically is this:
key_map = { 0:  "c",
1:  "c#",
2:  "d#",
3:  "d#",
4:  "e",
5:  "f",
6:  "f#",
7:  "g",
8:  "g#",
9:  "a",
10: "a#",
11: "b"
}

# Midi configuration

midi_in = rtmidi.MidiIn()
available_ports = midi_in.get_ports()
port = midi_in.open_port(1)

def hit_a_key(message, data):
m = message[0][1]%12
self.ring.notes[key_map[m]].played()

def release_a_key(message, data):
m = message[0][1]%12
self.ring.notes[key_map[m]].idle()

port.set_callback(hit_a_key, data=self)
port.set_callback(release_a_key, data=self)

The two problems I faced are:

   1. I cannot pass the self object who contain my ring into the midi 
   function
   2. I didn't found how to implement an event hit/release. The callback is 
   called each time you press/release a key and I don't want that^^
   
Furthermore, I'm not sure if this is properly nested with the 
pyglet.app.run() loop

My code is on github https://github.com/way2key/Midi_Visualizer HERE 


I'm close to the end of this small program! 

Merci Eelke

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-03-04 Thread Eelke Johnson



Hi community,

I updated my small project. I reviewed how my code works and I implemented 
chord lines between notes.

Now, I need your suggestions :)
I want to improve the visual part with a glow effect when a note is played 
like in the software synthétisa. have you any idea how to implement it?  I 
listen to your commentaries and if you have another good idea I take it!

My second challenge is to implement it with my midi keyboard. There isn't 
many documentation available online. Do you have any ressources for a 
pyglet program who use midi input?

Thank you for your support :D I'm proud of the result and I hope I can keep 
it moving straight forward !

Eelke (way2key)

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-27 Thread Eelke Johnson
Yes of course.
I'm stuck on the order of execution and eventually mix it with a midi library.
I don't exactly understand how pyglet.app.run() work and when it call the 
on_draw() event.Furthermore, I already writed a small program who handle midi 
with pygame but I don't know how to implement it with pyglet.

The second thing I'm stuck on is the glowing effect. Here, I writed a function 
named played in the sector's class who draw from scratch a blue sector over the 
other. What I want, is a function who use the ancient sector and tweak it with 
openGl and make something nicer.

Thank you one more time. I hope you can share the knowledge you own.

Eelke

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-26 Thread Eelke Johnson
Hi Benjamin,
I started a Githubrepo because google group's post are too small to contain 
the code

here is my repo :
https://github.com/way2key/Midi_Visualizer

I merged partially your code with mine and new functions

my answer is in the last post

++ Eelke

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-26 Thread Eelke Johnson
Hi benjamin here is the fusion of our codes:
from pyglet.gl import *
from math import *


class sector(object):
def __init__(self, radius, inner_radius, angle, angle_in, points):
self.radius = radius
self.inner_radius = inner_radius
self.angle = angle
self.angle_in = angle_in
self.points = points
self.vertex = []
self.color = []
self.indices = []
for i in range(points):
angle = self.angle * (i / (points - 1)) + angle_in
x = cos(angle) * radius
y = sin(angle) * radius
z = 0
self.vertex.extend([x,y,z])
self.color.extend([255, 8, 45])
for i in range(points):
angle = self.angle - self.angle * (i/(points-1)) + angle_in
x = cos(angle) * inner_radius
y = sin(angle) * inner_radius
z = 0
self.vertex.extend([x,y,z])
self.color.extend([255,120,12])
for i in range(points - 1):
n = 2 * points - 1
self.indices.extend([i, i + 1 , n - i])
self.indices.extend([n - i, n - 1 - i, i + 1])
def render(self):
self.vertices = pyglet.graphics.draw_indexed(2 * self.points, 
GL_TRIANGLES, self.indices, ('v3f', self.vertex),('c3B',self.color))
def played(self):
self.color = []
for i in range(2 * self.points):
self.color.extend([0,0,255])
self.vertices = pyglet.graphics.draw_indexed(2 * self.points, 
GL_TRIANGLES, self.indices, ('v3f', self.vertex),('c3B',self.color))

class ring(object):
def __init__(self):
self.notes = {
'c' : None,
'c#': None,
'd' : None,
'd#': None,
'e' : None,
'f' : None,
'f#': None,
'g' : None,
'g#': None,
'a' : None,
'a#': None,
'b' : None
}
i = 0
for note in self.notes:
self.notes[note] = sector(0.7, 0.6, pi / 6.4, 2 * i * pi / 12, 
360)
i += 1
def render(self):
for note in self.notes:
self.notes[note].render()

class myWindow(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_minimum_size(300, 300)
glClearColor(0.2, 0.2, 0.21, 1)
self.ring = ring()
self.draw_list = []
self.sectors = [sector(0.7, 0.6, pi / 6.4, 2 * n * pi / 12, 360) for 
n in range(12)]
def on_draw(self):
self.clear()
self.ring.render()

for sector in self.draw_list:
sector.played()

def on_resize(self, width, height):
glViewport(0, 0, width, height)

def on_key_press(self, key, modifier):
#default behavior
if key == pyglet.window.key.ESCAPE:
pyglet.app.exit()
# Mapping key presses
if key == pyglet.window.key.Q:
self.draw_list.append(self.sectors[0])
elif key == pyglet.window.key.W:
self.draw_list.append(self.sectors[1])
elif key == pyglet.window.key.E:
self.draw_list.append(self.sectors[2])
elif key == pyglet.window.key.R:
self.draw_list.append(self.sectors[3])
elif key == pyglet.window.key.T:
self.draw_list.append(self.sectors[4])
elif key == pyglet.window.key.Z:
self.draw_list.append(self.sectors[5])
elif key == pyglet.window.key.U:
self.draw_list.append(self.sectors[6])
elif key == pyglet.window.key.I:
self.draw_list.append(self.sectors[7])
elif key == pyglet.window.key.O:
self.draw_list.append(self.sectors[8])

def on_key_release(self, key, modifier):
self.draw_list.clear()




if __name__ == "__main__":
windows = myWindow(800, 800, "midi_visualizer", resizable=True)
pyglet.app.run()


-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-26 Thread Eelke Johnson



Hi Benjamin,

Merci beaucoup for the fast answer!
Thank you for idea of the drawing list it will help me a lot! 
Before I got your message, I already started a new class called ring with a 
dictionnary for the midi keys mapping and I writed two render functions. 
One for iddle state and the second when an event occurs.

What I want to implement:
I want to keep the ring printed on screen and when an event occur, the 
sector concerned would glown shine or I dont know what kind of fancy effect 
(here I drawn a blue sector).

I don't know much about pyglet structure, batch or vlist. and I don't know 
how to implement it properly. Should I integrate the draw_list into my ring 
class? Can I write a function in the sector class who tweak the sector and 
I call this function directly on the dictionnary? There is a lot of points 
I don't master and I want to write it like KISS. (Keep It Simple and Stupid)

Thank you for your support! I appreciate that :D I sought an active 
community to ask questions and learn. here I am 

Eelke

Here is my code:
from pyglet.gl import *
from math import *
from pyglet.window import key

class sector(object):
def __init__(self, radius, inner_radius, angle, angle_in,points):
self.radius = radius
self.inner_radius = inner_radius
self.angle = angle
self.angle_in = angle_in
self.points = points
self.vertex = []
self.color = []
self.indices = []
for i in range(points):
angle=self.angle*(i/(points-1))+angle_in
x=cos(angle)*radius
y=sin(angle)*radius
z=0
self.vertex.extend([x,y,z])
self.color.extend([255,800,45])
for i in range(points):
angle=self.angle-self.angle*(i/(points-1))+angle_in
x=cos(angle)*inner_radius
y=sin(angle)*inner_radius
z=0
self.vertex.extend([x,y,z])
self.color.extend([255,120,12])
for i in range(points-1):
n = 2*points-1
self.indices.extend([i,i+1,n-i])
self.indices.extend([n-i,n-1-i,i+1])
def render(self):
self.vertices = pyglet.graphics.draw_indexed(2*self.points,
GL_TRIANGLES,self.indices,('v3f', self.vertex),('c3B',self.color))
def played(self):
self.color = []
for i in range(2*self.points):
self.color.extend([0,0,255])
self.vertices = pyglet.graphics.draw_indexed(2*self.points,
GL_TRIANGLES,self.indices,('v3f', self.vertex),('c3B',self.color))

class ring(object):
def __init__(self):
self.notes = {
'c' : None,
'c#': None,
'd' : None,
'd#': None,
'e' : None,
'f' : None,
'f#': None,
'g' : None,
'g#': None,
'a' : None,
'a#': None,
'b' : None
}
i=0
for note in self.notes:
self.notes[note] = sector(0.7,0.6,pi/6.4,2*i*pi/12,360)
i+=1
def render(self):
for note in self.notes:
self.notes[note].render()

class myWindow(pyglet.window.Window):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.set_minimum_size(300,300)
glClearColor(0.2,0.2,0.21,1)
self.ring = ring()
self.sector = sector(0.7,0.6,pi/6.4,2*pi/12,360)

def on_draw(self):
self.clear()
self.ring.render()
self.sector.played()


def on_resize(self,width,height):
glViewport(0,0,width,height)


if __name__ == "__main__":
windows = myWindow(800,800,"midi_visualizer",resizable=True)
pyglet.app.run()


-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-26 Thread Eelke Johnson




Hi Benjamin,

Merci beaucoup for the fast answer!
Thank you for idea of the drawing list it will help me a lot! 
Before I got your message, I already started a new class called ring with a 
dictionnary for the midi keys mapping and I writed two render functions. 
One for iddle state and the second when an event occurs.

What I want to implement:
I want to keep the ring printed on screen and when an event occur, the 
sector concerned would glown shine or I dont know what kind of fancy effect 
(here I drawn a blue sector).

I don't know much about pyglet structure, batch or vlist. and I don't know 
how to implement it properly. Should I integrate the draw_list into my ring 
class? Can I write a function in the sector class who tweak the sector and 
I call this function directly on the dictionnary? There is a lot of points 
I don't master and I want to write it like KISS. (Keep It Simple and Stupid)

Thank you for your support! I appreciate that :D I sought an active 
community to ask questions and learn. here I am 

Eelke

Here is my code:
from pyglet.gl import *
from math import *
from pyglet.window import key

class sector(object):
def __init__(self, radius, inner_radius, angle, angle_in,points):
self.radius = radius
self.inner_radius = inner_radius
self.angle = angle
self.angle_in = angle_in
self.points = points
self.vertex = []
self.color = []
self.indices = []
for i in range(points):
angle=self.angle*(i/(points-1))+angle_in
x=cos(angle)*radius
y=sin(angle)*radius
z=0
self.vertex.extend([x,y,z])
self.color.extend([255,800,45])
for i in range(points):
angle=self.angle-self.angle*(i/(points-1))+angle_in
x=cos(angle)*inner_radius
y=sin(angle)*inner_radius
z=0
self.vertex.extend([x,y,z])
self.color.extend([255,120,12])
for i in range(points-1):
n = 2*points-1
self.indices.extend([i,i+1,n-i])
self.indices.extend([n-i,n-1-i,i+1])
def render(self):
self.vertices = pyglet.graphics.draw_indexed(2*self.points,
GL_TRIANGLES,self.indices,('v3f', self.vertex),('c3B',self.color))
def played(self):
self.color = []
for i in range(2*self.points):
self.color.extend([0,0,255])
self.vertices = pyglet.graphics.draw_indexed(2*self.points,
GL_TRIANGLES,self.indices,('v3f', self.vertex),('c3B',self.color))

class ring(object):
def __init__(self):
self.notes = {
'c' : None,
'c#': None,
'd' : None,
'd#': None,
'e' : None,
'f' : None,
'f#': None,
'g' : None,
'g#': None,
'a' : None,
'a#': None,
'b' : None
}
i=0
for note in self.notes:
self.notes[note] = sector(0.7,0.6,pi/6.4,2*i*pi/12,360)
i+=1
def render(self):
for note in self.notes:
self.notes[note].render()

class myWindow(pyglet.window.Window):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.set_minimum_size(300,300)
glClearColor(0.2,0.2,0.21,1)
self.ring = ring()
self.sector = sector(0.7,0.6,pi/6.4,2*pi/12,360)

def on_draw(self):
self.clear()
self.ring.render()
self.sector.played()


def on_resize(self,width,height):
glViewport(0,0,width,height)


if __name__ == "__main__":
windows = myWindow(800,800,"midi_visualizer",resizable=True)
pyglet.app.run()




-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Re: Midi Visualizer

2018-02-18 Thread Eelke Johnson



Hi,
I began to use openGL and pyglet. Now I'm trying to get a function who 
return a sector. I want to use GL_POLYGON draw method but I've got weird 
result... Can you help me? I use cos(pi/2) for my x coordinate and 
sin(pi/2) for my y coordinate. I used red for the outter ring and green for 
the inner ring. I only want to fill my array of points^^ I dont know much 
about openGL but it's a start! I already prepared the midi interface. Im 
only stuck with the graphic parts...

here is my code


from pyglet.gl import *
> from math import *
>
> class secteur(object):
> def __init__(self, radius, inner_radius, angle, points):
> self.radius = radius
> self.inner_radius = inner_radius
> self.angle = angle
> self.points = points
> self.vertex = []
> self.color = []
> for i in range(points):
> angle=self.angle/points*i
> x=cos(angle)*radius
> y=sin(angle)*radius
> z=0
> self.vertex.extend([x,y,z])
> self.color.extend([255,0,0])
> for i in range(points):
> angle=self.angle-self.angle/points*i
> x=cos(angle)*inner_radius
> y=sin(angle)*inner_radius
> z=0
> self.vertex.extend([x,y,z])
> self.color.extend([0,255,0])
> self.vertices = pyglet.graphics.vertex_list(2*points,('v3f', self.
> vertex),('c3B',self.color))
>
> class myWindow(pyglet.window.Window):
> def __init__(self,*args,**kwargs):
> super().__init__(*args,**kwargs)
> self.set_minimum_size(300,300)
> glClearColor(0.2,0.2,0.21,1)
> self.secteur = secteur(0.5,0.3,pi/2,11)
>
>
> def  on_draw(self):
> self.clear()
> self.secteur.vertices.draw(GL_POLYGON)
>
>
> def on_resize(self,width,height):
> glViewport(0,0,width,height)
>
>
>
> if __name__ == "__main__":
> windows = myWindow(800,800,"midi_visualizer",resizable=True)
>
> pyglet.app.run()
>
>
>
>


-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


Midi Visualizer

2018-02-04 Thread Eelke Johnson


Hi community!

I'm a newbie and a muscician and I want to programm a live python midi 
interface to visualize my favourite song when I play it on my keyboard. 
I've started learning python, installed Ubuntu, configured my environnement 
and searched for online libraries.
I found here <https://wiki.python.org/moin/GuiProgramming> those libraries:




*-pygame-pyglet-pyopengl*My purpose was to use pygame's midi librairies to 
listen to my keyboard and use pyopengl for the graphics. 
The problem was that I didn't found anywhere sufficient documentation for 
learning pyopengl and I gave up until I discovered Piglet!


I'm not sure if I can implement the pygame's midi library and integrate it 
with piglet. Is this possible? or should I use pygame with pyopengl instead?
My question is : *Can I use piglet to programme my app with pygame's midi 
library?*




*What I want to do:*

Here is an animation more or less simillar than my idea ( I only want 12 
sectors and of course map it with my midi keyboard)
https://www.youtube.com/watch?v=4kkNbtbWbm8

First step,
I want to draw a circle with sector like this (in 2d or 3d)

<https://fr-images.tuto.net/tuto/thumb/648/288/49140.jpg>

But first thing first,
I started with hello world and then writed a simple app who draw a circle 
(https://www.youtube.com/watch?v=dEZDPjVegT4)
But then,
I want to do this shape with 12 sectors and I don't know how to proceed. I 
looked for the GL_POLYGON method but I don't know how to implement it.
Can someone help me with a basic example or procedure to follow? 

*(for instance :*
   
   1. *make an array with all vertices *
   2. *draw a polygon shape with GL *
   3. *fill it *
   4. *change the camera projection*
   5. *etc...*

*)*



I'm motivated to learn piglet, opengl and python but I seek for ressources, 
example and support
Sorry for my bad english I'm not native.

Eelke Johnson

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.