Exemple #1
0
 def test_selection_layer(layerclass):
     graph = Mock({"channels": [], "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     selection = Mock({"pixels": (20, 100), "selected": True})
     selection.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(layerclass(layered, selection))
     return layered
Exemple #2
0
 def sine():
     from math import sin
     sine = [sin(2 * 3.14 * 0.01 * x) for x in range(500)]
     channels = [[(i, i) for i in sine]]
     graph = Mock({"channels": channels, "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(WaveformLayer(layered, graph))
     return layered
Exemple #3
0
 def sine():
     from math import sin
     sine = [sin(2 * 3.14 * 0.01 * x) for x in xrange(500)]
     channels = [[(i, i) for i in sine]]
     graph = Mock({"channels": channels, "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(WaveformLayer(layered, graph))
     return layered
Exemple #4
0
def test():
    from gum.lib.mock import Fake, Mock
    graph = Mock({"frames_info":(0, 0, [], []),
                  "channels": [[(0, 0.5)]],
                  "set_width": None,
                  "scroll_left": None,
                  "scroll_right": None})
    graph.changed = Fake()
    selection = Mock({"pixels": [50, 100],
                      "start_selection": None,
                      "end_selection": None,
                      "selected": True})
    selection.changed = Fake()
    cursor = Mock({'pixel': 20})
    cursor.changed = Fake()
    class FakeEditor(Fake):
        def __init__(self):
            self.filename_changed = Fake()
            self.error = Fake()

    notebook = EditorNotebook()
    win = EditorWindow(notebook)
    page = EditorPage(FakeEditor(), graph, selection, cursor)
    notebook.add_page(page)
    win.resize(700, 500)
    win.show_all()
    gtk.main()

    display_error("Title", "Text")
Exemple #5
0
 def randomized():
     from random import random        
     channels = [[((random() - 0.5) * 2, (random() - 0.5) * 2)
                for i in xrange(500)]]
     graph = Mock({"channels": channels,
                   "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(WaveformLayer(layered, graph))
     return layered
Exemple #6
0
 def randomized():
     from random import random        
     channels = [[((random() - 0.5) * 2, (random() - 0.5) * 2)
                for i in range(500)]]
     graph = Mock({"channels": channels,
                   "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(WaveformLayer(layered, graph))
     return layered
Exemple #7
0
def test_middle():
    from gum.lib.mock import Mock, Fake
    import numpy
    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = []
    g = Graph(sound)
    for nframes, mid in [(4, 1.5), (9, 4), (10, 4.5)]:
        sound.frames = numpy.array(list(range(nframes)))
        g.set_sound(sound)
        assert g.middle() == mid
Exemple #8
0
def test_middle():
    from gum.lib.mock import Mock, Fake
    import numpy
    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = []
    g = Graph(sound)
    for nframes, mid in [(4, 1.5), (9, 4), (10, 4.5)]:
        sound.frames = numpy.array(range(nframes))
        g.set_sound(sound)
        assert g.middle() == mid
Exemple #9
0
def test_channels():
    import numpy
    from gum.lib.mock import Mock, Fake
    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = numpy.array(list(range(1000000)), DTYPE)
    g = Graph(sound)

    for w in [1, 10, 11, 12, 13, 14, 15, 29, 54, 12.0, 347, 231., 1030]:
        g.set_width(w)
        c = g.channels()
        assert len(c[0]) == w, \
             "expected: %d, got: %d, density: %f, last value: %s " % \
                                     (w, len(c[0]), g.density, str(c[0][-1]))
Exemple #10
0
def test_Graph():
    from gum.lib.mock import Mock, Fake
    import numpy

    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = numpy.array(list(range(1000)), DTYPE)

    c = Graph(sound)
    c.set_width(200)
    o = c.channels()

    class Foo:
        def foo(self):
            print("Changed.")

    f = Foo()
    c = Graph(sound)
    c.changed.connect(f.foo)
    c.set_width(200)
    o = c.channels()

    # stereo
    import numpy
    sound = Mock({"numchan": 2})
    sound.changed = Fake()
    data = numpy.array([[1, 1], [2, 2], [3, 3]], DTYPE)
    sound.frames = data
    c = Graph(sound)
    o = c.channels()
    assert (len(o)) == 2
Exemple #11
0
def test_channels():
    import numpy
    from gum.lib.mock import Mock, Fake
    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = numpy.array(range(1000000), DTYPE)
    g = Graph(sound)

    for w in [1, 10, 11, 12, 13, 14, 15, 29, 54, 12.0, 347, 231., 1030]:
        g.set_width(w)
        c = g.channels()
        assert len(c[0]) == w, \
             "expected: %d, got: %d, density: %f, last value: %s " % \
                                     (w, len(c[0]), g.density, str(c[0][-1]))
Exemple #12
0
def test_scroll():
    import numpy
    from gum.lib.mock import Mock, Fake

    sound = Mock({})
    data = numpy.array([1, 2, 3, 4])
    sound.frames = data
    sound.changed = Fake()

    g = Graph(sound)
    g.set_width(4)

    g.scroll_right()
    length = g.numframes()
    start, end = g.view()
    assert length == 4
    assert start == 0
    assert end == 4
Exemple #13
0
def test_scroll():
    import numpy
    from gum.lib.mock import Mock, Fake

    sound = Mock({})
    data = numpy.array([1, 2, 3, 4])
    sound.frames = data
    sound.changed = Fake()

    g = Graph(sound)
    g.set_width(4)

    g.scroll_right()
    length = g.numframes()
    start, end = g.view()
    assert length == 4
    assert start == 0
    assert end == 4
Exemple #14
0
def test_zoom_in():
    import numpy
    from gum.lib.mock import Mock, Fake
    sound = Mock({"numchan": 1})
    sound.changed = Fake()

    data = numpy.array([1, 2, 3, 4], DTYPE)
    sound.frames = data
    g = Graph(sound)

    g.set_width(2)
    g.zoom_in()
    o = g.channels()
    assert o == [[(2, 2), (3, 3)]]

    g.zoom_out()
    g.set_width(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
Exemple #15
0
def test_zoom_in():
    import numpy 
    from gum.lib.mock import Mock, Fake
    sound = Mock({"numchan": 1})
    sound.changed = Fake()

    data = numpy.array([1, 2, 3, 4], DTYPE)
    sound.frames = data
    g = Graph(sound)

    g.set_width(2)
    g.zoom_in()
    o = g.channels()
    assert o == [[(2, 2), (3, 3)]]

    g.zoom_out()
    g.set_width(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
Exemple #16
0
 def cursor():
     graph = Mock({"channels": [], "set_width": None,
                   "frames_info": (0, 0, 0)})
     class Cursor: pass
     cursor = Cursor()
     cursor.changed = Fake()
     cursor.pixel = lambda: 50
     layered = LayeredGraphView(graph)
     cursorlayer = CursorLayer(layered, cursor)
     cursorlayer.rgba = (1, 0, 0, 1)
     layered.layers.append(cursorlayer)
     return layered
Exemple #17
0
def test():
    from gum.lib.mock import Fake, Mock
    graph = Mock({"frames_info":(0, 0, [], []),
                  "channels": [[(0, 0.5)]],
                  "set_width": None,
                  "scroll_left": None,
                  "scroll_right": None})
    graph.changed = Fake()
    selection = Mock({"pixels": [50, 100],
                      "start_selection": None,
                      "end_selection": None,
                      "selected": True})
    selection.changed = Fake()
    cursor = Mock({'pixel': 20})
    cursor.changed = Fake()
    class FakeEditor(Fake):
        def __init__(self):
            self.filename_changed = Fake()
            self.error = Fake()

    notebook = EditorNotebook()
    win = EditorWindow(notebook)
    page = EditorPage(FakeEditor(), graph, selection, cursor)
    notebook.add_page(page)
    win.resize(700, 500)
    win.show_all()
    gtk.main()

    display_error("Title", "Text")
Exemple #18
0
def test_Graph():
    from gum.lib.mock import Mock, Fake
    import numpy
    
    sound = Mock({"numchan": 1})
    sound.changed = Fake()
    sound.frames = numpy.array(range(1000), DTYPE)

    c = Graph(sound)
    c.set_width(200)
    o = c.channels()

    class Foo:
        def foo(self):
            print "Changed."
    f = Foo()
    c = Graph(sound)
    c.changed.connect(f.foo)
    c.set_width(200)
    o = c.channels()

    # stereo
    import numpy
    sound = Mock({"numchan": 2})
    sound.changed = Fake()
    data = numpy.array([[1, 1], [2, 2], [3, 3]], DTYPE)
    sound.frames = data
    c = Graph(sound)
    o = c.channels()
    assert(len(o)) == 2
Exemple #19
0
 def test_selection_layer(layerclass):
     graph = Mock({"channels": [], "set_width": None,
                   "frames_info": (0, 0, 0)})
     graph.changed = Fake()
     selection = Mock({"pixels": (20, 100), "selected": True})
     selection.changed = Fake()
     layered = LayeredGraphView(graph)
     layered.layers.append(layerclass(layered, selection))
     return layered
Exemple #20
0
def test_fix_selection():
    from gum.lib.mock import Fake, Mock
    from gum.models import Selection
    import numpy

    # Undo
    graph = Mock({})
    graph.changed = Fake()
    selection = Selection(graph, Fake())
    sound = Sound()
    sound.frames = numpy.array(list(range(1000)))
    editor = Editor(sound, Fake(), Fake(), selection)
    frames = sound.frames
    selection.set(0, 999)
    editor.copy()
    editor.paste()
    selection.set(1500, 1500)
    editor.undo()
    editor.paste()
    editor.undo()
    assert sound.frames.tolist() == frames.tolist()

    # Redo
    graph = Mock({})
    graph.changed = Fake()
    selection = Selection(graph, Fake())
    sound = Sound()
    sound.frames = numpy.array(list(range(1000)))
    editor = Editor(sound, Fake(), Fake(), selection)
    frames = sound.frames
    selection.set(10, 999)
    editor.cut()
    editor.undo()
    selection.set(900, 900)
    editor.redo()
    frames = sound.frames
    editor.paste()
    editor.undo()
    assert sound.frames.tolist() == frames.tolist()
Exemple #21
0
def testPlayer():
    from gum.lib.mock import Mock
    from math import sin
    SR = 44100
    f0 = 440
    time = 1
    sine = numpy.array([sin(2 * 3.14 * f0/SR * x) for x in range(time * SR)])
    sound = Mock({"numchan": 1})
    sound.samplerate = 44100
    sound.frames = sine
    
    player = Player(sound)
    player.thread_play().join()

    from gum.lib import pysndfile
    import gum
    f = pysndfile.sndfile(gum.basedir + '/data/test/test1.wav')
    data = f.read_frames(f.get_nframes())
    sound.frames = data
    player.set_sound(sound)
    player.thread_play().join()
    player.thread_play().join()

    # Testing position
    player.start = 40000
    player.thread_play().join()
    player.start = 0

    # Test reentrancy
    print ("Two threads will attempt to play at a small interval, you should "
           "hear the first one being interrupted by the second one.")
    
    from time import sleep
    t1 = player.thread_play()
    sleep(0.5)
    t2 = player.thread_play()
    t1.join()
    t2.join()

    print ("Two threads will attempt to play simultaneously, you should "
           "hear only one.")
    
    from time import sleep
    t1 = player.thread_play()
    t2 = player.thread_play()
    t1.join()
    t2.join()

    # Testing stop
    print 
    print "Testing stop(): the sound should stop after 0.3 seconds."
    player.thread_play()
    sleep(0.3)
    player.stop()

    # Testing stereo
    f = pysndfile.sndfile(gum.basedir + '/data/test/test2.wav')
    data = f.read_frames(f.get_nframes())
    sound = Mock({"numchan": 2})
    sound.samplerate = 44100
    sound.frames = data
    player = Player(sound)
    player.thread_play().join()
Exemple #22
0
def test_zoom():
    from gum.lib.mock import Mock, Fake
    import numpy

    sound = Mock({"numchan": 1})
    data = numpy.array([1, 2, 3, 4], DTYPE)
    sound.frames = data
    sound.changed = Fake()

    g = Graph(sound)

    g.set_width(4)
    g._zoom(1)
    g.center_on(1.5)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
    
    g._zoom(factor=1)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g._zoom(1)
    g.center_on(6)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
    
    g._zoom(factor=0.5)
    g.center_on(1.5)
    g.set_width(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g.set_width(2)
    g._zoom(0.5)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2)]]

    g.set_width(4)
    g._zoom(0.25)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
    
    g.set_width(4)
    g._zoom(4)
    g.center_on(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]], o

    g.set_width(100)
    data = numpy.array(range(3241))
    sound.frames = data
    g.zoom_out_full()
    g._zoom(factor=0.5)
    g._zoom(factor=0.5)
    start, end = g.view()
    g.zoom_out_full()    
    g._zoom(factor=0.5 * 0.5)
    assert (start, end) == g.view()
Exemple #23
0
def test_zoom():
    from gum.lib.mock import Mock, Fake
    import numpy

    sound = Mock({"numchan": 1})
    data = numpy.array([1, 2, 3, 4], DTYPE)
    sound.frames = data
    sound.changed = Fake()

    g = Graph(sound)

    g.set_width(4)
    g._zoom(1)
    g.center_on(1.5)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g._zoom(factor=1)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g._zoom(1)
    g.center_on(6)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g._zoom(factor=0.5)
    g.center_on(1.5)
    g.set_width(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g.set_width(2)
    g._zoom(0.5)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2)]]

    g.set_width(4)
    g._zoom(0.25)
    g.center_on(0)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]

    g.set_width(4)
    g._zoom(4)
    g.center_on(4)
    o = g.channels()
    assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]], o

    g.set_width(100)
    data = numpy.array(list(range(3241)))
    sound.frames = data
    g.zoom_out_full()
    g._zoom(factor=0.5)
    g._zoom(factor=0.5)
    start, end = g.view()
    g.zoom_out_full()
    g._zoom(factor=0.5 * 0.5)
    assert (start, end) == g.view()
Exemple #24
0
def testPlayer():
    from gum.lib.mock import Mock
    from math import sin
    SR = 44100
    f0 = 440
    time = 1
    sine = numpy.array([sin(2 * 3.14 * f0 / SR * x) for x in range(time * SR)])
    sound = Mock({"numchan": 1})
    sound.samplerate = 44100
    sound.frames = sine

    player = Player(sound)
    player.thread_play().join()

    from gum.lib import pysndfile
    import gum
    f = pysndfile.sndfile(gum.basedir + '/data/test/test1.wav')
    data = f.read_frames(f.get_nframes())
    sound.frames = data
    player.set_sound(sound)
    player.thread_play().join()
    player.thread_play().join()

    # Testing position
    player.start = 40000
    player.thread_play().join()
    player.start = 0

    # Test reentrancy
    print("Two threads will attempt to play at a small interval, you should "
          "hear the first one being interrupted by the second one.")

    from time import sleep
    t1 = player.thread_play()
    sleep(0.5)
    t2 = player.thread_play()
    t1.join()
    t2.join()

    print("Two threads will attempt to play simultaneously, you should "
          "hear only one.")

    from time import sleep
    t1 = player.thread_play()
    t2 = player.thread_play()
    t1.join()
    t2.join()

    # Testing stop
    print()
    print("Testing stop(): the sound should stop after 0.3 seconds.")
    player.thread_play()
    sleep(0.3)
    player.stop()

    # Testing stereo
    f = pysndfile.sndfile(gum.basedir + '/data/test/test2.wav')
    data = f.read_frames(f.get_nframes())
    sound = Mock({"numchan": 2})
    sound.samplerate = 44100
    sound.frames = data
    player = Player(sound)
    player.thread_play().join()