Code Monkey home page Code Monkey logo

Comments (5)

kalegood avatar kalegood commented on July 19, 2024

Working on this, but I don't know any python. Trying to use the generateTitle block as a template for generateBeat. I stripped things down and was hoping this would run, but alas, it does not. Still working on it.

#!/usr/bin/env python

coding=utf-8

import collections
import copy
import os
import re
import shutil
import subprocess
import sys
import urllib
from collections import namedtuple
from distutils.version import StrictVersion
from optparse import OptionParser
from struct import pack

from PIL import Image, ImageDraw, ImageFont
from pyPdf import PdfFileWriter, PdfFileReader
import midi

from pprint import pprint, pformat

DEBUG = False # --debug sets to True

def generateBeat1(beatText, width, height, ttfFile, fps, tempo):
"""
Generates frames with beat number 1.

Params:
- width:        pixel width of frames (and video)
- height:       pixel height of frames (and video)
- ttfFile:      path to TTF file to use for title text
- fps:          frame rate (frames per second) of final video
- tempo:        tempo
"""

# create image of title screen
beatScreen = Image.new("RGB", (width, height), (255,255,255))
# it will draw text on titleScreen
drawer = ImageDraw.Draw(titleScreen)
# save folder for frames
if not os.path.exists("beats"):
    os.mkdir("beats")

totalFrames = int(round(("60" / 100) * 30))
progress("Beats: ly2video will generate approx. %d frames." % totalFrames)

# font for beat 1, args - font type, size
beatFont = ImageFont.truetype(ttfFile, height / 15)

# args - position of left upper corner of rectangle (around text), text, font and color (black)
drawer.text(((width - nameFont.getsize("1")[0]) / 2,
             (height - nameFont.getsize("1")[1]) / 2 - height / 25),
            "1", font=nameFont, fill=(0,0,0))

# generate needed number of frames (= (60/tempo) * fps)
for frameNum in xrange(totalFrames):
    beatScreen.save("frame%d.png" % frameNum)

progress("Beats: Generating title screen has ended. (%d/%d)" %
         (totalFrames, totalFrames))
return 0

generateBeat1

from ly2video.

kalegood avatar kalegood commented on July 19, 2024

A hack of generate title to create beat 1 image.

def generateTitle(titleText, width, height, ttfFile, fps, titleLength):
"""
Generates frames with name of song and its author.

Params:
- width:        pixel width of frames (and video)
- height:       pixel height of frames (and video)
- ttfFile:      path to TTF file to use for title text
- fps:          frame rate (frames per second) of final video
- tempo:        tempo
"""

# create image of title screen
titleScreen = Image.new("RGB", (width, height), (255,255,255))
# it will draw text on titleScreen
drawer = ImageDraw.Draw(titleScreen)
# save folder for frames
if not os.path.exists("beats"):
    os.mkdir("beats")

totalFrames = int(round((60.000/100.000) * fps))
progress("Beats: ly2video will generate approx. %d frames." % totalFrames)

# font for beat 1, args - font type, size
nameFont = ImageFont.truetype(ttfFile, height / 15)

# args - position of left upper corner of rectangle (around text), text, font and color (black)
drawer.text(((width - nameFont.getsize("1")[0]) / 2,
             (height - nameFont.getsize("1")[1]) / 2 - height / 25),
            "1", font=nameFont, fill=(0,0,0))

# generate needed number of frames (= (60/tempo) * fps)
for frameNum in xrange(totalFrames):
    titleScreen.save(tmpPath("beats", "frame%d.png" % frameNum))

progress("Beats: Generating title screen has ended. (%d/%d)" %
         (totalFrames, totalFrames))
return 0

from ly2video.

kalegood avatar kalegood commented on July 19, 2024

again, hacking the title font. my best though is to have ly2video pull the time signature to figure out how many beats to have. It would have to be able to recognize compound meters. It would also be good to have a manual override to multiple measures of count-in, as two beats for 2/2, 2/4, 6/8, etc would not be enough.

I think I'm just going to get this working for 4/4 for myself and manually edit the file when I need more/ less beats. If someone could figure out how to cycle this process, inserting the appropriate beat into "beat" variable each time, it should do the trick.

def generateTitle(titleText, width, height, ttfFile, fps, titleLength):

# create image of title screen
titleScreen = Image.new("RGB", (width, height), (255,255,255))
# it will draw text on titleScreen
drawer = ImageDraw.Draw(titleScreen)
# save folder for frames
if not os.path.exists("beats"):
    os.mkdir("beats")

totalFrames = int(round((60.000/100.000) * fps))
progress("Beats: ly2video will generate approx. %d frames for each beat." % totalFrames)

#this variable needs to increase with each cycle of the process.
beat = 1

# font for beat 1, args - font type, size
nameFont = ImageFont.truetype(ttfFile, height / 15)

# args - position of left upper corner of rectangle (around text), text, font and color (black)
drawer.text(((width - nameFont.getsize(beat)[0]) / 2,
             (height - nameFont.getsize(beat)[1]) / 2 - height / 25),
            beat, font=nameFont, fill=(0,0,0))

# generate needed number of frames (= (60/tempo) * fps)
for frameNum in xrange(totalFrames):
    titleScreen.save(tmpPath("beats", "frame%d.png" % (((beat-1)*totalFrames)+frameNum)))

progress("Beats: Generating title screen has ended. (%d/%d)" %
         (totalFrames, totalFrames))
return 0

from ly2video.

kalegood avatar kalegood commented on July 19, 2024

might be nice to have an option to make the last beat a different color as well (might be more hassle than its worth)

from ly2video.

kalegood avatar kalegood commented on July 19, 2024

This does the trick for generating the screens; now I need to create a call for it in the main function and cat it together. For now, I think I'll try to make some command line options rather than figure out how to pull data from the .ly file.

def generateTitle(titleText, width, height, ttfFile, fps, titleLength):
"""
Generates frames with name of song and its author.

Params:
- width:        pixel width of frames (and video)
- height:       pixel height of frames (and video)
- ttfFile:      path to TTF file to use for title text
- fps:          frame rate (frames per second) of final video
- tempo:        tempo
"""


# save folder for frames
if not os.path.exists("beats"):
    os.mkdir("beats")

#grab the number of beats
beats = 4

totalFrames = int(round((60.000/100.000) * fps))

for currentBeat in range(beats):

    printBeat = currentBeat + 1 

    # create image of title screen
    titleScreen = Image.new("RGB", (width, height), (255,255,255))
    # it will draw text on titleScreen
    drawer = ImageDraw.Draw(titleScreen)

    progress("Beats: ly2video will generate approx. %d frames." % totalFrames)
    # font for beat args - font type, size
    nameFont = ImageFont.truetype(ttfFile, height / 15)

    # args - position of left upper corner of rectangle (around text), text, font and color (black)
    drawer.text(((width - nameFont.getsize("%d" % printBeat)[0]) / 2,
             (height - nameFont.getsize("%d" % printBeat)[1]) / 2 - height / 25),
            "%d" % printBeat, font=nameFont, fill=(0,0,0))

    # generate needed number of frames (= (60/tempo) * fps)
    for frameNum in xrange(totalFrames):
        titleScreen.save(tmpPath("beats", "frame%d.png" % ((currentBeat*totalFrames)+frameNum)))

    progress("Beats: Generating title screen has ended. (%d/%d)" %
             (totalFrames, totalFrames))


return 0

from ly2video.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.